Ask Your Question
0

Resize Mat error components

asked 2017-07-28 05:02:18 -0500

Alvaro gravatar image

I want to resize a matrix but the components are diferents. This is the code

int p = 0;
Mat A = Mat(20,20, CV_64F);
for (int i = 0; i < 20; i++)
{
    for (int j = 0; j < 20; j++)
    {
        A.at<double>(i, j) = p;
        p++;
    }
}
cout << A <<endl;

Mat m = A.col(0);
for(int i=0;i<A.cols-1;i++)
vconcat(m, A.col(i+1), m);

Mat z = m(Range(0, 4), Range(0, 1));
Mat dest;
cout << z <<endl;
resize(z, dest, cv::Size(2, 2));
cout << dest <<endl;

and this the output:

[0;
 20;
 40;
 60]
[10, 10;
 50, 50]

The first output is a matrix z, and the sencond is matrix is produce by the resizing of the mat z.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-07-28 05:49:40 -0500

berak gravatar image

updated 2017-07-28 06:41:23 -0500

your result from resize() is entirely correct.

to resize from 4 elements to 2 vertically, linear interpolation is applied (INTER_LINEAR is the default flag), so,

 10 =  0 + (20 -  0) / 2
 50 = 40 + (60 - 40) / 2

can it be, you wanted to reshape it from 4x1 to 2x2 ?

z = z.reshape(1,2);
[0, 20;
 40, 60]
edit flag offensive delete link more

Comments

Yes!!! Thank you so much.

Alvaro gravatar imageAlvaro ( 2017-07-31 06:16:17 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2017-07-28 05:02:18 -0500

Seen: 138 times

Last updated: Jul 28 '17