Image not being displayed using webcam in opencv

534 views Asked by At

I have just started to learn opencv, but now stuck in a program.

I am trying to run a program which just displays the video from the in-built webcam.

#include <opencv2\highgui\highgui.hpp>

int main() {
cvNamedWindow("Streaming", CV_WINDOW_AUTOSIZE);
CvCapture* capture = cvCreateCameraCapture(0);
IplImage* frame;
while (1) {
    frame = cvQueryFrame(capture);
    if (!frame) break;
    cvShowImage("Streaming", frame);
    char c = cvWaitKey(33);
    if (c == 27) break;
}
cvReleaseCapture(&capture);
cvDestroyWindow("Streaming");
return 0;
}

All is working fine no errors being thrown, but when i run the program a new window named Streaming is being opened and my webcam light also switch on (means webcam has started), but inspite of all this no video is being displayed in the new window which opened.

Can any help on this? I am just a beginner in this.

Thanks in advance!!

1

There are 1 answers

0
DanBC On BEST ANSWER

I suggest migrating from your old cv implementation to the newly made methods from OpenCV 2.

Take a look at the VideoCapture class, it has much more intuitive methods. For example, you can use the method isOpened() to check if your webcam has been successfully activated.

There's also a nice tutorial over here to help you out with the new methods.