Ask Your Question
1

Conversion of 3x1 or 1x3 cv::Mat to cv::Point3d?

asked 2013-08-29 21:18:16 -0600

pipotux gravatar image

updated 2013-08-30 00:47:18 -0600

Moster gravatar image

I'm dealing with some code in which a do a lot of 3x3 matrix multiplications an also some translation of 3d points using rotation matrices, etc. I decided to use opencv core functionalities for the mathematical operations. The possibility to use the recent constructor added to the cv::Mat class to convert directly a cv::Point3d to a 3x1 cv::Mat reduces and simplify greatly the code.

What I am wondering now is if there is a simple way to convert a 3x1 or 1x3 cv::Mat to an cv::Point3d. I always can do something like:

cv::Mat mat(3,1,CV_64FC1);
cv::Point3d p (mat.at<double>(0,0), mat.at<double>(1,0), mat.at<double>(2,0));

or

cv::Mat mat(3,1,CV_64FC1);
const double *data = mat.ptr<double>(0);
cv::Point3d p (data[0], data[1], data[2]);

If I worried so much about the performance (avoid the 3 calls to at method).

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
3

answered 2013-08-30 00:54:06 -0600

Moster gravatar image

The 2nd variant is already good. Btw, you shouldnt really worry about performance on a 3x1 Mat with "at". Also, the those index checks on "at" are only done in Debug mode.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-08-29 21:18:16 -0600

Seen: 2,770 times

Last updated: Aug 29 '13