当前位置:网站首页>点云数据集常用处理
点云数据集常用处理
2022-04-23 19:13:00 【给算法爸爸上香】
数据集增强
仿射变换
平移变换
import numpy as np
import random
#文件名
old_file=r"rabbit.txt"
new_file=r"rabbit_change.txt"
#平移参数
x_offset=random.uniform(-10, 10)
y_offset=random.uniform(-10, 10)
z_offset=random.uniform(-10, 10)
#变换矩阵
transformation_matrix=np.array([
[1,0,0,x_offset],
[0,1,0,y_offset],
[0,0,1,z_offset],
[0,0,0,1]
])
#加载文件
old_array=np.loadtxt(old_file)
old_xyz=old_array[:,:3]
#补充数据为齐次项
ones_data=np.ones(old_xyz.shape[0])
old_xyz=np.insert(old_xyz,3,values=ones_data,axis=1)
#变换数据
new_xyz = np.dot(transformation_matrix,old_xyz.T)
new_array=np.concatenate((new_xyz.T[:,:3],old_array[:,3:]),axis=1)
np.savetxt(new_file,new_array,fmt='%.06f')
旋转变换
import numpy as np
import random
#文件名
old_file=r"rabbit.txt"
new_file=r"rabbit_change.txt"
#旋转角度
roate_x=random.uniform(-np.pi/10, np.pi/10)
roate_y=random.uniform(-np.pi/10, np.pi/10)
roate_z=random.uniform(-np.pi/10, np.pi/10)
roate_x_matrix=np.array([
[1,0,0,0],
[0,np.cos(roate_x),-np.sin(roate_x),0],
[0,np.sin(roate_x),np.cos(roate_x),0],
[0,0,0,1]
])
roate_y_matrix=np.array([
[np.cos(roate_y),0,np.sin(roate_y),0],
[0,1,0,0],
[-np.sin(roate_y),0,np.cos(roate_y),0],
[0,0,0,1]
])
roate_z_matrix=np.array([
[np.cos(roate_z),-np.sin(roate_z),0,0],
[np.sin(roate_z),np.cos(roate_z),0,0],
[0,0,1,0],
[0,0,0,1]
])
#变换矩阵
transformation_matrix=dot(roate_z_matrix).dot(roate_y_matrix).dot(roate_x_matrix)
#加载文件
old_array=np.loadtxt(old_file)
old_xyz=old_array[:,:3]
#补充数据为齐次项
ones_data=np.ones(old_xyz.shape[0])
old_xyz=np.insert(old_xyz,3,values=ones_data,axis=1)
#变换数据
new_xyz = np.dot(transformation_matrix,old_xyz.T)
new_array=np.concatenate((new_xyz.T[:,:3],old_array[:,3:]),axis=1)
np.savetxt(new_file,new_array,fmt='%.06f')
尺度变换
import numpy as np
import random
#文件名
old_file=r"rabbit.txt"
new_file=r"rabbit_change.txt"
#缩放参数
scale=0.1
#变换矩阵
transformation_matrix=np.array([
[scale,0,0,0],
[0,scale,0,0],
[0,0,scale,0],
[0,0,0,1]
])
#加载文件
old_array=np.loadtxt(old_file)
old_xyz=old_array[:,:3]
#补充数据为齐次项
ones_data=np.ones(old_xyz.shape[0])
old_xyz=np.insert(old_xyz,3,values=ones_data,axis=1)
#变换数据
new_xyz = np.dot(transformation_matrix,old_xyz.T)
new_array=np.concatenate((new_xyz.T[:,:3],old_array[:,3:]),axis=1)
np.savetxt(new_file,new_array,fmt='%.06f')
仿射变换
上面三种变换综合可以写成:
import numpy as np
import random
#文件名
old_file=r"rabbit.txt"
new_file=r"rabbit_change.txt"
#平移参数
x_offset=random.uniform(-10, 10)
y_offset=random.uniform(-10, 10)
z_offset=random.uniform(-10, 10)
#缩放参数
scale=0.1
#旋转角度
roate_x=random.uniform(-np.pi/10, np.pi/10)
roate_y=random.uniform(-np.pi/10, np.pi/10)
roate_z=random.uniform(-np.pi/10, np.pi/10)
roate_x_matrix=np.array([
[1,0,0,0],
[0,np.cos(roate_x),-np.sin(roate_x),0],
[0,np.sin(roate_x),np.cos(roate_x),0],
[0,0,0,1]
])
roate_y_matrix=np.array([
[np.cos(roate_y),0,np.sin(roate_y),0],
[0,1,0,0],
[-np.sin(roate_y),0,np.cos(roate_y),0],
[0,0,0,1]
])
roate_z_matrix=np.array([
[np.cos(roate_z),-np.sin(roate_z),0,0],
[np.sin(roate_z),np.cos(roate_z),0,0],
[0,0,1,0],
[0,0,0,1]
])
#变换矩阵
transformation_matrix=np.array([
[scale,0,0,x_offset],
[0,scale,0,y_offset],
[0,0,scale,z_offset],
[0,0,0,1]
]).dot(roate_z_matrix).dot(roate_y_matrix).dot(roate_x_matrix)
#加载文件
old_array=np.loadtxt(old_file)
old_xyz=old_array[:,:3]
#补充数据为齐次项
ones_data=np.ones(old_xyz.shape[0])
old_xyz=np.insert(old_xyz,3,values=ones_data,axis=1)
#变换数据
new_xyz = np.dot(transformation_matrix,old_xyz.T)
new_array=np.concatenate((new_xyz.T[:,:3],old_array[:,3:]),axis=1)
np.savetxt(new_file,new_array,fmt='%.06f')
仿射变换:
PCL 仿射变换,实现点云平移旋转
添加噪声
import numpy as np
#文件名
old_file=r"rabbit.txt"
new_file=r"rabbit_change.txt"
def add_noise(point, sigma=0.1, clip=0.1):
point = point.reshape(-1,3)
Row, Col = point.shape
noisy_point = np.clip(sigma * np.random.randn(Row, Col), -1*clip, clip)
noisy_point += point
return noisy_point
#加载文件
old_array=np.loadtxt(old_file)
old_xyz=old_array[:,:3]
new_xyz=add_noise(old_xyz)
new_array=np.concatenate((new_xyz,old_array[:,3:]),axis=1)
np.savetxt(new_file,new_array,fmt='%.06f')
下采样
import numpy as np
#文件名
old_file=r"rabbit.txt"
new_file=r"rabbit_change.txt"
#体素滤波
def voxel_filter(point_cloud, leaf_size):
filtered_points = []
# 计算边界点
x_min, y_min, z_min = np.amin(point_cloud, axis=0) #计算x y z 三个维度的最值
x_max, y_max, z_max = np.amax(point_cloud, axis=0)
# 计算 voxel grid维度
Dx = (x_max - x_min) // leaf_size + 1
Dy = (y_max - y_min) // leaf_size + 1
Dz = (z_max - z_min) // leaf_size + 1
# 计算每个点的voxel索引
h = list() # h为保存索引的列表
for i in range(len(point_cloud)):
hx = (point_cloud[i][0] - x_min) // leaf_size
hy = (point_cloud[i][1] - y_min) // leaf_size
hz = (point_cloud[i][2] - z_min) // leaf_size
h.append(hx + hy * Dx + hz * Dx * Dy)
h = np.array(h)
#筛选点
h_indice = np.argsort(h) #返回h里面的元素按从小到大排序的索引
h_sorted = h[h_indice]
begin = 0
for i in range(len(h_sorted) - 1): # 0~9999
if h_sorted[i] != h_sorted[i + 1]:
point_idx = h_indice[begin: i + 1]
filtered_points.append(np.mean(point_cloud[point_idx], axis=0))
begin = i+1
#把点云格式改成array,并对外返回
filtered_points = np.array(filtered_points, dtype=np.float64)
return filtered_points
#加载文件
old_array=np.loadtxt(old_file)
old_xyz=old_array[:,:3]
#保存文件
new_xyz=voxel_filter(old_xyz, 1)
np.savetxt(new_file,new_xyz,fmt='%.06f')
数据归一化
去中心化
centroid = np.mean(pc, axis=0)
pc = pc - centroid
尺度归一化
m = np.max(np.sqrt(np.sum(pc**2, axis=1)))
pc = pc / m
版权声明
本文为[给算法爸爸上香]所创,转载请带上原文链接,感谢
https://blog.csdn.net/taifyang/article/details/124365265
边栏推荐
- arcgis js api dojoConfig配置
- Openharmony open source developer growth plan, looking for new open source forces that change the world!
- Why is PostgreSQL about to surpass SQL Server?
- White screen processing method of fulter startup page
- openlayers 5.0 当地图容器大小改变时,重新加载地图
- arcMap 发布切片服务
- Client interns of a large factory share their experience face to face
- Methods of nested recycleview to solve sliding conflict and incomplete item display
- Coordinate conversion WGS-84 to gcj-02 and gcj-02 to WGS-84
- SSDB foundation 1
猜你喜欢
開關電源設計分享及電源設計技巧圖解
[today in history] April 23: the first video uploaded on YouTube; Netease cloud music officially launched; The inventor of digital audio player was born
Wechat applet part of the mobile phone Preview PDF did not respond
From technical system to business insight, the closing chapter of the practice of small and medium-sized R & D team structure
MySQL Téléchargement et installation de la version Linux
浅谈c语言指针的强制转换
Introduction to micro build low code zero Foundation (lesson 3)
Client interns of a large factory share their experience face to face
Oracle配置st_geometry
开关电源设计分享及电源设计技巧图解
随机推荐
SQL server requires to query the information of all employees with surname 'Wang'
開關電源設計分享及電源設計技巧圖解
Customize the non slidable viewpage and how to use it
Solutions such as unknown or garbled code or certificate problem prompt in Charles's mobile phone packet capture, actual measurement.
Circuit on-line simulation
Problems caused by flutter initialroute and home
Codeforces Round #784 (Div. 4)
[record] typeerror: this getOptions is not a function
Introduction to micro build low code zero Foundation (lesson 3)
Using 8266 as serial port debugging tool
网络协议之:sctp流控制传输协议
Redis common interview questions
SSDB基础2
Practice of Druid SQL and security in meituan review
All table queries and comment description queries of SQL Server
简化路径(力扣71)
Raspberry pie uses root operation, and the graphical interface uses its own file manager
Esp01s with Arduino development environment
openlayers 5.0 两种居中方式
arcgis js api dojoConfig配置