如何在不关闭正在运行的程序的情况下释放 OpenCV 中的相机?我使用了以下代码,但相机仍处于开启状态。
main( int argc, char* argv[] )
{
int j;
CvCapture* capture = NULL;
capture = cvCreateCameraCapture( 0 );
IplImage *frames = cvQueryFrame(capture);
//Create a new window
cvNamedWindow( "Recording ...press ESC to stop !", CV_WINDOW_AUTOSIZE );
while(1)
{
if (j<10)
{
frames = cvQueryFrame( capture );
cvShowImage( "Recording ...press ESC to stop !", frames );
}
j++;
if(j==10)
cvReleaseCapture ( &capture );
char c = cvWaitKey(33);
if( c == 27 ) break;
}
cvDestroyWindow ( "Recording ...press ESC to stop !");
return 0;
}