PHYTON+IP CAMARA+OBJECT RECOGNITION+CV2

174 views
Skip to first unread message

Rocio Lorena

unread,
Mar 3, 2016, 3:21:48 PM3/3/16
to Python GCU Forum
How do you connect an IP camera using CV2 python? CV2 is a library that works with a webcam but "apparently" does not work with an IP camera.

Rajnish Singh

unread,
Mar 20, 2016, 3:09:25 PM3/20/16
to Python GCU Forum
#include "cv.h"
#include "highgui.h"
#include <iostream>

int main(int, char**) {
    cv::VideoCapture vcap;
    cv::Mat image;

    const std::string videoStreamAddress = "rtsp://cam_address:554/live.sdp"; 
    /* it may be an address of an mjpeg stream, 
    e.g. "http://user:pass@cam_address:8081/cgi/mjpg/mjpg.cgi?.mjpg" */

    //open the video stream and make sure it's opened
    if(!vcap.open(videoStreamAddress)) {
        std::cout << "Error opening video stream or file" << std::endl;
        return -1;
    }

    //Create output window for displaying frames. 
    //It's important to create this window outside of the `for` loop
    //Otherwise this window will be created automatically each time you call
    //`imshow(...)`, which is very inefficient. 
    cv::namedWindow("Output Window");

    for(;;) {
        if(!vcap.read(image)) {
            std::cout << "No frame" << std::endl;
            cv::waitKey();
        }
        cv::imshow("Output Window", image);
        if(cv::waitKey(1) >= 0) break;
    }   
}
Reply all
Reply to author
Forward
0 new messages