[英]Drawing Bounding Box in MatplotLib 3D Scatterplot
You need to define where your vertices are, and which edges need connecting.您需要定义顶点在哪里,以及哪些边需要连接。 Assuming you have defined a set of edges as pairs of vertices in some list
AllEdgesVertexPairs
, ask matplotlib to make a line for each pair.假设您已在某个列表
AllEdgesVertexPairs
中将一组边定义为顶点对,请让 matplotlib 为每一对创建一条线。
#Plot a line segment for each edge pair:
for SingleEdgeVertexPair in AllEdgesVertexPairs:
Vertex1 = SingleEdgeVertexPair[0]
Vertex2 = SingleEdgeVertexPair[1]
EdgeXvals = [Vertex1[0], Vertex2[0] ]
EdgeYvals = [Vertex1[1], Vertex2[1] ]
EdgeZvals = [Vertex1[2], Vertex2[2] ]
matplotlib.pyplot.plot(
EdgeXvals,
EdgeYvals,
EdgeZvals,
c='k',
marker=None,
linestyle = '-',
linewidth = 0.2,
)
In a particular case for myself, I needed to plot a cube so my AllEdgesVertexPairs
looked like:在我自己的一个特殊情况下,我需要 plot 一个立方体,所以我的
AllEdgesVertexPairs
看起来像:
[[[ 16. 16. 115.]
[-14. 16. 115.]]
[[ 16. 16. 115.]
[ 16. -14. 115.]]
[[ 16. 16. 115.]
[ 16. 16. 85.]]
[[-14. 16. 115.]
[-14. -14. 115.]]
[[-14. 16. 115.]
[-14. 16. 85.]]
[[ 16. -14. 115.]
[-14. -14. 115.]]
[[ 16. -14. 115.]
[ 16. -14. 85.]]
[[-14. -14. 115.]
[-14. -14. 85.]]
[[ 16. 16. 85.]
[-14. 16. 85.]]
[[ 16. 16. 85.]
[ 16. -14. 85.]]
[[-14. 16. 85.]
[-14. -14. 85.]]
[[ 16. -14. 85.]
[-14. -14. 85.]]]
In your case you will also need 8 vertices, and 12 edges.在您的情况下,您还需要 8 个顶点和 12 个边。 However, its not super obvious how you will choose them.
但是,您将如何选择它们并不是很明显。
If you need an algorithm to choose the bounding vertices yourself based on your image, I would suggest the following:如果您需要一种算法来根据您的图像自己选择边界顶点,我会建议以下内容:
By doing it with PCA and rectangular prism, you can make a mathematical statement about how many points will be inside your "bounding box".通过使用 PCA 和直角棱镜,您可以对“边界框”内的点数做出数学陈述。 (you are basically approximating an ellipsoid derived from a multivariate Gaussian with a rectangular box).
(您基本上是在用一个矩形框逼近从多元高斯派生的椭圆体)。 There are likely better or more clever algorithms out there.
那里可能有更好或更聪明的算法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.