python 使用 numpy 进行点云过滤

python pointcloud filtering with numpy

我正在尝试使用 numpy 过滤点云。

我将所有内容都转换为 numpy 数组。

verts = np.asarray (points.get_vertices (2)). reshape (h, w, 3)

现在我会,例如喜欢只查看某个 xmin、xmax 范围内的值。或者还有 xmin、xmax、ymin、ymax。

I tried the following for the x filter

verts = np.asarray(points.get_vertices(2)).reshape(h, w, 3)
texcoords = np.asarray(points.get_texture_coordinates(2))


xmin = -0.25
xmax = 0.25
ymin = 0.0
ymax = 1.0

inidx = np.all(np.logical_and(xmin <= verts, verts <= xmax), axis=0)
inbox = verts[inidx]
print(verts.length, inbox.length)

但我已经收到一条错误消息

IndexError: boolean index did not match indexed array along dimension 1; dimension is 212 but corresponding boolean dimension is 3

通过 np.split:

分隔不同的组件
>>> x, y, z = np.split(verts, 3, axis=-1)

您可以根据 xy:

与乘法运算符组合条件
>>> mask = (xmin <= x)*(x <= xmax)*(ymin <= y)*(y <= ymax)

然后屏蔽你的 verts 数组:

>>> verts_masked = verts[mask[..., 0]]
tensor([[ 0.1221,  0.2402,  0.7808],
        [ 0.1274,  0.1203, -0.9398],
        [ 0.0789,  0.8018, -0.7915],
        [ 0.1515,  0.3616, -0.2061],
        [ 0.2166,  0.3970,  0.4706],
        [ 0.2421,  0.0457,  0.1082],
        [ 0.0480,  0.9252,  0.2259],
        [ 0.2145,  0.5752, -0.3701],
        [-0.2099,  0.4220,  0.2342],
        [ 0.0949,  0.9467, -0.4768],
        [ 0.0746,  0.2131, -0.1160],
        [-0.2072,  0.4472, -0.3754],
        [-0.0994,  0.8972, -0.7704],
        [ 0.2424,  0.3210, -0.2291],
        [ 0.1093,  0.2599, -0.2868],
        [-0.2482,  0.6001, -0.3283]])

此外,如果您还想用 mask 掩盖 texcoords

>>> textcoords_masked = textcoords[mask[..., 0]]

要根据 z 对结果数组进行排序,您可以使用 np.argsort:

>>> indices = np.argsort(verts_masked[:,-1])

然后将 vertstextcoords 的筛选排序数组分别作为 verts_masked[indices]textcoords_masked[indices]