如何实现点云体素化及由密集特征得到二维伪图像特征

点云体素化

    def preprocess(self, lidar):
        #[N,4]
        # This func cluster the points in the same voxel.
        # shuffling the points
        np.random.shuffle(lidar)
        #把每个点分配到体素里,点坐标减去起始,除以每个体素的大小
        voxel_coords = ((lidar[:, :3] - np.array([self.xrange[0], self.yrange[0], self.zrange[0]])) / (
                        self.vw, self.vh, self.vd)).astype(np.int32)

        # convert to  (D, H, W)  [N,3]
        voxel_coords = voxel_coords[:,[2,1,0]]
        #np.unique该函数是去除数组中的重复数字,并进行排序之后输出。axis=0(返回二维数组的唯一行)return_inverse返回旧列表里面的值在新列表里的索引
        #return_counts返回新列表里面的行在旧列表里面的个数。
        voxel_coords, inv_ind, voxel_counts = np.unique(voxel_coords, axis=0, \
                                                  return_inverse=True, return_counts=True)
        #[N1,3],[N,1],[N1,1]N1表示非空体素的个数,voxel_counts统计每个非空体素里面的点个数

        voxel_features = []

        for i in range(len(voxel_coords)):
            #self.T每个体素里面最多点数
            voxel = np.zeros((self.T, 7), dtype=np.float32)
            #得到这个体素里面的点
            pts = lidar[inv_ind == i]
            if voxel_counts[i] > self.T:
                pts = pts[:self.T, :]
                voxel_counts[i] = self.T
            # 进行数据扩充,np.concatenate不增加维度对两向量相加
            voxel[:pts.shape[0], :] = np.concatenate((pts, pts[:, :3] - np.mean(pts[:, :3], 0)), axis=1)
            voxel_features.append(voxel)
        #voxel_features[N1,35,7],voxel_coords[N1,3]
        return np.array(voxel_features), voxel_coords

密集特征得到二维伪图像特征

def voxel_indexing(self, sparse_features, coords):
    #sparse_features[B,N1,C]  coords[N1,4]
    dim = sparse_features.shape[-1]

    dense_feature = torch.zeros(cfg.N, cfg.D, cfg.H, cfg.W, dim).to(cfg.device)

    dense_feature[coords[:,0], coords[:,1], coords[:,2], coords[:,3], :]= sparse_features

    return dense_feature.permute(0, 4, 1, 2, 3)

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

CVplayer111

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值