【问题标题】:python pointcloud filtering with numpypython点云过滤与numpy
【发布时间】:2021-08-27 08:10:05
【问题描述】:

我正在尝试使用 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

【问题讨论】:

    标签: python numpy realsense


    【解决方案1】:

    通过使用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]

    【讨论】:

    • 好的,h,w 形状的数组是问题所在。如何结合两个搜索? numpy 怎么知道它应该在 x 上搜索,而不是在 x 或 z 上搜索
    • @bluelemonade 抱歉,我的回答不正确,我已经编辑过了,见上文。
    • 太棒了,这减少了我的 poitcloud massiv。我可以使用 verts2 = verts[mask[..., 0]] 创建一个掩码数组。我可以使用相同的掩码减少 texcoords 吗?先分割它,然后用 verts 掩码对其进行掩码?
    • texcoords的形状是什么?
    • 我认为是verts的第一个to,它的大小是verts的2/3。
    猜你喜欢
    • 2021-02-15
    • 1970-01-01
    • 2021-07-05
    • 2020-06-24
    • 2013-08-14
    • 2022-10-20
    • 2021-11-17
    • 2017-07-13
    相关资源
    最近更新 更多