Access IP Camera in Python OpenCV

后端 未结 11 1382
执笔经年
执笔经年 2020-11-29 01:49

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         


        
相关标签:
11条回答
  • 2020-11-29 02:46

    An IP camera can be accessed in opencv by providing the streaming URL of the camera in the constructor of cv2.VideoCapture.

    Usually, RTSP or HTTP protocol is used by the camera to stream video. An example of IP camera streaming URL is as follows:

    rtsp://192.168.1.64/1

    It can be opened with OpenCV like this:

    capture = cv2.VideoCapture('rtsp://192.168.1.64/1')
    

    Most of the IP cameras have a username and password to access the video. In such case, the credentials have to be provided in the streaming URL as follows:

    capture = cv2.VideoCapture('rtsp://username:password@192.168.1.64/1')
    
    0 讨论(0)
  • 2020-11-29 02:46

    To access an Ip Camera, first, I recommend you to install it like you are going to use for the standard application, without any code, using normal software.

    After this, you have to know that for different cameras, we have different codes. There is a website where you can see what code you can use to access them:

    https://www.ispyconnect.com/sources.aspx

    But be careful, for my camera (Intelbras S3020) it does not work. The right way is to ask the company of your camera, and if they are a good company they will provide it.

    When you know your code just add it like:

    cap = cv2.VideoCapture("http://LOGIN:PASSWORD@IP/cgi-bin/mjpg/video.cgi?&subtype=1")
    

    Instead LOGIN you will put your login, and instead PASSWORD you will put your password.

    To find out camera's IP address there is many softwares that you can download and provide the Ip address to you. I use the software from Intelbras, but I also recommend EseeCloud because they work for almost all cameras that I've bought:

    https://eseecloud.software.informer.com/1.2/

    In this example, it shows the protocol http to access the Ip camera, but you can also use rstp, it depends on the camera, as I said.

    If you have any further questions just let me know.

    0 讨论(0)
  • 2020-11-29 02:47

    In pycharm I wrote the code for accessing the IP Camera like:

    import cv2
    
    cap=VideoCapture("rtsp://user_name:password@IP_address:port_number")
    
    ret, frame=cap.read()
    

    You will need to replace user_name, password, IP and port with suitable values

    0 讨论(0)
  • 2020-11-29 02:47

    Getting the correct URL for your camera seems to be the actual challenge! I'm putting my working URL here, it might help someone. The camera is EZVIZ C1C with exact model cs-c1c-d0-1d2wf. The working URL is

    rtsp://admin:SZGBZT@192.168.1.2/h264_stream
    

    where SZGBZT is the verification code found at the bottom of the camera. admin is always admin regardless of any settings or users you have.

    The final code will be

    video_capture = cv2.VideoCapture('rtsp://admin:SZGBZT@192.168.1.2/h264_stream')
    
    0 讨论(0)
  • 2020-11-29 02:51

    As mentioned above by @Gustavo GeoDrones you can find your Cam URL using https://www.ispyconnect.com/sources.aspx.

    Go to the website, click on the model of your camera and a "Cam Video URL Generator" will appear. Insert your IP, username, etc. and click on "generate".

    Cam URL for my Canon VB-H45 is (of course with my specific username, password and IP):

    http://username:password@IP/-wvhttp-01-/video.cgi
    

    The final code:

    cap = cv2.VideoCapture('http://username:password@IP/-wvhttp-01-/video.cgi')
    
    0 讨论(0)
提交回复
热议问题