点云学习01

点云学习01

1. PCA and normal vector

# compute the PCA
def PCA(data, correlation = False, sort = True):
    data_normal = data - np.mean(data, axis = 0)
    eig, eig_vec = np.linalg.eig(np.dot(data_normal.transpose(), data_normal))
    if sort and data_normal.shape[0] > 0:
        sort_index = eig.argsort()[::-1]
        eig = np.sqrt(np.abs(eig[sort_index]) / data_normal.shape[0])
        eig_vec = eig_vec[:, sort_index]

    return eig, eig_vec 

# main
cat_index = 'airplane'
root_dir = '/home/lss/Code/point_cloud/modelnet40_normal_resampled'
file_name = os.path.join(root_dir, cat_index, cat_index + "_0134.txt")

# load data
data = np.loadtxt(file_name, dtype = float, delimiter = ',')
point_cloud = data[:, 0:3]
point_cloud_o3d = o3d.geometry.PointCloud()
point_cloud_o3d.points = o3d.utility.Vector3dVector(point_cloud)
o3d.visualization.draw_geometries([point_cloud_o3d])

# PCA demo
w, v = PCA(point_cloud)
point_mean = np.mean(point_cloud, axis=0)
pca_vec = w * v
pca_points = np.vstack((np.array([0, 0, 0]), pca_vec.transpose())) + point_mean
line_index = [
    [0, 1],
    [0, 2],
    [0, 3]
]
line_colors = [
    [1.0, 0, 0],
    [1.0, 0, 0],
    [1.0, 0, 0]
]
pca_line_set = o3d.geometry.LineSet(
    points = o3d.ut
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值