Why does my program not show output on namedWindow ?

asked 2014-03-29 07:30:05 -0500

hoder gravatar image

updated 2014-03-30 03:20:10 -0500

berak gravatar image

I am using opencv 2.4.8 on VS express 2013 for desktop.I am using C++ language.

#include "opencv2/highgui/highgui.hpp"
#include "opencv2\imgproc\imgproc.hpp"
int main() {
    cv::namedWindow("Example3", cv::WINDOW_AUTOSIZE);
    cv::VideoCapture cap;
    cap.open(0);
    if (!cap.isOpened())
        return -2;
    cv::Mat frame;
    while (1) {
        cap >> frame;
        if (!frame.data) return -1;
        cv::imshow("Example3", frame);
        if (cv::waitKey(33) >= 0) break;
    }
    return 0;
}

This program is always returning -1 and not showing any output on namedwindow.

But, if I do cap.open("file_name"); It gives desired output (i.e. plays the video)
What may be wrong?

edit retag flag offensive close merge delete

Comments

try : if (frame.empty()) continue; // as your first frame might be invalid ( camera warmup )

berak gravatar imageberak ( 2014-03-30 03:21:28 -0500 )edit