openCV说无法找到相机

时间:2013-02-22 20:10:09

标签: c++ opencv visual-studio-2012

大家好我即兴使用我的相机使用openCV和Visual Studio 2012(C ++)来获取视频,但会出现一条错误消息:“没有检测到相机!!!”  图片解释了我的问题:

我执行我的代码:

enter image description here

我选择了Ok:

enter image description here

我的代码:

#include <opencv2/objdetect/objdetect.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>


#include <iostream>
#include <stdio.h>


using namespace std;
using namespace cv;



int main( int argc, const char** argv )
{
    CvCapture* capture = 0;
    Mat frame, frameCopy, image;


    capture = cvCaptureFromCAM( CV_CAP_ANY ); //0=default, -1=any camera, 1..99=your camera

if( !capture )
{
cout << "No camera detected" << endl;
system("pause");
}

cvNamedWindow( "result", CV_WINDOW_AUTOSIZE );

if( capture )
{
cout << "In capture ..." << endl;
for(;;)
{
IplImage* iplImg = cvQueryFrame( capture );
frame = iplImg;

if( frame.empty() )
break;
if( iplImg->origin == IPL_ORIGIN_TL )
frame.copyTo( frameCopy );
else
flip( frame, frameCopy, 0 );

cvShowImage( "result", iplImg );

if( waitKey( 10 ) >= 0 )
break;
}
// waitKey(0);
}



cvWaitKey(50);

cvReleaseCapture( &capture );
cvDestroyWindow( "result" );

return 0;
    }

感谢您提前

1 个答案:

答案 0 :(得分:2)

你的代码没有错。再次检查您的网络摄像头。 (例如,网络摄像头驱动程序),并测试:"capture = cvCaptureFromCAM( -1 );"