open3d 显示人体面部区域

1.使用cv2读取彩色图像和深度图像

2.深度图像转点云

3.只保留面部区域的点云

4.显示

import cv2
import numpy as np
import open3d
 
def depth2xyz(depth_map,depth_cam_matrix,flatten=False,depth_scale=1000):
    fx,fy = depth_cam_matrix[0,0],depth_cam_matrix[1,1]
    cx,cy = depth_cam_matrix[0,2],depth_cam_matrix[1,2]
    h,w=np.mgrid[0:depth_map.shape[0],0:depth_map.shape[1]]
    z=depth_map/depth_scale
    x=(w-cx)*z/fx
    y=(h-cy)*z/fy
    xyz=np.dstack((x,y,z)) if flatten==False else np.dstack((x,y,z)).reshape(-1,3)
    #xyz=cv2.rgbd.depthTo3d(depth_map,depth_cam_matrix)
    return xyz
 
 
img = cv2.imread('./2021-01-26/whq_0_color.png')
depth = cv2.imread('./2021-01-26/whq_0_depth.png', -1)
 
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
colors = img.reshape(-1,3)
 
depth_cam_matrix = np.array([[900.584, 0, 636.849],
                    [0, 900.584, 370.579],
                    [0, 0, 0]])
 
points = depth2xyz(depth, depth_cam_matrix, True)
 
index = np.where(points[:, 0] > 0.15)
points = np.delete(points, index, axis=0)
colors = np.delete(colors, index, axis=0)
 
index = np.where(points[:, 0] < -0.15)
points = np.delete(points, index, axis=0)
colors = np.delete(colors, index, axis=0)
 
index = np.where(points[:, 1] > 0.1)
points = np.delete(points, index, axis=0)
colors = np.delete(colors, index, axis=0)
 
index = np.where(points[:, 1] < -0.2)
points = np.delete(points, index, axis=0)
colors = np.delete(colors, index, axis=0)
 
index = np.where(points[:, 2] > 0.7)
points = np.delete(points, index, axis=0)
colors = np.delete(colors, index, axis=0)
 
index = np.where(points[:, 2] < 0.1)
points = np.delete(points, index, axis=0)
colors = np.delete(colors, index, axis=0)
 
point_cloud = open3d.geometry.PointCloud()
point_cloud.points = open3d.utility.Vector3dVector(points)
point_cloud.colors = open3d.utility.Vector3dVector(colors/255)
 
# point_cloud 需要用中括号括住
open3d.draw_geometries([point_cloud])

  • 11
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值