调整图像大小并改变其深度 [英] resize an image and changing its depth

查看:78
本文介绍了调整图像大小并改变其深度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要调整 IplImage 的大小并将其转换为不同深度的 CvMat,这是我目前编写的代码:

I need to resize an IplImage and convert it into a CvMat of different depth, this is the code I've written so far:

void cvResize2(IplImage *imgSrc, IplImage *imgDst)
{
    IplImage *imgTemp;
    imgTemp = cvCreateImage( cvGetSize( imgSrc ), IPL_DEPTH_64F, 1 );

    cvScale( imgSrc, imgTemp, 1/255., 0.0 );
    cvResize( imgTemp, imgDst );
}

源图像是灰度图像,目标图像是 64F 位深.cvScale 只在相同大小的图像之间缩放,因此是临时图像.

The source image is grayscale, the destination one is 64F bit deep. cvScale only scales between images of same size, hence the temp image.

程序在调用 cvResize 时引发以下异常:

The program rises the following exception when invoking cvResize:

OpenCV Error: Assertion failed (func != 0) in resize, file /tmp/buildd/opencv-2.1.0/src/cv/cvimgwarp.cpp, line 1488
terminate called after throwing an instance of 'cv::Exception'
what():  /tmp/buildd/opencv-2.1.0/src/cv/cvimgwarp.cpp:1488: error: (-215) func != 0 in function resize

我不知道为什么,我已经检查过图像是否符合强加的条件

I can't figure out why, I've checked that the images respect the conditions imposed

  • src:512x384,8 深度
  • tmp:512x384,64 深度
  • dst:64x64,64 深度

有什么线索吗?提前致谢

Any clues? Thanks in advance

推荐答案

您可能发现了一个错误.我也可以复制它(Ubuntu 64 位,OpenCV-2.1.0).如果您使用 32 位浮点精度,它可以工作,但会因 64 位浮点数而崩溃.我的建议是将您的 OpenCV 更新到最新版本,看看问题是否消失.如果没有,则在调试模式下构建库并逐步执行抛出断言的函数.从 cvimgwarp.cpp 中的罪魁祸首来源来看,它似乎无法找到用于目标图像的插值方法.

You may have found a bug. I can reproduce it on my end, too (Ubuntu 64-bit, OpenCV-2.1.0). If you use 32-bit floating point precision, it works, but crashes with 64-bit floats. My recommendation is to update your OpenCV to the most recent version and see if the problem goes away. If not, then build the library in debug mode and step through the function that is throwing the assertion. From looking at the culprit source in cvimgwarp.cpp, it looks like it's unable to find an interpolation method to use for the destination image.

这篇关于调整图像大小并改变其深度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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