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()?
Pass the location of the camera in your cap = cv2.VideoCapture()
line:
cap = cv2.VideoCapture('http://<user>:<pass>@<addr>:<port>/videostream.cgi?.mjpg')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With