降低OpenCV中的图像分辨率 [英] Decrease image resolution in OpenCV

查看:723
本文介绍了降低OpenCV中的图像分辨率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用OpenCV从A4Tech相机捕获图像。当我尝试降低图像分辨率时,图像断言失败:

  CvCapture * camera = cvCreateCameraCapture(1); // 0是笔记本电脑集成摄像头的索引
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); //这失败。 (行71在这里)
// ....
}

输出为:

  HIGHGUI错误:V4L:初始捕获错误:无法加载初始内存缓冲区。 
udpits:main.cpp:71:int main(int,char **):断言`image'失败。
中止


解决方案

正确的方式,但 OpenCV已知有做这种东西的问题。您确定您的相机支持160x140吗?奶酪说我的相机支持 160x120 ,但是当我选择此格式时,似乎没有任何改变。但是有一件事,最好总是检查OpenCV调用的返回,例如:

  CvCapture * camera = cvCreateCameraCapture(1); 
if(!camera)
{
//打印错误并退出
}

您可以做的一件事是调整捕获的帧大小到你想要的分辨率。这不是理想的,我知道,你的CPU将要做这个任务,因此会有一些性能的成本,你的应用程序,但如果你需要的图像是一定的大小和OpenCV不打得很好,没有多少除非您愿意在OpenCV上进行手术。



编辑:



你应该做的一件事是检查这些值是否真的设置。所以设置完成后,用 cvGetCaptureProperty()检索它们。


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

解决方案

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

这篇关于降低OpenCV中的图像分辨率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆