记录一些点云处理相关的东西。
-
注意检查函数的输入是弧度还是角度
-
不同软件使用的坐标系
调用不同的库之前要记得进行坐标系的变换。
-
深度图不能resize太小,否则转成点云后,物体边缘的点会不准。
-
pytorch实现voxel_downsample,在4090上百万个点降采样只要几毫秒。
import torch def unique(x, dim=None): """Unique elements of x and indices of those unique elements https://github.com/pytorch/pytorch/issues/36748#issuecomment-619514810 e.g. unique(tensor([ [1, 2, 3], [1, 2, 4], [1, 2, 3], [1, 2, 5] ]), dim=0) => (tensor([[1, 2, 3], [1, 2, 4], [1, 2, 5]]), tensor([0, 1, 3])) """ unique, inverse = torch.unique(x, sorted=True, return_inverse=True, dim=dim) perm = torch.arange(inverse.size(0), dtype=inverse.dtype, device=inverse.device) inverse, perm = inverse.flip([0]), perm.flip([0]) index = inverse.new_empty(unique.size(0)).scatter_(0, inverse, perm) return unique, index def voxel_downsample(points, colors, features=None, cell_size=0.1): points_ = torch.round(points / cell_size) points_down, index = unique(points_, dim=0) points_down = points_down * cell_size colors_down = colors[index, :] if features is None: return points_down, colors_down features_down = features[index, :] return points_down, colors_down, features_down