![](/img/trans.png)
[英]How can I compute orthographical projection image from perspective projection image?
[英]How can I associate rgb values to pixel locations in a perspective projection?
在完成透视投影后,我试图将 rgb 值与像素坐标相关联。 透视投影的方程为:
其中x
、 y
是点的像素位置, X
、 Y
和Z
是点在相机框架中的位置,其他参数表示相机的固有参数。 给定包含点位置和 rgb 值的点云,我想根据透视投影将 rgb 值与像素位置相关联。
以下代码应创建正确的图像:
import matplotlib.pyplot as plt
import open3d as o3d
import numpy as np
cx = 325.5;
cy = 253.5;
fx = 518.0;
fy = 519.0;
K = np.array([[fx, 0, cx], [0, fy, cy], [0, 0, 1]])
pcd = o3d.io.read_point_cloud('freiburg.pcd', remove_nan_points=True)
points = np.array(pcd.points)
colors = np.array(pcd.colors)
projection = (K @ points.T).T
normalization = projection / projection[:, [2]] #last elemet must be 1
pixel_coordinates = normalization.astype(int)
img = np.zeros((480, 640, 3))
#how can I fill the img appropriately? The matrix pixel coordinates should
# inform about where to place the color intensities.
for position, intensity in zip(pixel_coordinates, colors):
row, column = position[0], position[1]
#img[row, column, :] = intensity # returns with error
img[column, row, :] = intensity # gives a strange picture.
点云可以在这里阅读。 我希望能够在最后一个循环中关联 rgb 值:
for position, intensity in zip(pixel_coordinates, colors):
row, column = position[0], position[1]
#img[row, column, :] = intensity # returns with error
img[column, row, :] = intensity # gives a strange picture.
奇怪的是,如果倒数第二行没有注释,程序会在尝试写入超出可用列范围的 rgb 值时返回IndexError
。 循环中的最后一行运行但是没有问题。 生成的图片和正确的图片如下图:
如何修改上面的代码以获得正确的图像?
几个问题:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.