1
votes

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?

2
Saw that earlier, I think it's different enough. I got problems in OpenCV 2.1, not 2.3. On a windows platform.Sodrohu
Did you check all 3 of the above duplicates, i.e. not just the first one ?Paul R
I did. Two of em runs on Ubuntu. Mine was Windows 7 32-bit.The other one didn't specify her OS but either way that post wasn't helpful to me.Sodrohu
It means it can't open the camera. Either you don't have a camera(!), the driver isn't working or some other app (typically skpe) has grabbed the cameraMartin Beckett

2 Answers

0
votes

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

0
votes

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.