How do I access my IP Camera stream?
Code for displaying a standard webcam stream is
import cv2
import numpy as np
cap = cv2.VideoCapture(0)
while(Tr
For getting the IP Camera video link:
IP
and PORT
in browserThe easiest way to stream video via IP Camera !
I just edit your example. You must replace your IP and add /video
on your link. And go ahead with your project
import cv2
cap = cv2.VideoCapture('http://192.168.18.37:8090/video')
while(True):
ret, frame = cap.read()
cv2.imshow('frame',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
cv2.destroyAllWindows()
break
This works with my IP camera:
import cv2
#print("Before URL")
cap = cv2.VideoCapture('rtsp://admin:123456@192.168.1.216/H264?ch=1&subtype=0')
#print("After URL")
while True:
#print('About to start the Read command')
ret, frame = cap.read()
#print('About to show frame of Video.')
cv2.imshow("Capturing",frame)
#print('Running..')
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
I found the Stream URL in the Camera's Setup screen:
Note that I added the Username (admin) and Password (123456) of the camera and ended it with an @ symbol before the IP address in the URL (admin:123456@)
I answer my own question reporting what therefore seems to be the most comprehensive overall procedure to Access IP Camera in Python OpenCV.
Given an IP camera:
IP
address port
where the IP address is accessed protocol
(HTTP/RTSP etc.) specified by the camera provider Then, if your camera is protected go ahead and find out:
username
password
Then use your data to run the following script:
"""Access IP Camera in Python OpenCV"""
import cv2
stream = cv2.VideoCapture('protocol://IP:port/1')
# Use the next line if your camera has a username and password
# stream = cv2.VideoCapture('protocol://username:password@IP:port/1')
while True:
r, f = stream.read()
cv2.imshow('IP Camera stream',f)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cv2.destroyAllWindows()
NOTE: In my original question I specify to being working with Teledyne Dalsa Genie Nano XL Camera. Unfortunately for this kind of cameras this normal way of accessing the IP Camera video stream does not work and the Sapera SDK must be employed in order to grab frames from the device.
You can access most IP cameras using the method below.
import cv2
# insert the HTTP(S)/RSTP feed from the camera
url = "http://username:password@your_ip:your_port/tmpfs/auto.jpg"
# open the feed
cap = cv2.VideoCapture(url)
while True:
# read next frame
ret, frame = cap.read()
# show frame to user
cv2.imshow('frame', frame)
# if user presses q quit program
if cv2.waitKey(1) & 0xFF == ord("q"):
break
# close the connection and close all windows
cap.release()
cv2.destroyAllWindows()
First find out your IP camera's streaming url, like whether it's RTSP/HTTP etc.
Code changes will be as follows:
cap = cv2.VideoCapture("ipcam_streaming_url")
For example:
cap = cv2.VideoCapture("http://192.168.18.37:8090/test.mjpeg")