admin管理员组文章数量:1391969
I am trying to project my 3D lidar points onto an image using the KITTI dataset. This is my script to compute the projection for the lidar points
# -*- coding: utf-8 -*-
import numpy as np
# Define Matrices
K = np.array([
[959.1977, 0.0, 694.4383],
[0.0, 952.9324, 241.6793],
[0.0, 0.0, 1.0]
])
P = np.array([
[707.0912, 0.0, 601.8873, 46.88783],
[0.0, 707.0912, 183.1104, 0.1178601],
[0.0, 0.0, 1.0, 0.00620]
])
R = np.array([
[0.9999019, 0.01307921, -0.005015634],
[-0.01307809, 0.9999144, 0.0002561203],
[0.005018555, -0.0001905003, 0.9999874]
])
T = np.array([[0.334], [0.062], [-0.075]]) # Translation vector
R_new = R.copy()
R_new[[0, 2], :] = R[[2, 0], :] # Swap X and Z rows
R_new[:, [0, 2]] = R[:, [2, 0]] # Swap X and Z columns
T = T[[2, 1, 0]] # Swap X and Z in translation
T[1] = -T[1] # Flip Y-axis translation
# Construct 4×4 Transformation Matrix
T_cam_lidar = np.eye(4)
#T_cam_lidar[:3, :3] = R # Assign rotation
T_cam_lidar[:3, :3] = R_new
T_cam_lidar[:3, 3] = T.flatten() # Assign translation
print("4×4 LiDAR-to-Camera Transformation Matrix:\n", T_cam_lidar)
print("Translation Vector T (after processing):\n", T.flatten())
# Function to Project LiDAR Points to Image
def project_lidar_to_image(lidar_points, P, T_cam_lidar):
""" Project LiDAR points to image plane """
# Convert LiDAR points to homogeneous coordinates (N, 4)
lidar_hom = np.hstack((lidar_points, np.ones((lidar_points.shape[0], 1)))) # (N, 4)
# Transform LiDAR points to the camera frame
cam_points = np.dot(T_cam_lidar, lidar_hom.T).T # (N, 4)
cam_points = cam_points[:, :3] # Drop homogeneous coordinate
#
本文标签:
pythonProjecting LiDAR points onto ImageStack Overflow
版权声明:本文标题:python - Projecting LiDAR points onto Image - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人,
转载请联系作者并注明出处:http://www.betaflare.com/web/1744693320a2620128.html,
本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论