OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Sun, 29 Apr 2018 11:00:57 -0500Row and Col problem when Mat represents 3d point cloudhttp://answers.opencv.org/question/189357/row-and-col-problem-when-mat-represents-3d-point-cloud/The row and col of a Mat to represent 3d point cloud in OpenCV is N * 3, N is the number of the points in the cloud and 3 is the x, y, z coordinate respectively. For example, when I use method loadPLYSimple to load data from PLY file I will get N * 3 Mat, when I use the Flann KDTREE, I need to pass N * 3 Mat as the parameter... But the problem is that when I try to perform a transformation on the data, such as rotation. If we have a 3 * 3 rotation Mat R, and the points Mat pc N * 3, the common way is just R * pc. However, pc is N * 3, so we need to do some extra transpose work. I'm not familiar with OpenCV, I just want to know if there is any better way to do that instead of doing the transpose work each time? Or maybe there is something which I do not understand hidden behind？Thanks.Fri, 13 Apr 2018 16:28:56 -0500http://answers.opencv.org/question/189357/row-and-col-problem-when-mat-represents-3d-point-cloud/Answer by LBerger for <p>The row and col of a Mat to represent 3d point cloud in OpenCV is N * 3, N is the number of the points in the cloud and 3 is the x, y, z coordinate respectively. For example, when I use method loadPLYSimple to load data from PLY file I will get N * 3 Mat, when I use the Flann KDTREE, I need to pass N * 3 Mat as the parameter... But the problem is that when I try to perform a transformation on the data, such as rotation. If we have a 3 * 3 rotation Mat R, and the points Mat pc N * 3, the common way is just R * pc. However, pc is N * 3, so we need to do some extra transpose work. I'm not familiar with OpenCV, I just want to know if there is any better way to do that instead of doing the transpose work each time? Or maybe there is something which I do not understand hidden behind？Thanks.</p>
http://answers.opencv.org/question/189357/row-and-col-problem-when-mat-represents-3d-point-cloud/?answer=189402#post-id-189402I hope it will help you :
Mat R= (Mat_<double>(3, 3) << 1, 0, 0, 0, cos(CV_PI/4), -sin(CV_PI / 4), 0, sin(CV_PI / 4),cos(CV_PI / 4));
Mat p= (Mat_<double>(2, 3) << 1, 0, 0, 0,1,0);
for (int i = 0; i < p.rows; i++)
cout << R * p.row(i).t() << endl;
Sun, 15 Apr 2018 12:07:33 -0500http://answers.opencv.org/question/189357/row-and-col-problem-when-mat-represents-3d-point-cloud/?answer=189402#post-id-189402Comment by Tab for <p>I hope it will help you :</p>
<pre><code>Mat R= (Mat_<double>(3, 3) << 1, 0, 0, 0, cos(CV_PI/4), -sin(CV_PI / 4), 0, sin(CV_PI / 4),cos(CV_PI / 4));
Mat p= (Mat_<double>(2, 3) << 1, 0, 0, 0,1,0);
for (int i = 0; i < p.rows; i++)
cout << R * p.row(i).t() << endl;
</code></pre>
http://answers.opencv.org/question/189357/row-and-col-problem-when-mat-represents-3d-point-cloud/?comment=190487#post-id-190487Thanks. I just realize that store Mat data in this way (N*3) can be more efficient when accessing memory.Sun, 29 Apr 2018 11:00:57 -0500http://answers.opencv.org/question/189357/row-and-col-problem-when-mat-represents-3d-point-cloud/?comment=190487#post-id-190487Comment by LBerger for <p>I hope it will help you :</p>
<pre><code>Mat R= (Mat_<double>(3, 3) << 1, 0, 0, 0, cos(CV_PI/4), -sin(CV_PI / 4), 0, sin(CV_PI / 4),cos(CV_PI / 4));
Mat p= (Mat_<double>(2, 3) << 1, 0, 0, 0,1,0);
for (int i = 0; i < p.rows; i++)
cout << R * p.row(i).t() << endl;
</code></pre>
http://answers.opencv.org/question/189357/row-and-col-problem-when-mat-represents-3d-point-cloud/?comment=189406#post-id-189406transpose before matrix operation p.col(i) is only a roi (no deep copy)Sun, 15 Apr 2018 13:56:48 -0500http://answers.opencv.org/question/189357/row-and-col-problem-when-mat-represents-3d-point-cloud/?comment=189406#post-id-189406Comment by Tab for <p>I hope it will help you :</p>
<pre><code>Mat R= (Mat_<double>(3, 3) << 1, 0, 0, 0, cos(CV_PI/4), -sin(CV_PI / 4), 0, sin(CV_PI / 4),cos(CV_PI / 4));
Mat p= (Mat_<double>(2, 3) << 1, 0, 0, 0,1,0);
for (int i = 0; i < p.rows; i++)
cout << R * p.row(i).t() << endl;
</code></pre>
http://answers.opencv.org/question/189357/row-and-col-problem-when-mat-represents-3d-point-cloud/?comment=189405#post-id-189405Thank you, that's what I mean the "extra transpose work". I wonder why not just use 3 * N Mat to represent 3d points to make the computation easier?Sun, 15 Apr 2018 12:52:36 -0500http://answers.opencv.org/question/189357/row-and-col-problem-when-mat-represents-3d-point-cloud/?comment=189405#post-id-189405