无法捕获图像Opencv

时间:2012-01-26 08:46:43

标签: visual-studio-2010 opencv

无法捕捉图像,在其他笔记本电脑上工作,我的网络摄像头无法打开。但它可以在其他笔记本电脑上工作。输出为“错误:捕获是空的”

#include "cv.h" 
 #include "highgui.h" 
 #include <stdio.h>  
 // A Simple Camera Capture Framework 
 int main() {
   CvCapture* capture = cvCaptureFromCAM( CV_CAP_ANY );
   if ( !capture ) {
     fprintf( stderr, "ERROR: capture is NULL \n" );
     getchar();
     return -1;
   }
   // Create a window in which the captured images will be presented
   cvNamedWindow( "mywindow", CV_WINDOW_AUTOSIZE );
   // Show the image captured from the camera in the window and repeat
   while ( 1 ) {
     // Get one frame
     IplImage* frame = cvQueryFrame( capture );
     if ( !frame ) {
       fprintf( stderr, "ERROR: frame is null...\n" );
       getchar();
       break;
     }
     cvShowImage( "mywindow", frame );
     // Do not release the frame!
     //If ESC key pressed, Key=0x10001B under OpenCV 0.9.7(linux version),
     //remove higher bits using AND operator
     if ( (cvWaitKey(10) & 255) == 27 ) break;
   }
   // Release the capture device housekeeping
   cvReleaseCapture( &capture );
   cvDestroyWindow( "mywindow" );
   return 0;
 }

2 个答案:

答案 0 :(得分:0)

您可以在CV_CAP_ANY的位置尝试不同的数字。

您的OpenCV也可能没有正确安装,那么您应该按照建议here使用libv4l重新安装它。

使用OpenCV时,您的相机可能不是compatible

答案 1 :(得分:0)

尝试传递-1而不是CV_CAP_ANY