Soroush Rabiei
Soroush Rabiei

Reputation: 10868

Decrease image resolution in OpenCV

I'm using OpenCV to capture images from A4Tech camera. When I try to decrease image resolution, image assertion fails:

CvCapture *camera = cvCreateCameraCapture(1); // 0 is index of Laptop integrated camera
cvSetCaptureProperty( camera, CV_CAP_PROP_FRAME_WIDTH, 160 );
cvSetCaptureProperty( camera, CV_CAP_PROP_FRAME_HEIGHT, 140 );
assert(camera); // This is passed
while(true)
{
    // ....
    IplImage * image=cvQueryFrame(camera);
    assert(image); // This fails. (Line 71 is here)
    // ....
}

Output is:

HIGHGUI ERROR: V4L: Initial Capture Error: Unable to load initial memory buffers.
udpits: main.cpp:71: int main(int, char**): Assertion `image' failed.
Aborted

Upvotes: 2

Views: 6487

Answers (1)

karlphillip
karlphillip

Reputation: 93410

You seem to be doing it the right way, but OpenCV is known to have issues doing this kind of stuff. Are you sure your camera supports 160x140? Cheese says my camera supports 160x120, but when I select this format nothing seems to change.

One thing though, it's best to always check the return of OpenCV calls, for instance:

CvCapture *camera = cvCreateCameraCapture(1);
if (!camera)
{
    // print error and exit
}

One thing you could do is resize the captured frame to the resolution you want. It's not ideal, I know, your CPU is going to do this task and therefore there will be some performance cost to your application, but if you need the image to be of a certain size and OpenCV is not playing nice there ain't much you can do, unless you are willing to make a surgery on OpenCV.

EDIT:

One thing you should do is check whether these values were really set. So after setting them, retrieve them with cvGetCaptureProperty().

Upvotes: 6

Related Questions