OpenCV - 如何捕获rtsp视频流 [英] OpenCV - how to capture rtsp video stream

查看:4146
本文介绍了OpenCV - 如何捕获rtsp视频流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如我们有工作rtsp流测试像:rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov(它在发布此帖的时候工作)

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)

现在我想在openCV中捕获这个视频流(opencv 2.4.7 / 2.4.8)
我的代码在本地电影文件上工作得很好,但是当我尝试捕获rtsp时我收到msgs像:无法读取电影文件rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov

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"

我尝试过几种不同的方式, / p>

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");
}

或:

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;
}

有什么想法吗?

-

Niedved

推荐答案

以下代码适用于我,没有任何问题。如果您有流的用户名和密码,请不要忘记将其包含在网址地址中。

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);
}

这篇关于OpenCV - 如何捕获rtsp视频流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆