当前位置:网站首页>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()
边栏推荐
- How to upload a project to the code cloud using idea
- 电工学自学笔记1.21
- Collection集合
- [p5.js learning notes] basic knowledge of code drawing
- 编译原理学习笔记1(编译原理概述与词法分析)
- 【Unity Tilemap】教程 | Basic、Rule Tile、Prefab Brush、Tilemap Collider
- Mysql 优化总结
- Please make sure you have the correct access rights and the repository exists.
- 零基础学习软件测试有什么条件?
- 有奖征文 | 2022 云原生编程挑战赛征稿活动开启!
猜你喜欢

软件测试真有网上说的那么好吗?

mmdetection3D---(1)

【Unity】Timeline学习笔记(七):自定义片段(Clip)

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

C#中virtual(虚方法)的理解以及和abstract(抽象方法)的区别

Sql Server STUFF与FOR XML PATH

Jerry ac692n --- prompt tone compression and modification

JVM performance tuning

从0到1:基于云开发的投票小程序开发笔记

abstract、static、final
随机推荐
小白必看的软件测试发展路线
leetcode系统性刷题(一)-----链表、栈、队列、堆
Complete MySQL interview questions (updated in succession)
Jerry ac692n --- prompt tone compression and modification
.net MVC understanding
域名解析问题记录
【p5.js】实战临摹——国际象棋盘
软件测试真有网上说的那么好吗?
2022 IDEA (学生邮箱认证)安装使用教程以及基础配置教程
Collection集合
An article takes you closer to the overview and principle of kubernetes
[阅读笔记] For:Object Detection with Deep Learning: The Definitive Guide
小白如何零基础学习软件测试?
想学习软件测试,零基础去哪里学呢?
【Unity】三张图让你看懂ShaderGraph编辑器
The solution to the problem that the computer cannot be charged
软件测试培训两个月骗局?培训机构到底如何选择?
[p5.js actual combat] my self portrait
On the non recursive and recursive implementation of finding the nth Fibonacci number respectively
Visual object class introduces Pascal VOC dataset