Resize matrix in Java

asked 2014-04-09 11:26:32 -0600

reem gravatar image

updated 2014-04-09 11:34:47 -0600

berak gravatar image

Hello,

I am trying to resize a matrix of CvType.CV_32S to a smaller matrix. Every time I use the Imgproc.resize() methode, I am getting the following exception:

OpenCV Error: Assertion failed (func != 0) in cv::resize, file ........\opencv\modules\imgproc\src\imgwarp.cpp, line 1970 CvException [org.opencv.core.CvException: cv::Exception: ........\opencv\modules\imgproc\src\imgwarp.cpp:1970: error: (-215) func != 0 in function cv::resize ]

My code looks linke this:

Imgproc.resize(img16u, liveMatHalfRawData, new Size(img16u.rows()/2,img16u.cols()/2), 0, 0,
                Imgproc.INTER_CUBIC);

Thanks for help,

reem

edit retag flag offensive close merge delete

Comments

btw, did you want new Size(img16u.cols()/2,img16u.rows()/2) ?

berak gravatar imageberak ( 2014-04-09 11:34:13 -0600 )edit

of course, the new liveMatHalfRawData-matrix should have the half size of the old one. that means to me, that rows and cols schould be half also.

reem gravatar imagereem ( 2014-04-09 11:37:33 -0600 )edit

oh i only meant , that you might have swapped rows & cols there.

berak gravatar imageberak ( 2014-04-09 11:47:06 -0600 )edit

the img16u-matrix is quadratic. but I really dont understand the problem. or maybe the resize()-method is not able to resize() 32Bit-singned-Int Matrices.

reem gravatar imagereem ( 2014-04-09 11:54:11 -0600 )edit

ah, ok. but you seem to be right, there's no entry for ints here

berak gravatar imageberak ( 2014-04-09 12:13:26 -0600 )edit

but it doesent work with other types. if you want to reproduce the error, here some code:

float[] a = {   64000f, 12000f, 1f, 2f };
        Mat src = new Mat(2, 2, CvType.CV_32S);
        src.put(0, 0, a);       
        Mat dst = new Mat();
        Imgproc.resize(src, dst, src.size(), 0.5, 0.5,
                Imgproc.INTER_LINEAR);
reem gravatar imagereem ( 2014-04-09 12:17:15 -0600 )edit

you still got an int mat there. (you tried to put float data into it, but that does not change the type)

berak gravatar imageberak ( 2014-04-09 12:22:08 -0600 )edit

Hey,

using a float-array instead of an int-array solved the problem. And dont forget to change the

CvType.CV_32F

But of course I had to waste more memory, because of the unneeded float-arrays...

Regards, reem

reem gravatar imagereem ( 2014-04-10 09:36:30 -0600 )edit