3D 对象位置到 2D 图像

问题描述 投票:0回答:1

我正在使用 ROS 记录来自 CARLA 模拟器的数据。我想在 RGB 前置摄像头图像上渲染一个与其他车辆位置相对应的边界框。

以下是 bag 文件中的示例框架:

假设当前图像中我的自我车辆的位置是 (60, -65, 0.7),红色车辆的位置是 (45, -70, 0.8),比例是 (4, 2, 1)。我根据我对图形数学的理解想出了以下代码,但我不知道 CARLA 相机的焦距或要点。

// Camera intrinsic parameters (calibration)
double focal_length_x = ...;
double focal_length_y = ...;
double principal_point_x = ...;
double principal_point_y = ...;

// Vehicle's world position
Vector3d vehicle_position_world(45, -70, 0.8);

// Camera's world position
Vector3d camera_position_world(60, -65, 0.7);

// Calculate the relative position of the vehicle to the camera
Vector3d relative_position = vehicle_position_world - camera_position_world;

// Calculate 2D camera coordinates using the projection formula
double camera_x = (relative_position.x() / relative_position.z()) * focal_length_x + principal_point_x;
double camera_y = (relative_position.y() / relative_position.z()) * focal_length_y + principal_point_y;

有人可以帮助我正确的方法来转换并获得边界框的准确位置吗?

谢谢!

c++ math matrix graphics 3d
1个回答
0
投票

首先:我们没有关于您提到的坐标系、单位和相机的信息,因此不可能以特定的温度来回答...您应该添加描述这些的图像以及相机信息,例如每个轴的 FOV、相机分辨率、芯片传感器尺寸...

如果您知道相机的

FOVx,FOVy
以及其分辨率
xs,ys
,您可以计算焦距,以便可以在任何屏幕 2D 位置投射 3D 射线

FOVx = 2*tan(xs/(2*focal_length))
FOVy = 2*tan(ys/(2*focal_length))

focal_length = xs/(2*atan(FOVx/2))
focal_length = ys/(2*atan(FOVy/2))

如果您还有深度信息,您可以计算每个像素相对于相机的 3D 位置。

如果你不这样做,你可以假设道路是“平坦的地面”,如果你知道你的相机相对于地面的位置,你可以计算每个道路像素(3D位置)的距离,所以只需找到与道路像素相邻的目标像素,你就可以得到您相对(相对于相机)的 3D 位置...

© www.soinside.com 2019 - 2024. All rights reserved.