1

I am going through the book Learning OpenCV 3 and test out the video example 2.3. I could edit, compile and run it, but the problem is that it closed down immediately.

// DisplayPicture.cpp : Defines the entry point for the console application.
//

//#include "opencv2/opencv.hpp" // Include file for every supported OpenCV function 


#include "opencv2\imgproc\imgproc.hpp"
#include "opencv2\highgui\highgui.hpp"
#include <opencv2/videoio.hpp>

#include <stdio.h>
#include <string.h>

using namespace cv;
using namespace std;

int main(int argc, char** argv) {
    namedWindow("video3", WINDOW_AUTOSIZE);
    VideoCapture cap;
    cap.open( string(argv[1]));
    int tell = 0;
    Mat frame;
    for (;;) {
        cap >> frame;
        //waitKey(30);
        if (frame.empty())
        {
            break;
            //end of film
        }
        imshow("video3", frame);
    }
    return 0;
}

I found that my computer processed the data too fast. It could not read the next frame fast enough. if (frame.empty()) became true the program reached the break statement and ended.

By adding a waitkey of 30 millisec before viewing the image frame, the video program works very well. At least I can view the video. Since this example is from the 'bible' it should work, but not with my computer.

I am running a MSI gt72 2PE computer with nvidia gtx880m. Not sure if that matters.

I assume that adding a waitKey(30) is not appropriate, so I am seeking suggestions as to what could be done differently.

Craig Scott
  • 9,238
  • 5
  • 56
  • 85
User1953
  • 171
  • 1
  • 7

0 Answers0