首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何有效地基于点坐标和所需的bin网格大小来存储三维点云数据?

如何有效地基于点坐标和所需的bin网格大小来存储三维点云数据?
EN

Stack Overflow用户
提问于 2022-01-14 22:14:51
回答 1查看 558关注 0票数 1

我在open3D中有一个很大的点云,我想基本上建立一个三维网格,并根据它们在哪个立方体上存储点。其他人称它为“三维空间中的二进制”。

只有一个方向的网格的例子图像(我想分裂成3D卷)

我想要做的更好的形象

示例:

代码语言:javascript
复制
import numpy as np

A = np.array([[ 0, -1, 10],
 [ 1, -2 ,11],
 [ 2, -3 ,12],
 [ 3, -4 ,13],
 [ 4, -5 ,14],
 [ 5, -6 ,15],
 [ 6, -7 ,16],
 [ 7, -8 ,17],
 [ 8, -9 ,18]])

#point 1: X,Y,Z
#point 2: X,Y,Z

print(A)

X_segments = np.linspace(0,8,3) #plane at beginning, middle and end - this creates 2 sections where data can be
Y_segments = np.linspace(-9,-1,3)
Z_segments = np.linspace(10,18,3)

#all of these combined form 4 cuboids where data can be 
#its also possible for the data to be outside these cuboids but we can ignore that

bin1 =  A where A[0,:] is > X_segments [0] and < X_segments[1]
    and A where A[1,:] is > Y_segments [0] and < Y_segments[1] 
    and A where A[2,:] is > Z_segments [0] and < Z_segments[1] 

bin2 =  A where A[0,:] is > X_segments [1] and < X_segments[2]
    and A where A[1,:] is > Y_segments [0] and < Y_segments[1] 
    and A where A[2,:] is > Z_segments [0] and < Z_segments[1] 

bin3 =  A where A[0,:] is > X_segments [1] and < X_segments[2]
    and A where A[1,:] is > Y_segments [1] and < Y_segments[2] 
    and A where A[2,:] is > Z_segments [0] and < Z_segments[1] 

bin4 =  A where A[0,:] is > X_segments [1] and < X_segments[2]
    and A where A[1,:] is > Y_segments [1] and < Y_segments[2] 
    and A where A[2,:] is > Z_segments [1] and < Z_segments[2]  

谢谢大家!

EN

回答 1

Stack Overflow用户

发布于 2022-01-14 22:46:35

您可以尝试以下方法:

代码语言:javascript
复制
import numpy as np

A = np.array([[ 0, -1, 10],
              [ 1, -2 ,11],
              [ 2, -3 ,12],
              [ 3, -4 ,13],
              [ 4, -5 ,14],
              [ 5, -6 ,15],
              [ 6, -7 ,16],
              [ 7, -8 ,17],
              [ 8, -9 ,18]])

X_segments = np.linspace(0,8,3)
Y_segments = np.linspace(-9,-1,3)
Z_segments = np.linspace(10,18,3)

edges = [X_segments, Y_segments, Z_segments]

print(edges) # just to show edges of the bins

我们得到:

代码语言:javascript
复制
[[ 0.  4.  8.]
 [-9. -5. -1.]
 [10. 14. 18.]]

接下来,沿着每个坐标系应用np.digitize

代码语言:javascript
复制
coords = np.vstack([np.digitize(A.T[i], b, right=True) for i, b in enumerate(edges)]).T
print(coords)

这意味着:

代码语言:javascript
复制
[[0 2 0]
 [1 2 1]
 [1 2 1]
 [1 2 1]
 [1 1 1]
 [2 1 2]
 [2 1 2]
 [2 1 2]
 [2 0 2]]

此数组的行描述A的相应行在回收箱网格中的位置。例如,第二行[1, 2, 1]表示A的第二行,即[1, -2, 11]位于沿X轴的第一行(自0 < 1 <= 4)、沿Y轴的第二行(自-5 < -2 <= -1),以及沿Z轴的第一行(自10 < 11 <= 14)。然后您可以选择属于每个长方体的元素:

代码语言:javascript
复制
# select rows of A that are in the cuboid with coordinates [1, 2, 1]
A[np.all(coords == [1, 2, 1], axis=1)] 

这意味着:

代码语言:javascript
复制
array([[ 1, -2, 11],
       [ 2, -3, 12],
       [ 3, -4, 13]])
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70717111

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档