Pointnet中点云旋转

在pointnet的文件夹里有train.py, provider.py 和evaluate.py, 其中打开provider.py,里面有点云旋转的代码。

1. shuffle_data(data, labels) 函数用来在B这个维度上随机打乱数据。注释中输入维度B:batch_size,N:num_pointsdef 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
 

2. rotate_point_cloud(batch_data) 函数用来绕竖直轴随机旋转点云,作为数据集增强的一部分。因为实际激光雷达采集数据的时候同一个物体由于角度的不同采集到的点云坐标也不同,不希望这导致不同的分类。通过循环旋转batch中的每一个样本(特征向量)。输入点云只有3个维度(XYZ),与旋转变换矩阵相乘返回旋转后的点云。

def rotate_point_cloud_by_angle(batch_data, rotation_angle):
 

这一函数与上一个类似,只是可以指定旋转角度。

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)
    # randn(): standard norm distribution
    # clip(): limit the data within min and max
    jittered_data = np.clip(sigma * np.random.randn(B, N, C), -1*clip, clip)
    jittered_data += batch_data
    return jittered_data
 

3.jitter_point_cloud(batch_data, sigma=0.01, clip=0.05) 在原始点云数据集上通过标准正太分布(np.random.randn())添加噪声,作为数据集增强的一种。噪声数据用np.clip()函数限幅。默认是在点的每一个维度(C:Channel)上添加噪声,也可以按需要修改代码。def getDataFiles(list_filename):
    return [line.rstrip() for line in open(list_filename)]
 
def load_h5(h5_filename):
    f = h5py.File(h5_filename)
    data = f['data'][:]
    label = f['label'][:]
    return (data, label)
 
def loadDataFile(filename):
    return load_h5(filename)
 
def load_h5_data_label_seg(h5_filename):
    f = h5py.File(h5_filename)
    data = f['data'][:]
    label = f['label'][:]
    seg = f['pid'][:]
    return (data, label, seg)
 
 
def loadDataFile_with_seg(filename):
    return load_h5_data_label_seg(filename)
 

这些函数用来加载h5py格式的数据集

 

 

--------------------- 本文来自 shaozhenghan 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/shaozhenghan/article/details/81087372?utm_source=copy

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值