您好,每个人都想使用我的相机通过openCV和Visual Studio 2012(C++)来获取视频,但出现错误消息:“未检测到相机!!!”
图片解释了我的问题:
当我执行我的代码时:
我选择确定:
我的代码:
#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;
}
谢谢前进
最佳答案
您的代码没有错。再次检查您的网络摄像头。 (例如,网络摄像头驱动程序),并进行测试:"capture = cvCaptureFromCAM( -1 );"
关于c++ - openCV说找不到相机,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15032427/