tags:

views:

35

answers:

1

Hi,

I am using a Mac OS X 10.6 machine. I have OpenCV 2.1 x64 compiled from source using Xcode and its GCC compiler.

I am having trouble using the C++ video reading features of OpenCV. Here is the simple test code I am using (came straight from OpenCV documentation):

#include "cv.h"
#include "highgui.h"

using namespace cv;

int main(int, char**)
{
    VideoCapture cap(0); // open the default camera
    if(!cap.isOpened())  // check if we succeeded
        return -1;

    Mat edges;
    namedWindow("edges",1);
    for(;;)
    {
        Mat frame;
        cap >> frame; // get a new frame from camera
        cvtColor(frame, edges, CV_BGR2GRAY);
        GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5);
        Canny(edges, edges, 0, 30, 3);
        imshow("edges", edges);
        if(waitKey(200) >= 0) break;
    }
    // the camera will be deinitialized automatically in VideoCapture destructor
    return 0;
}

The program compiles fine, but when I try to run it, I see the green light on my webcam come on for a few seconds, then the program exits with the error message:

OpenCV Error: Bad flag (parameter or structure field) (Unrecognized or unsupported array type) in cvGetMat, file /Users/mark/Downloads/OpenCV-2.1.0/src/cxcore/cxarray.cpp, line 2476
terminate called after throwing an instance of 'cv::Exception'
  what():  /Users/mark/Downloads/OpenCV-2.1.0/src/cxcore/cxarray.cpp:2476: error: (-206) Unrecognized or unsupported array type in function cvGetMat

Under debug mode, the matrix still seems to be empty after the cap >> frame line.

I get similar behavior when I try to capture from a video file or an image, so it's not the camera. What is wrong, do you think? Anything I can do to make this work?

EDIT: I'd like to add that if I use the C features, everything works fine. But I would like to stick with C++ if I can.

Thanks

A: 

Try simplifying the program so that you can identify the exact location of the problem, e.g. change your loop so that it looks like this:

for(;;)
{
    Mat frame;
    cap >> frame; // get a new frame from camera
//  cvtColor(frame, edges, CV_BGR2GRAY);
//  GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5);
//  Canny(edges, edges, 0, 30, 3);
//  imshow("edges", edges);
    imshow("edges", frame);
    if(waitKey(200) >= 0) break;
}

If that works OK then try adding the processing calls back in, one at a time, e.g

for(;;)
{
    Mat frame;
    cap >> frame; // get a new frame from camera
    cvtColor(frame, edges, CV_BGR2GRAY);
//  GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5);
//  Canny(edges, edges, 0, 30, 3);
    imshow("edges", edges);
    if(waitKey(200) >= 0) break;
}

and so on...

Once you've identified the problematic line you can then focus on that and investigate further.

Paul R
I've narrowed the problem down, cap >> frame does not seem to grab a frame into the matrix. the matrix is still empty after cap >> frame