Decrease image resolution in OpenCV

别来无恙 提交于 2019-12-19 04:38:22

问题


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

回答1:


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().



来源:https://stackoverflow.com/questions/8339077/decrease-image-resolution-in-opencv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!