windows OpenCV cvCaptureFromCAM 返回零

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6749067/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 17:30:08  来源:igfitidea点击:

OpenCV cvCaptureFromCAM returns zero

c++windowsimage-processingopencvcamera

提问by Sodrohu

I got OpenCV 2.1 installed on my laptop and is trying to implement a face detection program. I'm using Logitech C210 for my project. I know the camera is okay because the software detects and displays it, and starting facedetect.exe in the samples directory shows the camera to be working. But somehow when using the original facedetect.cpp code in my VS2010 Ultimate I couldn't even get the cvCaptureFromCAM to work! Here's my code:

我在我的笔记本电脑上安装了 OpenCV 2.1 并正在尝试实施面部检测程序。我的项目使用罗技 C210。我知道相机没问题,因为软件会检测并显示它,并且在示例目录中启动 facedetect.exe 显示相机正在工作。但不知何故,在我的 VS2010 Ultimate 中使用原始 facedetect.cpp 代码时,我什至无法让 cvCaptureFromCAM 工作!这是我的代码:

#include "stdafx.h"
#include <iostream>
#include "cv.h"
#include "highgui.h"

using namespace std;
using namespace cv;

int main(int, char**) {
IplImage* frame;
// CvCapture* cap = cvCaptureFromCAM(-1);
//  cvNamedWindow( "Example2_9", CV_WINDOW_AUTOSIZE );
CvCapture* capture;
cvWaitKey(20);
capture = cvCreateCameraCapture( -1 ); //yes, if 0 doesn't work try with -1
//assert( capture != NULL );

for(;;) {
    frame = cvQueryFrame(capture);

    if(frame == NULL)
        return -1;

   imshow("cap", frame);
    if(waitKey(30) >= 0)
        break;
}

}

Okay, so that isn't the actual facedetect code(it's too long), but it highlights the problem here it think:

好的,所以这不是实际的 facedetect 代码(太长了),但它突出了它认为的问题:

Using breakpoints I found out that the value capture after cvCaptureFromCAM is 0x000000. This isn't supposed to happen, is it? Can someone tell me what's going on?

使用断点我发现在 cvCaptureFromCAM 之后捕获的值是 0x000000。这不应该发生,是吗?有人可以告诉我这是怎么回事吗?

回答by coder9

Try duplicating the calls. Please refer to my question which looks similar. How to avoid "Video Source -> Capture source" selection in OpenCV 2.3.0 - Visual C++ 2008

尝试复制呼叫。请参考我的问题,它看起来很相似。如何避免 OpenCV 2.3.0 中的“视频源 -> 捕获源”选择 - Visual C++ 2008

回答by Patrizio Bertoni

Try upgrading to OpenCV 2.4.2. Not the exact same problem ( for me queryFrame() was returning always NULL using v2.2.0), but now it works like a charm. Maybe are just compatibility issues.

尝试升级到 OpenCV 2.4.2。不是完全相同的问题(对我来说 queryFrame() 使用 v2.2.0 总是返回 NULL),但现在它就像一个魅力。也许只是兼容性问题。