c++ - openCV 说找不到相机

标签 c++ opencv visual-studio-2012

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

当我执行我的代码时:

enter image description here

我选择了确定:

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;
    }

感谢提前

最佳答案

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

关于c++ - openCV 说找不到相机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15032427/

相关文章:

父返回子中的 C++ 函数

c++ - 什么是空间开销(当引用 C++ 数组时)?

Python 为图像添加一个 channel

python - 图像定位 OpenCV

c# - 如何禁用向上/向下键滚动 Visual Studio 中的方法重载?

c++ - QTableWidget更新项

macos - 从 Qt 创建者中构建时,qmake 找不到 opencv 包

c++ - 存储少量数据供以后使用的最佳 C++ 方法

asp.net - VS2012 RC 中不识别外键

c# - 无法访问 asp :TextBox tag from the C# file : the name 'txtUsername' does not exist in the current context