PDA

View Full Version : OpenCV --> window reopens while webcam outputing..How to stop it?



hakermania
13th November 2010, 21:04
That's the code:

#include "opencv/highgui.h"
int main( int argc, char** argv ) {
/* // Capture the Image from the webcam
CvCapture *pCapturedImage = cvCreateCameraCapture(0);

// Get the frame
IplImage *pSaveImg = cvQueryFrame(pCapturedImage);

// Save the frame into a file
cvSaveImage("test.jpg" ,pSaveImg);

*/


cvNamedWindow( "Example2", CV_WINDOW_AUTOSIZE );

CvCapture* capture = cvCreateCameraCapture(0) ;
IplImage* frame;

while(1) {
frame = cvQueryFrame( capture );
if( !frame ) break;
cvShowImage( "Example2", frame );
char c = cvWaitKey(33);
if( c == 27 ) break;

}
cvReleaseCapture( &capture );
cvDestroyWindow( "Example2" );

}

It actually shows the webcam video till it gets [Esc]
This is OK but when I manually close the window from the X button then it reopens...How can i avoid this from being done?

ChrisW67
14th November 2010, 01:11
My money is on cvShowImage() unhiding the window, which still exists when "closed" it is just hidden until the cvNamedWindow object is destroyed. As for how you break out of the loop when the cvNamedWindow is "closed": you probably should ask this question in an OpenCV forum because it has nothing to do with Qt.

HelderC
15th November 2010, 17:44
Hey, look this example http://qt-apps.org/content/show.php/Qt+Opencv+webcam+viewer?content=89995

The author put the captured video inside QMainWindow and you don't need the highgui.