OpenCV cvCaptureFromCAM返回零 [英] OpenCV cvCaptureFromCAM returns zero

查看:504
本文介绍了OpenCV cvCaptureFromCAM返回零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的笔记本电脑上安装了OpenCV 2.1,试图实现一个面部检测程序。我正在为我的项目使用Logitech C210。我知道相机是好的,因为软件检测和显示它,并启动facesetect.exe在示例目录显示相机正在工作。但不知何故当使用原来facesetect.cpp代码在我的VS2010终极我甚至不能得到cvCaptureFromCAM工作!这是我的代码:

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:

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

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?

推荐答案

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

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 cvCaptureFromCAM返回零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆