mayavi 显示人体面部区域彩色点云

编程入门 行业动态 更新时间:2024-10-10 00:28:08

mayavi 显示人体<a href=https://www.elefans.com/category/jswz/34/1755305.html style=面部区域彩色点云"/>

mayavi 显示人体面部区域彩色点云

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

2.深度图像转点云

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

4.使用mayavi.mlab显示彩色点云

import cv2
import numpy as npfrom mayavi import mlabdef 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_scalex=(w-cx)*z/fxy=(h-cy)*z/fyxyz=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 xyzimg = 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)# 显示
nodes = mlab.points3d(points[:,0], points[:,1], points[:,2], scale_factor=0.001)
nodes.glyph.scale_mode = 'scale_by_vector'
nodes.mlab_source.dataset.point_data.scalars = colors
mlab.show()# fig = mlab.figure(bgcolor=(0, 0, 0), size=(800, 600))
# nodes = mlab.points3d(points[:,0], points[:,1], points[:,2], scale_factor=0.001, figure=fig)
# nodes.glyph.scale_mode = 'scale_by_vector'
# nodes.mlab_source.dataset.point_data.scalars = colors
# mlab.show()

 

参考文献:

1.使用mayavi python为point3d中的每个点分配颜色

2.Animating the data

3.Plotting functions

4.mayavi

更多推荐

mayavi 显示人体面部区域彩色点云

本文发布于:2024-03-08 11:52:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1720792.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:面部   彩色   人体   区域   mayavi

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!