Ask Your Question
0

Why videocapture is not showing any frames?

asked 2018-04-30 05:20:51 -0600

malloc123 gravatar image

I'm writing some simple code for opencv3 to process video stream

#include<opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/videoio/videoio.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include<iostream>
#include<conio.h>           


int main() {



std::string video = "/videos/video1.avi";
cv::VideoCapture capture(video);

if (!capture.isOpened())
    throw "Error when reading steam_avi";
cv::Mat frame;

for (;;)
{


    capture >> frame;
    if (!frame.empty()) {
        cv::imshow("name", frame);
    }
}


return(0);

}

But I always get a gray window that doesn't show any image what can be my problem?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2018-04-30 05:23:22 -0600

berak gravatar image

updated 2018-04-30 05:27:01 -0600

add a

 cv::waitKey(10);

after the imshow(); else nothing will get drawn ever.

(imshow() only copies an image pointer, waitKey() holds the internal event loop, which will trigger the drawing/update finally)

also note: if you ever get here:

if (frame.empty()) {

when playing a video file, it means , that you reached the last frame (and you should probably return, or break out of the loop)

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-04-30 05:20:51 -0600

Seen: 178 times

Last updated: Apr 30 '18