首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Opencv中将图像与深度图对齐

在Opencv中将图像与深度图对齐
EN

Stack Overflow用户
提问于 2019-06-18 03:12:14
回答 1查看 680关注 0票数 2

我正在处理一个数据集,其中我们有RGB图像和相应的depth地图。深度图与RGB图像不是完全对齐的,我们需要使用Sensor Calibration进行对齐。下面是参数:

代码语言:javascript
复制
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图像对齐?

EN

回答 1

Stack Overflow用户

发布于 2020-07-24 04:23:06

我遇到了同样的问题,下面是我在Python中所做的(其中K是深度传感器和彩色相机的内部变量,ext是外部变量):

代码语言:javascript
复制
# 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))
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56637513

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档