当前位置:网站首页>Point cloud processing voxel filter
Point cloud processing voxel filter
2022-07-28 17:50:00 【Zhang Feifei~】
# Realization voxel wave filtering , Load and verify the data set
# import open3d as o3d
import os
import numpy as np
from pyntcloud import PyntCloud
# function : Point cloud voxel wave filtering
# Input :
# point_cloud: Enter the point cloud
# leaf_size: voxel Size
def voxel_filter(point_cloud, leaf_size, mode):
filtered_points = []
data = point_cloud
# Homework 3
# Shielding starts
#1. Calculate the maximum and minimum value of the point cloud
D_min = data.min(0)
D_max = data.max(0)
#2. Set partition voxel size , Calculate the number of space partitions 1x3
D = (D_max - D_min) / leaf_size
#3. Calculate the partition index for each point
point_x, point_y, point_z = np.array(data.x), np.array(data.y), np.array(data.z)
hx = np.floor((point_x - D[0]) / leaf_size)
hy = np.floor((point_y - D[1]) / leaf_size)
hz = np.floor((point_z - D[2]) / leaf_size)
index = np.array(np.floor(hx + hy * D[0] + hz * D[0] * D[1])) #Nx1
# No sorting , Use hash mapping to filter points #
#4. Sort the index
data_index_point = np.c_[index, point_x, point_y, point_z]
sort_idx = data_index_point[:, 0].argsort()
data_index_point = data_index_point[sort_idx]
size = data_index_point.shape[0]
tem_point = []
if mode == 1:
# Use random sampling , Select the last point with the same index as the filter output point , It is equivalent to random sampling
for i in range(size - 1):
if(data_index_point[i][0] != data_index_point[i+1][0]):
filtered_points.append(data_index_point[i][1:])
# The last one has no comparison , add
filtered_points.append(data_index_point[size-1][1:])
filtered_points = np.array(filtered_points)
if mode == 2:
# Use the calculated mean method
for i in range(size - 1):
# Judge whether the previous serial number is equal to the next one
if data_index_point[i][0] == data_index_point[i+1][0]: # For those with only two points, only one point will be reserved
tem_point.append(data_index_point[i][1:])
continue
if tem_point == []:
continue
filtered_points.append(np.mean(tem_point, axis=0))
tem_point = []
filtered_points = np.array(filtered_points)
#4. Use the hash table to map the index of the point into the hash container , Be careful to exclude conflicting points
# End of shielding
# Change the point cloud format to array, And return to
filtered_points = np.array(filtered_points, dtype=np.float64)
return filtered_points
def main():
# # from ModelNet Auto index path in dataset folder , Load point cloud
# cat_index = 10 # Object number , The scope is 0-39, That is, the corresponding data set 40 An object
# root_dir = '/Users/renqian/cloud_lesson/ModelNet40/ply_data_points' # Dataset path
# cat = os.listdir(root_dir)
# filename = os.path.join(root_dir, cat[cat_index],'train', cat[cat_index]+'_0001.ply') # The first point cloud is used by default
# point_cloud_pynt = PyntCloud.from_file(file_name)
# Load your own point cloud file
file_name = "airplane_0001.ply"
point_cloud_pynt = PyntCloud.from_file(file_name)
# Turn into open3d Recognizable format
# point_cloud_o3d = point_cloud_pynt.to_instance("open3d", mesh=False)
# o3d.visualization.draw_geometries([point_cloud_o3d]) # Displays the original point cloud
print('the original pointcloud size is:', point_cloud_pynt.points.shape[0])
# call voxel The filter function , Realize filtering
filtered_cloud = voxel_filter(point_cloud_pynt.points, 10, 2)
print('the pointcloud size is:', filtered_cloud.shape[0])
# point_cloud_o3d.points = o3d.utility.Vector3dVector(filtered_cloud)
# Displays the filtered point cloud
# o3d.visualization.draw_geometries([point_cloud_o3d])
if __name__ == '__main__':
main()
边栏推荐
- 点云处理---二叉树
- PyTorch中grid_sample的使用方法
- MySQL基本查询和运算符
- MySQL与IDEA连接
- Technical aspects passed easily, HR: those with only three years of experience in large factories are not worth 20K
- 软件测试前景如何?
- PCA reports error in eigen (crossprod (t (x), t (x)), symmetric = true): 'x' has infinite value or missing value
- 1.4-dos
- leetcode系统性刷题(一)-----链表、栈、队列、堆
- 【C语言进阶】——函数指针
猜你喜欢

Interviewer: the actual record of algorithm question brushing.pdf I can't even answer it
![[p5.js learning notes] local variable (let) and global variable (VaR) declaration](/img/37/82cdf73eb6527fb2da5bc550c33223.png)
[p5.js learning notes] local variable (let) and global variable (VaR) declaration

How to bind idea with code cloud

Please make sure you have the correct access rights and the repository exists.

QT programming serial port assistant

【C语言进阶】——剖析入微数据在内存中的存储 【下】(浮点数存储)

How to upload a project to the code cloud using idea

IDEA报错Error running ‘Application‘ Command line is too long解决方案

ps快速制作全屏水印

Sql Server STUFF与FOR XML PATH
随机推荐
【C语言进阶】——指针进阶[Ⅰ]
Ros自定义消息及使用
mmdetection3d(3)---网络输出
[C language note sharing] character function and string function (recommended Collection)
【C语言进阶】——函数指针
[advanced C language] - function pointer
[p5.js] actual copy - chess board
软件测试需求人才越来越多,走上测试道路的人却越来越少?
编译原理学习笔记1(编译原理概述与词法分析)
Mmcv installation method
2022 IDEA (学生邮箱认证)安装使用教程以及基础配置教程
MySQL installation
从0到1:基于云开发的投票小程序开发笔记
IDEA报错Error running ‘Application‘ Command line is too long解决方案
An article takes you closer to the overview and principle of kubernetes
【p5.js学习笔记】局部变量(let)与全局变量(var)声明
Solve package is not available (for R ve [package 'xxx' is not available (for R version x.y.z) "warning?]
MySQL详解
软件测试零基础小白学习需要掌握哪些技能?
DOS command Daquan basic command + network common command