ReolinkCameraAPI / reolinkapipy

Reolink Camera API written in Python 3.6
GNU General Public License v3.0
211 stars 48 forks source link

question - novice questions getting my Reolink camera to work: #14

Closed duffjay closed 4 years ago

duffjay commented 4 years ago

Thanks for the answer on a previous question. My issue was solved by upgrading the firmware which surprised me. I am now trying a Reolink camera which appears to be far better than the Amcrest camera.

I verified that I can grab a frame from the camera. Using Chrome browser: http://192.168.1.122/cgi-bin/api.cgi?cmd=Snap&channel=0&user=admin&password=myPassword

If I refresh the browser - I get updated frames as expected. However, I tried using opencv VideoCapture - oddly (different behavior from Amcrest) - it will get 1 frame but does not return frames on subsequent calls. (my program worked well with the Amcrest cameras - the Reolink has better image quality so I'm switching cameras.) So I am looking at your API.

python 3.7

import RtspClient

r = RtspClient.RtspClient('192.168.1.122', 'admin', myPassword) r.connect() <socks.socksocket fd=10, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, laddr=('192.168.1.110', 46678), raddr=('192.168.1.122', 554)>

trying to get a snapshot

r.preview() 'NoneType' object has no attribute 'send' Traceback (most recent call last): File "", line 1, in File "/media/home/jay/projects/ReolinkCameraAPI/RtspClient.py", line 78, in preview cv2.imshow(win_name, self.get_frame()) cv2.error: OpenCV(4.2.0) /io/opencv/modules/highgui/src/window.cpp:376: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'imshow'

trying to get_frame()

bytes = r.get_frame() 'NoneType' object has no attribute 'send'

I'm a relative novice with RESTful APIs so this is probably a pretty simple issue. Looks like I have an object = None someplace

duffjay commented 4 years ago

I suspect this is a really simple mistake on my part - due to my very limited understanding of working with APIs.

I changed your test program slightly to look at the general api. I can login, get information but I can't get an image. It looks like something is wrong with my Request object.

My setup is super simple. Computer and camera on are on the same PoE switch. The camera is an RLC-420-5MP.

python test_reolink.py

Login success successfully created object: <class 'Camera.Camera'> Getting General System: [{'cmd': 'GetTime', 'code': 0, 'initial': {'Dst': {'enable': 0, 'endHour': 2, 'endMin': 0, 'endMon': 10, 'endSec': 0, 'endWeek': 5, 'endWeekday': 0, 'offset': 1, 'startHour': 2, 'startMin': 0, 'startMon': 3, 'startSec': 0, 'startWeek': 2, 'startWeekday': 0}, 'Time': {'day': 1, 'hour': 0, 'hourFmt': 0, 'min': 0, 'mon': 0, 'sec': 0, 'timeFmt': 'DD/MM/YYYY', 'timeZone': 28800, 'year': 0}}, 'range': {'Dst': {'enable': 'boolean', 'endHour': {'max': 23, 'min': 0}, 'endMin': {'max': 59, 'min': 0}, 'endMon': {'max': 12, 'min': 1}, 'endSec': {'max': 59, 'min': 0}, 'endWeek': {'max': 5, 'min': 1}, 'endWeekday': {'max': 6, 'min': 0}, 'offset': {'max': 2, 'min': 1}, 'startHour': {'max': 23, 'min': 0}, 'startMin': {'max': 59, 'min': 0}, 'startMon': {'max': 12, 'min': 1}, 'startSec': {'max': 59, 'min': 0}, 'startWeek': {'max': 5, 'min': 1}, 'startWeekday': {'max': 6, 'min': 0}}, 'Time': {'day': {'max': 31, 'min': 1}, 'hour': {'max': 23, 'min': 0}, 'hourFmt': {'max': 1, 'min': 0}, 'min': {'max': 59, 'min': 0}, 'mon': {'max': 12, 'min': 1}, 'sec': {'max': 59, 'min': 0}, 'timeFmt': ['MM/DD/YYYY', 'YYYY/MM/DD', 'DD/MM/YYYY'], 'timeZone': {'max': 43200, 'min': -46800}, 'year': {'max': 2100, 'min': 1900}}}, 'value': {'Dst': {'enable': 1, 'endHour': 1, 'endMin': 0, 'endMon': 11, 'endSec': 0, 'endWeek': 1, 'endWeekday': 0, 'offset': 1, 'startHour': 3, 'startMin': 0, 'startMon': 3, 'startSec': 0, 'startWeek': 2, 'startWeekday': 0}, 'Time': {'day': 15, 'hour': 15, 'hourFmt': 1, 'min': 48, 'mon': 3, 'sec': 33, 'timeFmt': 'MM/DD/YYYY', 'timeZone': 18000, 'year': 2020}}}, {'cmd': 'GetNorm', 'code': 0, 'initial': {'norm': 'NTSC'}, 'range': {'norm': ['PAL', 'NTSC']}, 'value': {'norm': 'NTSC'}}]

Getting Information: [{'cmd': 'GetDevInfo', 'code': 0, 'value': {'DevInfo': {'B485': 0, 'IOInputNum': 0, 'IOOutputNum': 0, 'audioNum': 1, 'buildDay': 'build 19061408', 'cfgVer': 'v2.0.0.0', 'channelNum': 1, 'detail': 'IPC_51516M5M110000000100000', 'diskNum': 0, 'firmVer': 'v2.0.0.448_19061408', 'hardVer': 'IPC_51516M5M', 'model': 'RLC-420-5MP', 'name': 'Reolink1', 'pakSuffix': 'pak', 'serial': '00000000000000', 'type': 'IPC', 'wifi': 0}}}]

Getting Performance: [{'cmd': 'GetPerformance', 'code': 0, 'value': {'Performance': {'codecRate': 6383, 'cpuUsed': 19, 'netThroughput': 0}}}]

Snap URL: http://192.168.1.122/cgi-bin/api.cgi?cmd=Snap&channel=0&rs=WG849DFJKM&user=admin&password=sT1nkeye req: <urllib.request.Request object at 0x7eff40748f90> Could not get Image data

Traceback (most recent call last): File "test_reolink.py", line 12, in c.get_snap() File "/media/home/jay/projects/ReolinkCameraAPI/api/recording.py", line 63, in get_snap reader = request.urlopen(req, timeout) File "/media/home/jay/anaconda3/envs/camera-api/lib/python3.7/urllib/request.py", line 222, in urlopen return opener.open(url, data, timeout) File "/media/home/jay/anaconda3/envs/camera-api/lib/python3.7/urllib/request.py", line 523, in open req = meth(req) File "/media/home/jay/anaconda3/envs/camera-api/lib/python3.7/urllib/request.py", line 1242, in do_request_ raise URLError('no host given') urllib.error.URLError:
duffjay commented 4 years ago

oops - seems I don't know Github either. I meant to add information, not close

Benehiko commented 4 years ago

It's strange that the OpenCV VideoCapture function doesn't return subsequent frames, maybe the method you are using to display the frames retrieved aren't updating?

Don't worry, this repository is still quite experimental and a lot might be broken. I can't test this right now, could you try checkout branch dev-1.0 and see if you can use the snap API?

Inside the folder where you cloned this repository: git checkout dev-1.0

vlebourl commented 4 years ago

Careful, a password seems to be left in clear in https://github.com/Benehiko/ReolinkCameraAPI/issues/14#issuecomment-599256527