0
点赞
收藏
分享

微信扫一扫

霍格沃兹测试开发从人员外包到测试工具、测试平台,提供全方位的测试解决方案~

目录

从相机空间到像素空间的投影

效果

​编辑

公式

​编辑

代码

像素空间到相机空间的反投影


记录一下从相机空间到像素空间的投影(3D-->2D)和像素空间到相机空间的反投影(2D-->3D)。

推荐blog:SLAM入门之视觉里程计(2):相机模型(内参数,外参数) - Brook_icv - 博客园 (cnblogs.com)

从相机空间到像素空间的投影

主要是估计出物体相对相机的位姿之后,把物体投影到2D像素平面看看mask,想看看根据marker的位姿传播的误差大不大。即看看投影误差。

效果

还是存在一些误差

公式

代码

我这里的代码是从物体坐标系--》相机坐标系--》像素坐标系

def project3Dto2D(points_local, center_local, pose, K, height, width):
    relative_points = points_local - center_local             # (0,0,0), 物体在物体坐标系下的点云的坐标
    homogeneous_points = np.ones((4,relative_points.shape[0]))
    homogeneous_points[:3,:] = relative_points.transpose()

    camera_points = np.matmul(pose, homogeneous_points)  # 物体在cam坐标系下的点云的坐标

    image_points = np.matmul(K, camera_points[:3,:]) # 相机坐标系下的点云坐标投影到图像平面

    assert np.min(image_points[2]) > 0

    image_points[0] = image_points[0]/image_points[2] # 将投影后的图像坐标除以深度,得到归一化坐标。
    image_points[1] = image_points[1]/image_points[2]

    pixel_points = np.round(image_points[:2,:]) # 对归一化坐标取整,得到像素坐标。

    mask1 = pixel_points[0,:] > -1            # 根据像素坐标的范围进行剪裁,即将超出图像范围的点云剔除。
    mask2 = pixel_points[1,:] > -1
    mask3 = pixel_points[0,:] < width
    mask4 = pixel_points[1,:] < height

    mask = mask1&mask2&mask3&mask4
    selected_index = np.where(mask)
    pixel_points = np.take(pixel_points, selected_index[0], axis=1)
    depth = np.take(image_points[2,:], selected_index[0])
    
    return pixel_points.astype(int), depth

像素空间到相机空间的反投影

主要是根据yolov8检测的mask(u,v),获取对应的深度值z,根据uvz求解出物体的在相机坐标下的3D坐标(XYZ)

cx, cy, fx, fy = 323, 238, 616, 616
x = (u - cx) / fx
y = (v - cy) / fy
x = x * z
y = y * z
举报

相关推荐

霍格沃兹软件测试

0 条评论