-
点云的基本组成
点云数据可以由空间坐标或加其他的形式出现,如
空间坐标(x,y,z)
空间坐标+强度 (x,y,z,i)
空间坐标+颜色信息 (x,y,z,(r,g,b))
空间坐标+法向量(x,y,z,n) -
点云存储格式
pcd文件:包含文件说明和点云数据两部分,文件说明由11行组成,包括文件说明、版本、字节数、类型、维度等,从第12行开始为点云数据。
ply文件:包括文件说明和点云数据两个部分,前三行与最后一行是描述语句,中间包含数据类型、数据数量及其属性等和按行存储的数据值。
txt文件:通常只包含点云数据不包含文件说明。txt中每一行即为一个点,行数则代表点数 -
点云体素
为了让三维点云也具备二维图像一样的均匀分布,体素将整个三维空间分为立体方格,体素可以将三维空间中的点云变为均匀分布的空间,使得点云数据均匀化。 -
点云的法向量
对于一个点的点云数据,其法向量是由周围点云数据计算拟合得到的平面 -
点云的拼接
对于不同视点的点云数据,需要通过点云配准来解决坐标系不一致的问题,例如ICP算法等 -
点云的旋转
点云旋转通过欧拉角、旋转矩阵、旋转向量和四元数等描述欧拉角:
旋转矩阵
-
点云数据增强的方法
7.1 中心归一化,沿着point这个维度,减去均值并处以点距离原点的最大距离。
def pc_normalize(pc):
centroid = np.mean(pc, axis=0)
pc = pc - centroid
m = np.max(np.sqrt(np.sum(pc ** 2, axis=1)))
pc = pc / m
return pc
7.2 打乱点云顺序
def shuffle_points(batch_data):
""" Shuffle orders of points in each point cloud -- changes FPS behavior.
Use the same shuffling idx for the entire batch.
Input:
BxNxC array
Output:
BxNxC array
"""
idx = np.arange(batch_data.shape[1])
np.random.shuffle(idx)
return batch_data[:,idx,:]
7.3 点云随机旋转,使用旋转矩阵
def rotate_point_cloud(batch_data):
""" Randomly rotate the point clouds to augument the dataset
rotation is per shape based along up direction
Input:
BxNx3 array, original batch of point clouds
Return:
BxNx3 array, rotated batch of point clouds
"""
rotated_data = np.zeros(batch_data.shape, dtype=np.float32)
for k in range(batch_data.shape[0]):
rotation_angle = np.random.uniform() * 2 * np.pi
cosval = np.cos(rotation_angle)
sinval = np.sin(rotation_angle)
rotation_matrix = np.array([[cosval, 0, sinval],
[0, 1, 0],
[-sinval, 0, cosval]])
shape_pc = batch_data[k, ...]
rotated_data[k, ...] = np.dot(shape_pc.reshape((-1, 3)), rotation_matrix)
return rotated_data
7.4 Z方向的点云随机旋转
def rotate_point_cloud_z(batch_data):
""" Randomly rotate the point clouds to augument the dataset
rotation is per shape based along up direction
Input:
BxNx3 array, original batch of point clouds
Return:
BxNx3 array, rotated batch of point clouds
"""
rotated_data = np.zeros(batch_data.shape, dtype=np.float32)
for k in range(batch_data.shape[0]):
rotation_angle = np.random.uniform() * 2 * np.pi
cosval = np.cos(rotation_angle)
sinval = np.sin(rotation_angle)
rotation_matrix = np.array([[cosval, sinval, 0],
[-sinval, cosval, 0],
[0, 0, 1]])
shape_pc = batch_data[k, ...]
rotated_data[k, ...] = np.dot(shape_pc.reshape((-1, 3)), rotation_matrix)
return rotated_data
7.5 点云的随机扰动
def jitter_point_cloud(batch_data, sigma=0.01, clip=0.05):
""" Randomly jitter points. jittering is per point.
Input:
BxNx3 array, original batch of point clouds
Return:
BxNx3 array, jittered batch of point clouds
"""
B, N, C = batch_data.shape
assert(clip > 0)
jittered_data = np.clip(sigma * np.random.randn(B, N, C), -1*clip, clip)
jittered_data += batch_data
return jittered_data
7.6 点云的随机平移
def shift_point_cloud(batch_data, shift_range=0.1):
""" Randomly shift point cloud. Shift is per point cloud.
Input:
BxNx3 array, original batch of point clouds
Return:
BxNx3 array, shifted batch of point clouds
"""
B, N, C = batch_data.shape
shifts = np.random.uniform(-shift_range, shift_range, (B,3))
for batch_index in range(B):
batch_data[batch_index,:,:] += shifts[batch_index,:]
return batch_data
7.7 点云的随机缩放
def random_scale_point_cloud(batch_data, scale_low=0.8, scale_high=1.25):
""" Randomly scale the point cloud. Scale is per point cloud.
Input:
BxNx3 array, original batch of point clouds
Return:
BxNx3 array, scaled batch of point clouds
"""
B, N, C = batch_data.shape
scales = np.random.uniform(scale_low, scale_high, B)
for batch_index in range(B):
batch_data[batch_index,:,:] *= scales[batch_index]
return batch_data
7.8 点云的随机丢弃
def random_point_dropout(batch_pc, max_dropout_ratio=0.875):
''' batch_pc: BxNx3 '''
for b in range(batch_pc.shape[0]):
dropout_ratio = np.random.random()*max_dropout_ratio # 0~0.875
drop_idx = np.where(np.random.random((batch_pc.shape[1]))<=dropout_ratio)[0]
if len(drop_idx)>0:
batch_pc[b,drop_idx,:] = batch_pc[b,0,:] # set to the first point
return batch_pc
代码来源于https://github.com/yanx27/Pointnet_Pointnet2_pytorch