Ask Your Question
1

warpPerspective with INTER_CUBIC or INTER_LINEAR and one channel Int source - crash

asked 2013-08-13 13:27:12 -0600

ThomasZ gravatar image

updated 2013-08-13 13:36:02 -0600

Hallo there,

because I work with a infrared data source I have a one channel intager matrix like

src = Mat::eye(480 , 640 , CV_32S);

now I want to use

warpPerspective (src, dest, transMat, size, WARP_INVERSE_MAP | INTER_LINEAR  ); //-  INTER_CUBIC | INTER_LINEAR | WARP_INVERSE_MAP

for Image rectification. When I do so, my Program crashs and I got the Error:

OpenCV Error: Assertion failed (ifunc != 0) in unknown function, file ..\..\..\src\opencv\modules\imgproc\src\imgwarp.cpp, line 2971

for Example:

#include "opencv/cv.h"
#include "opencv/highgui.h"

int main( int argc, char** argv )
{
    src = Mat::eye(480 , 640 , CV_32S);
    cv::Mat dest;

    Mat transMat = (Mat_<double>(3,3) << 0.83665, -0.0946, 35.96591, 0.00622, 0.49884, 92.2776, 0, -0.00029, 0.94627);

    cv::Size size( src.cols, src.rows);
    warpPerspective (src, dest, transMat, size, WARP_INVERSE_MAP | INTER_LINEAR  ); //-  OR: INTER_CUBIC | INTER_LINEAR

    imshow( "dest", dest );
    waitKey(0);
 }

When I use

src = Mat::eye(480 , 640 , CV_8U);

or

warpPerspective (src, dest, transMat, size, WARP_INVERSE_MAP | INTER_NEAREST  );

everything works fine... what's wrong with my code or is this a bug? Or is the a better way to do this? Or should I use float-Point values? Perhaps this is even faster?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
3

answered 2013-08-13 15:46:11 -0600

Moster gravatar image

updated 2013-08-13 16:00:27 -0600

Ok, I checked the source code of opencv and found the issue. In warpperspective the function cv::remap gets called. link text

 if( interpolation == INTER_LINEAR )
        ifunc = linear_tab[depth];

the linear_tab[depth] will return 0 ( depth for cv_32s is 4). So obviously the assert( ifunc != 0) will fail. So in my eyes this means that integer as a source mat is simply not supported/supposed to work.

edit flag offensive delete link more

Comments

First of all: >>Thank you<< . (is this a bug or a feature?) -> Is there a workaround? What would be the best cast for me (I use a value range of about 0 to 2 000 000 [mK] per pixel)? I take a look into "remapBilinear" and I do not undersand why is INT not supported... is the INT-cast commonly not supported?

ThomasZ gravatar imageThomasZ ( 2013-08-14 05:04:40 -0600 )edit
1

I personally dont understand it either. Short and ushort are supported and casted to float. Uchar is supported, but not schar and neither signed int. It doesnt really make sense to me and I also dont see why casting int to float would make so much trouble.

Moster gravatar imageMoster ( 2013-08-14 05:34:33 -0600 )edit

Thank you :-) ... I report this as a bug to OpenCV and I will see?!

ThomasZ gravatar imageThomasZ ( 2013-08-14 06:34:04 -0600 )edit

I dont think its actually a bug. They intended to do it like this, but I dont really see the reason though.

Moster gravatar imageMoster ( 2013-08-14 06:55:09 -0600 )edit

workaround: img=img.astype('float32')

beniev gravatar imagebeniev ( 2017-12-20 15:23:40 -0600 )edit

Question Tools

Stats

Asked: 2013-08-13 13:27:12 -0600

Seen: 6,097 times

Last updated: Aug 13 '13