Access IP Camera in Python OpenCV

后端 未结 11 1381
执笔经年
执笔经年 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:27

    For getting the IP Camera video link:

    1. Open the IP Camera with given IP and PORT in browser
    2. Right click the video and select "copy image address"
    3. Use that address to capture video
    0 讨论(0)
  • 2020-11-29 02:31

    The 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
    
    0 讨论(0)
  • 2020-11-29 02:32

    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@)

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

    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:

    • Find your camera IP address
    • Find the port where the IP address is accessed
    • Find the protocol (HTTP/RTSP etc.) specified by the camera provider

    Then, if your camera is protected go ahead and find out:

    • your username
    • your 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.

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

    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()
    
    0 讨论(0)
  • 2020-11-29 02:39

    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")
    
    0 讨论(0)
提交回复
热议问题