Search code examples
pythonopencvlive-streaming

Opencv stream from a camera connected to a remote machine


I am developing a wx application in python for streaming and displaying video from two different webcams. This works fine, but now I need to do this in a different scenario in which the two cameras are connected in separate machine running on Windows connected over a network. My application will run on machine 1. The video from the camera 1 can be fetched using opencv and display on a panel. And also I want to fetch video from camera 2 connected to machine 2, and display it in the application.

Is there any way to do this?


Solution

  • VLC can stream the image of a capture device's over RTSP, see the "Streaming using the GUI" chapter of VLC's "Streaming HowTo".

    Then OpenCV's VideoCapture can grab frames from RTSP stream such as:

    std::string address = "rtsp://<username:password>@<ip_address>:<port>";
    cv::VideoCapture cap;
    
    if(!cap.open(address)) 
    {
        std::cout << "Error opening video stream: " << address << std::endl;
        return -1;
    }
    

    Where address is something like rtsp://127.0.0.1:554 or rtsp://username:password@127.0.0.1:554 if it is password protected.