Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

resize an image and changing its depth

Tags:

opencv

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 );
}

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

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 depth
  • tmp: 512x384, 64 depth
  • dst: 64x64, 64 depth

Any clues? Thanks in advance

like image 302
Daniele Avatar asked Sep 12 '11 09:09

Daniele


People also ask

What is it called when you resize an image?

In computer graphics and digital imaging, image scaling refers to the resizing of a digital image. In video technology, the magnification of digital material is known as upscaling or resolution enhancement.

What is the difference between resizing and resampling an image?

Image resizing keeps the number of pixels in your image the same and affects only how large your image will print (the Document Size). Image resampling physically changes the number of pixels in your image (the Pixel Dimensions).


1 Answers

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.

like image 64
mpenkov Avatar answered Sep 20 '22 22:09

mpenkov