简体   繁体   English

OpenCV(C ++)-从已知的3D对象和相机位置计算图像的2D坐标

[英]OpenCV (C++) - Calculating 2D co-ordinates of an image from known 3D object and camera positions

So I already know the 3D camera position and the position and size of an object in the world frame, as well as the camera matrix and distortion coefficients from a previous camera calibration. 因此,我已经知道3D摄像机的位置以及对象在世界框架中的位置和大小,以及以前的摄像机校准中的摄像机矩阵和失真系数。

What I need to work out is the 2D image coordinates of the object. 我需要计算的是对象的2D图像坐标。 Let's just say the object is a sphere with world position objPos and radius objRad , so the image I want to find the coordinates for will be a circle of image position imgPos and radius imgRad . 假设该对象是具有世界位置objPos和半径objRad的球体 ,因此我要查找坐标的图像将是图像位置imgPos和半径imgRad的圆

How would I go about doing this? 我将如何去做呢?

Cheers 干杯

In OpenCV exists a function to project 3D coordinates on a (camera) image - projectPoints In my opinion you have all you need for calling this function. 在OpenCV中,存在一个用于在(摄像机)图像上投影3D坐标的函数-projectPoints在我看来,您拥有调用此函数所需的一切。 The arguments are: 参数为:

  1. 3D coordinates you want to project 您要投影的3D坐标
  2. Rotation of your camera - rvec 相机旋转-RVEC
  3. Position of your camera - tvec 相机位置-TVEC
  4. Camera matrix - from the calibration you have 相机矩阵-通过校准
  5. Camera distortion coefficients - from the calibration you have 相机失真系数-通过校准
  6. Resulting 2D image coordinates 产生的2D影像座标

If you have your extrinsic camera parameters in form of 4x4 matrix, you have to extract rvec and tvec from it ( see here ). 如果您具有4x4矩阵形式的外部摄像机参数,则必须从中提取rvec和tvec( 请参见此处 )。

To come to your example case: I would generate the 3D coordinates of such a sphere with the corresponding radius. 以您的示例为例:我将生成具有相应半径的此类球体的3D坐标。 In a next step, I would project these 3D coordinate with above method. 在下一步中,我将使用上述方法投影这些3D坐标。

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

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