Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading stream from IP camera with cv2.VideoCapture()

Tags:

python

opencv

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()?

like image 696
theta Avatar asked Mar 26 '14 08:03

theta


1 Answers

Pass the location of the camera in your cap = cv2.VideoCapture() line:

cap = cv2.VideoCapture('http://<user>:<pass>@<addr>:<port>/videostream.cgi?.mjpg')
like image 80
bugmenot123 Avatar answered Sep 25 '22 09:09

bugmenot123