OpenCV cvCaptureFromCAM 返回零

发布于 2024-11-25 05:06:02 字数 922 浏览 0 评论 0原文

我在我的笔记本电脑上安装了 OpenCV 2.1,并尝试实现一个人脸检测程序。我在我的项目中使用 Logitech 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;
}

}

好的,这不是实际的人脸检测代码(它太长了),但它突出了它认为的问题:

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

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:

#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:

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

最美的太阳 2024-12-02 05:06:02

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

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

红焚 2024-12-02 05:06:02

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文