OpenCV cvCaptureFromCAM 返回零
我在我的笔记本电脑上安装了 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试重复调用。请参考我的问题,看起来很相似。 如何避免“ 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
尝试升级到 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.