Ask Your Question
0

How can I reshape matrix 1xn to matrix sqrt(n)xsqrt(n) ?

asked 2017-01-20 06:49:08 -0600

Shabrina gravatar image

updated 2017-01-20 06:55:49 -0600

I have matrix 1x16. I will reshape this matrix to 4x4. How can I reshape this matrix? I just use this code, but the program was break.

//transpose 
    Mat det0 = Mat(d1);
    Mat dt1;
    dt1 = det0.reshape(0,4);
    cout << " Sebelum transpose "<<det0 <<endl;
    cout << "coba" << dt1 <<endl;

`

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-01-20 07:00:22 -0600

berak gravatar image

updated 2017-01-20 07:03:42 -0600

Mat square(const Mat &in)
{
    size_t n = in.total(); //count of all elements
    size_t ns = (size_t)sqrt(double(n));   // squared
    CV_Assert(ns*ns == n); //make sure, there was no rounding.
    return  in.reshape(0, ns);
}
edit flag offensive delete link more

Comments

I just trying these code but the program still break.

Shabrina gravatar imageShabrina ( 2017-01-20 08:04:50 -0600 )edit

please add the exact error msg to your question

also, we need to see, what d1 is, ynd how you initialize that.

berak gravatar imageberak ( 2017-01-20 09:13:30 -0600 )edit

Thank you the problem was solved, I get the misplace to initialize yesterday. Thank you for your attention :))

Shabrina gravatar imageShabrina ( 2017-01-21 22:24:37 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-01-20 06:49:08 -0600

Seen: 246 times

Last updated: Jan 20 '17