简体   繁体   中英

Reading stream from IP camera with cv2.VideoCapture()

Referring to this similar question How to parse mjpeg http stream from ip camera? I was able to read the stream from IP camera, by using requests :

stream = requests.get('http://<user>:<pass>@<addr>:<port>/videostream.cgi', stream=True)

bytez = ''
while True:
    bytez += stream.raw.read(16384)
    ...

and it works beautifully, but would like to get there by using cv2.VideoCapture() instead requests.

I tried variations in a manner of:

cap = cv2.VideoCapture()
cap.open('http://<user>:<pass>@<addr>:<port>/videostream.cgi?.mjpg')

while(True):
    ret, frame = cap.read()
    ...

but wasn't able to get anything, but Exception about empty frame.

How to read IP camera stream with cv2.VideoCapture()?

I haven't yet tried accessing an IP camera from VideoCapture, but on your method cap = cv2.VideoCapture() the video capture is expecting a number representing the camera usually 0 .

By leaving it empty, it doesn't access any camera thus the Exception about an empty frame (even though later on you declare cap.open() , openCV already tried to open a camera and determined that is empty)

Add C:\\OpenCV\\3rdparty\\ffmpeg\\ to the Windows PATH environment variable or copy opencv_ffmpeg.dll from that directory to C:\\Python27. This has been answered in this question OpenCV 2.4 VideoCapture not working on Windows

将相机的位置传递到cap = cv2.VideoCapture()行:

cap = cv2.VideoCapture('http://<user>:<pass>@<addr>:<port>/videostream.cgi?.mjpg')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM