【问题标题】:Bounding Box with PCA带有 PCA 的边界框
【发布时间】:2013-07-30 08:33:28
【问题描述】:

我尝试用 PCA 创建一个定向边界框。在图片中你可以看到我的结果:

  • 红点:点云
  • 蓝色向量: PCA 组件

我尝试将点投影到向量上,以获得最小值、最大值和平均值。

但是我现在如何定义我的盒子呢?有什么想法吗?

我想得到一个像:质心和两个方向的最小值最大值的框。

【问题讨论】:

    标签: pca bounding-box point-cloud-library point-clouds


    【解决方案1】:

    您的问题与 PCA 无关, 至于如何处理平面中的点和线: 移动点,并将点投影到一条线上。 (有关这方面的基础知识,请查看 SO questions/tagged/2d+geometry, 或使用这些标签提出新问题。) 如果没有这些基础知识,以及一点 Python 或 Matlab, 这个 Python 小程序毫无意义, 但无论如何它都在这里:

    from __future__ import division
    import numpy as np  # http://www.numpy.org/
    
    def pcabox( Pointcloud, Pca1, Pca2 ):
        """ Lo1, Hi1, Lo2, Hi2 = pcabox( Pointcloud, Pca1, Pca2 )
            In: Pointcloud: an N x 2 array of points
            In: Pca1, Pca2: unit vectors at right angles, from PCA
            Out: Lo1, Hi1, Lo2, Hi2: midpoints of the sides of a bounding box
        """
            # convert inputs to numpy arrays (if they aren't already) --
        Pointcloud = np.asarray(Pointcloud)
        Pca1 = np.asarray(pca1)
        Pca2 = np.asarray(pca2)
            # check N x 2 --
        assert Pointcloud.ndim == 2  and  Pointcloud.shape[1] == 2, Pointcloud.shape
    
        C = np.mean( Pointcloud, axis=0 )  # the centre of all the points
        Pointcloud = Pointcloud - C  # shift the cloud to be centred at [0 0]
    
            # distances along the long axis t * Pca1 --
        Dist1 = np.dot( Pointcloud, Pca1 )
        Lo1 = Dist1.min() * Pca1
        Hi1 = Dist1.max() * Pca1
            # and along the short axis t * Pca2 --
        Dist2 = np.dot( Pointcloud, Pca2 )
        Lo2 = Dist2.min() * Pca2
        Hi2 = Dist2.max() * Pca2
    
        return [Lo1, Hi1, Lo2, Hi2] + C  # 4 points
    

    【讨论】:

    • 我猜他用的是PCL(pointcloud library),答案需要用到pcl classes/functions。
    猜你喜欢
    • 2013-06-03
    • 2015-12-22
    • 1970-01-01
    • 2021-06-15
    • 2016-12-21
    • 1970-01-01
    • 1970-01-01
    • 2021-08-14
    • 2016-04-22
    相关资源
    最近更新 更多