[英]OpenCV: Get 3D coordinates from triangulatePoints
我试图使用OpenCV从两个立体图像中获取点云,但我无法获得坐标。
Mat RT1;<br> hconcat(R, T1, RT1);<br> Mat P1 = C*RT1;<br>
R是3x3旋转矩阵,T是3x1变换矩阵(列),P1 - 投影矩阵。
triangulatePoints(P1, P2, leftPoints, rightPoints, out);
P1和P2是3x4投影矩阵(Mat_ <double>)。 leftPoints和rightPoints是Point2f的std :: vector。 什么出来了? 它应该是1xN 4D坐标矩阵。 这是Vec4f吗?
我正在尝试获取坐标
for (int i = 0; i < out.cols; i++) { Vec4f vec = out.at<Vec4f>(0, i); float w = vec[3]; stream << "v " << vec[0] / w << " " << vec[1]/w << " " << vec[2]/w << "\\n"; }
但我有两个问题:
OpenCV错误:断言失败(dims <= 2 && data &&(unsigned)i0 <(unsigned)si ze.p [0] &&(unsigned)(i1 * DataType <_Tp> :: channels)<(unsigned)(size。 p 1 * cha nnels())&&((((sizeof(size_t)<< 28)| 0x8442211)>>((DataType <_Tp> :: depth)&((1 << 3) - 1))* 4 )&15)== elemSize1())在cv :: Mat :: at,文件c:\\ opencv \\ build \\ includ e \\ opencv2 \\ core \\ mat.inl.hpp,第89行
我认为这是某种Index Out Range Exception
所以,我做错了什么。 如何正确使用此功能并获得点的3D坐标? 我希望你能帮助我。
我完全不了解你获取坐标的方法。
据我所知,你不应该访问像这样的元素
out.at<Vec4f>(0, i);
相反,这样做:
float x = out.at<float>(0, i);
float y = out.at<float>(1, i);
float z = out.at<float>(2, i);
float w = out.at<float>(3, i);
stream << "v " << x << " " << y << " " << z << "\n";
或者使用double
...这取决于你是否out
的类型是CV_32F
或CV_64F
。
我是这样做的:
Mat points3DHomogeneous;
triangulatePoints(projectionMatrixL, projectionMatrixR, pointsL, pointsR, points3DHomogeneous);
projectionMatrixL
:
projectionMatrixR
:
pointsL
:
700 250
200 300
600 350
400 400
500 450
600 500
700 550
800 600
150 650
1000 700
pointsR
:
690 250
180 300
590 350
385 400
495 450
575 500
691 550
782 600
120 650
960 700
points3DHomogeneous
是结果:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.