简体   繁体   English

在OpenCV中,将2d图像点转换为3d世界单位矢量

[英]In OpenCV, converting 2d image point to 3d world unit vector

I have calibrated my camera with OpenCV (findChessboard etc) so I have: - Camera Distortion Coefficients & Intrinsics matrix - Camera Pose information (Translation & Rotation, computed separatedly via other means) as Euler Angles & a 4x4 - 2D points within the camera frame 我用OpenCV(findChessboard等)校准了我的相机,所以我有: - 相机失真系数和内在矩阵 - 相机姿势信息(平移和旋转,通过其他方式分开计算)作为欧拉角和相机框架内的4x4 - 2D点

How can I convert these 2D points into 3D unit vectors pointing out into the world? 如何将这些2D点转换为指向世界的3D单位向量? I tried using cv::undistortPoints but that doesn't seem to do it (only returns 2D remapped points), and I'm not exactly sure what method of matrix math to use to model the camera via the Camera intrinsics I have. 我尝试使用cv :: undistortPoints但似乎没有这样做(只返回2D重映射点),而且我不确定使用什么方法的矩阵数学来通过我内置的Camera内在函数来建模相机。

Convert your 2d point into a homogenous point (give it a third coordinate equal to 1) and then multiply by the inverse of your camera intrinsics matrix. 将您的2d点转换为同质点(给它一个等于1的第三个坐标),然后乘以相机内在函数矩阵的倒数。 For example 例如

cv::Matx31f hom_pt(point_in_image.x, point_in_image.y, 1);
hom_pt = camera_intrinsics_mat.inv()*hom_pt; //put in world coordinates

cv::Point3f origin(0,0,0);
cv::Point3f direction(hom_pt(0),hom_pt(1),hom_pt(2));

//To get a unit vector, direction just needs to be normalized
direction *= 1/cv::norm(direction);

origin and direction now define the ray in world space corresponding to that image point. 原点和方向现在定义与该图像点对应的世界空间中的光线。 Note that here the origin is centered on the camera, you can use your camera pose to transform to a different origin. 请注意,此处原点位于相机的中心,您可以使用相机姿势转换为不同的原点。 Distortion coefficients map from your actual camera to the pinhole camera model and should be used at the very beginning to find your actual 2d coordinate. 失真系数从您的实际相机映射到针孔相机模型,应该在最开始时使用以找到您的实际2d坐标。 The steps then are 然后是步骤

  1. Undistort 2d coordinate with distortion coefficients Undistort 2d与失真系数坐标
  2. Convert to ray (as shown above) 转换为光线(如上图所示)
  3. Move that ray to whatever coordinate system you like. 将该光线移动到您喜欢的任何坐标系。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM