Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV - how to capture rtsp video stream

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

like image 257
Niedved Avatar asked Jan 10 '14 10:01

Niedved


People also ask

How do I record streaming video with OpenCV?

Steps to capture a video:Use cv2. VideoCapture( ) to get a video capture object for the camera. Set up an infinite while loop and use the read() method to read the frames using the above created object. Use cv2.

Can OpenCV capture video?

OpenCV provides a very simple interface to do this. Let's capture a video from the camera (I am using the built-in webcam on my laptop), convert it into grayscale video and display it. Just a simple task to get started. To capture a video, you need to create a VideoCapture object.


1 Answers

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);
}
like image 140
Murat Şeker Avatar answered Sep 20 '22 23:09

Murat Şeker