OpenCV - how to capture rtsp video stream

2019-02-03 22:07发布

问题:

for example we have working rtsp stream test like: "rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov" (it works in moment of publishing this post)

Now I want to catch this video stream in openCV (opencv 2.4.7 / 2.4.8) I've my code works perfectly on local movie files but when I try to capture rtsp I get msgs like: "Couldn't read movie file rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov"

I've tried few different ways like:

CvCapture *camera = cvCreateFileCapture("rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov"); 
if (camera == NULL) {
 printf("video is null, aborting...");
 return -1;
}
else{ 
 printf("video ok");
}

or:

cv::VideoCapture vcap;
//open the video stream and make sure it's opened
if(!vcap.open("rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov")) {
    std::cout << "Error opening video stream or file" << std::endl;
    return -1;
}

Any idea ?

--

Niedved

回答1:

The following code works for me without any problem. If you have a username and password for the stream, do not forget to include it in the url address.

cv::VideoCapture capture(url);

if (!capture->isOpened()) {
    //Error
}

cv::namedWindow("TEST", CV_WINDOW_AUTOSIZE);

cv::Mat frame;

while(m_enable) {
    if (!capture->read(frame)) {
        //Error
    }
    cv::imshow("TEST", frame);

    cv::waitKey(30);
}