OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Sat, 21 Jan 2017 22:24:37 -0600How can I reshape matrix 1xn to matrix sqrt(n)xsqrt(n) ?http://answers.opencv.org/question/123305/how-can-i-reshape-matrix-1xn-to-matrix-sqrtnxsqrtn/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;
`Fri, 20 Jan 2017 06:49:08 -0600http://answers.opencv.org/question/123305/how-can-i-reshape-matrix-1xn-to-matrix-sqrtnxsqrtn/Answer by berak for <p>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. </p>
<pre><code>//transpose
Mat det0 = Mat(d1);
Mat dt1;
dt1 = det0.reshape(0,4);
cout << " Sebelum transpose "<<det0 <<endl;
cout << "coba" << dt1 <<endl;
</code></pre>
<p>`</p>
http://answers.opencv.org/question/123305/how-can-i-reshape-matrix-1xn-to-matrix-sqrtnxsqrtn/?answer=123308#post-id-123308
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);
}
Fri, 20 Jan 2017 07:00:22 -0600http://answers.opencv.org/question/123305/how-can-i-reshape-matrix-1xn-to-matrix-sqrtnxsqrtn/?answer=123308#post-id-123308Comment by Shabrina for <pre><code>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);
}
</code></pre>
http://answers.opencv.org/question/123305/how-can-i-reshape-matrix-1xn-to-matrix-sqrtnxsqrtn/?comment=123486#post-id-123486Thank you the problem was solved, I get the misplace to initialize yesterday. Thank you for your attention :))Sat, 21 Jan 2017 22:24:37 -0600http://answers.opencv.org/question/123305/how-can-i-reshape-matrix-1xn-to-matrix-sqrtnxsqrtn/?comment=123486#post-id-123486Comment by berak for <pre><code>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);
}
</code></pre>
http://answers.opencv.org/question/123305/how-can-i-reshape-matrix-1xn-to-matrix-sqrtnxsqrtn/?comment=123325#post-id-123325please add the exact error msg **to your question**
also, we need to see, what d1 is, ynd how you initialize that.Fri, 20 Jan 2017 09:13:30 -0600http://answers.opencv.org/question/123305/how-can-i-reshape-matrix-1xn-to-matrix-sqrtnxsqrtn/?comment=123325#post-id-123325Comment by Shabrina for <pre><code>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);
}
</code></pre>
http://answers.opencv.org/question/123305/how-can-i-reshape-matrix-1xn-to-matrix-sqrtnxsqrtn/?comment=123315#post-id-123315I just trying these code but the program still break.Fri, 20 Jan 2017 08:04:50 -0600http://answers.opencv.org/question/123305/how-can-i-reshape-matrix-1xn-to-matrix-sqrtnxsqrtn/?comment=123315#post-id-123315