我感觉注释写的挺全的,就不多写说明了
原本是用来做无人机拍摄点的,需要的话自己拿走改吧改吧,分享给刚入门的兄弟们
class Obb_show(object):
def __init__(self, point, cls=None, clusters=None):
"""
参数:
point:[x,y,z] shape[n,3]
cls:分类码 shape[n]
clusters:实例码 shape[n]
"""
self.point = point
self.cls = cls
if self.cls is None:
self.cls = point[:,2]
self.clusters = clusters
if self.clusters is None:
self.clusters = np.ones((point.shape[0]))
# 求一下最大边长,画图的时候外边界用
xl = np.max(self.point[:,0]) - np.min(self.point[:,0])
yl = np.max(self.point[:,1]) - np.min(self.point[:,1])
zl = np.max(self.point[:,2]) - np.min(self.point[:,2])
self.l = max(xl,yl,zl)/2
self.median = np.array([xl,yl,zl])/2 + np.array([np.min(self.point[:,0]),np.min(self.point[:,1]),np.min(self.point[:,2])])
def obb(self, point):
point1 = point.transpose(1,0)
cov_m = np.cov(point1) # 求协方差矩阵
vector, matrix = np.linalg.eig(cov_m) # 将协方差矩阵生成特征值和特征向量 取特征向量
return vector, matrix
def show(self, cls=None, vector_show=False, line=1, mode='box', camrea=False):
"""
参数:
cls:当cls不为None的时候,只显示当前分类码的obb盒
vector:为Ture时显示特征向量
line: 特征向量的长度 默认1米
mode: 两种模式 ‘box’,‘mend’
returm:
mend_list: list 根据obb盒补充的点 [m,n,3]
camera_list: list 拍摄点 每个实例三个拍摄点 [m,3,3]
"""
mp.figure('3D Scatter')
ax3d = mp.gca(projection='3d')
# ax3d.set_aspect("equal")
ax3d.set_xlabel('X', fontsize=14