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

后端 未结 1 1307
无人共我
无人共我 2021-02-08 20:34

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 fu

相关标签:
1条回答
  • 2021-02-08 21:05

    cv::Point3d has a constructor which allows direct creation from cv::Mat:

    cv::Mat mat(3,1,CV_64FC1);
    cv::Point3d p(mat);
    

    Another possibility you may not have considered is using cv::Matx instead of cv::Mat for your mathematical operations. I find it is easier to use, and offers more functionality, like multiplication of Point types without needing a conversion:

    cv::Point3d p(1,2,3);
    cv::Matx33d m = cv::Matx33d::eye();
    cv::Point3d p2 = m * p;
    

    cv::Matx is also statically allocated, rather than dynamically (like cv::Mat), in case you really need that extra little bit of performance. However, as in all performance-related advice: make sure what you're optimizing is actually a bottleneck by profiling.

    0 讨论(0)
提交回复
热议问题