Opencv – resize an image and changing its depth

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: 512×384, 8 depth
  • tmp: 512×384, 64 depth
  • dst: 64×64, 64 depth

Any clues?
Thanks in advance

Best Answer

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.

Related Topic