我正在处理一个数据集,其中我们有RGB图像和相应的depth地图。深度图与RGB图像不是完全对齐的,我们需要使用Sensor Calibration进行对齐。下面是参数:
intrinsic matrix for the depth sensor
584.27 0 337.11
0 584.27 254.17
0 0 1
intrinsic matrix of the color camera
519.47 0 329.76
0 519.47 264.09
0 0 1
extrinsic parameters mapping the depth coordinate system to the camera coordinate system
rotation matrix
0.999947 -0.00432361 0.00929419
0.00446314 0.999877 0.0150443
-0.009228 -0.015085 0.999844
translation vector
25.0198 -0.2000 3.2308 如何在OpenCV python中使用它们将深度图与RGB图像对齐?
发布于 2020-07-24 04:23:06
我遇到了同样的问题,下面是我在Python中所做的(其中K是深度传感器和彩色相机的内部变量,ext是外部变量):
# All what we need to align our images:
depth_scale = 0.001
fx_d = K_depth[0,0]
fy_d = K_depth[1,1]
cx_d = K_depth[0,2]
cy_d = K_depth[1,2]
fx_rgb = K_col[0,0]
fy_rgb = K_col[1,1]
cx_rgb = K_col[0,2]
cy_rgb = K_col[1,2]
height = depth.shape[0]
width = depth.shape[1]
aligned = np.zeros((height,width,6))
for v in range (height):
for u in range (width):
# Apply Depth intrinsics
z = depth[v,u].sum() * depth_scale
x = ((u - cx_d) * z) / fx_d
y = ((v - cy_d) * z) / fy_d
# Apply extrinsic
transformed = np.dot(ext ,np.array([x,y,z,1])).T
aligned[v,u,0] = transformed[0]
aligned[v,u,1] = transformed[1]
aligned[v,u,2] = transformed[2]
for v in range (height):
for u in range (width):
# Apply RGB intrinsic
x = (aligned[v,u,0] * fx_rgb / aligned[v,u,2]) + cx_rgb
y = (aligned[v,u,1] * fy_rgb / aligned[v,u,2]) + cy_rgb
# Endle out of bound pixels
if x > width-1 or y > height-1 or x < 0 or y < 0:
pass
else:
x = int(round(x))
y = int(round(y))
aligned[v,u,3] = color[y, x, 0]
aligned[v,u,4] = color[y, x, 1]
aligned[v,u,5] = color[y, x, 2]
# Retrive RGB value from our aligned version
test = np.zeros((height,width,3))
for i in range (height):
for j in range (width):
test[i,j] = aligned[i,j][3:6]
plt.imshow(test.astype(int))https://stackoverflow.com/questions/56637513
复制相似问题