- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在尝试使用回归公式 Z= aX + bY +C 在 3d 点云中查找平面
我实现了最小二乘法和 ransac 解决方案, 但3参数方程将平面拟合限制在2.5D——该公式不能应用于平行于Z轴的平面。
我的问题是如何将平面拟合推广到全 3d?我想添加第四个参数以获得完整的方程式 aX +bY +c*Z + d我怎样才能避免琐碎的 (0,0,0,0) 解决方案?
谢谢!
我正在使用的代码:
from sklearn import linear_model
def local_regression_plane_ransac(neighborhood):
"""
Computes parameters for a local regression plane using RANSAC
"""
XY = neighborhood[:,:2]
Z = neighborhood[:,2]
ransac = linear_model.RANSACRegressor(
linear_model.LinearRegression(),
residual_threshold=0.1
)
ransac.fit(XY, Z)
inlier_mask = ransac.inlier_mask_
coeff = model_ransac.estimator_.coef_
intercept = model_ransac.estimator_.intercept_
最佳答案
此功能现已集成到 https://github.com/daavoo/pyntcloud 中并使平面拟合过程更加简单:
给定一个点云:
你只需要像这样添加一个标量场:
is_floor = cloud.add_scalar_field("plane_fit")
Wich 将为拟合平面的点添加值为 1 的新列。
您可以将标量场可视化:
我认为您可以轻松使用 PCA使平面适合 3D 点而不是回归。
这是一个简单的 PCA 实现:
def PCA(data, correlation = False, sort = True):
""" Applies Principal Component Analysis to the data
Parameters
----------
data: array
The array containing the data. The array must have NxM dimensions, where each
of the N rows represents a different individual record and each of the M columns
represents a different variable recorded for that individual record.
array([
[V11, ... , V1m],
...,
[Vn1, ... , Vnm]])
correlation(Optional) : bool
Set the type of matrix to be computed (see Notes):
If True compute the correlation matrix.
If False(Default) compute the covariance matrix.
sort(Optional) : bool
Set the order that the eigenvalues/vectors will have
If True(Default) they will be sorted (from higher value to less).
If False they won't.
Returns
-------
eigenvalues: (1,M) array
The eigenvalues of the corresponding matrix.
eigenvector: (M,M) array
The eigenvectors of the corresponding matrix.
Notes
-----
The correlation matrix is a better choice when there are different magnitudes
representing the M variables. Use covariance matrix in other cases.
"""
mean = np.mean(data, axis=0)
data_adjust = data - mean
#: the data is transposed due to np.cov/corrcoef syntax
if correlation:
matrix = np.corrcoef(data_adjust.T)
else:
matrix = np.cov(data_adjust.T)
eigenvalues, eigenvectors = np.linalg.eig(matrix)
if sort:
#: sort eigenvalues and eigenvectors
sort = eigenvalues.argsort()[::-1]
eigenvalues = eigenvalues[sort]
eigenvectors = eigenvectors[:,sort]
return eigenvalues, eigenvectors
下面是如何将点拟合到平面上:
def best_fitting_plane(points, equation=False):
""" Computes the best fitting plane of the given points
Parameters
----------
points: array
The x,y,z coordinates corresponding to the points from which we want
to define the best fitting plane. Expected format:
array([
[x1,y1,z1],
...,
[xn,yn,zn]])
equation(Optional) : bool
Set the oputput plane format:
If True return the a,b,c,d coefficients of the plane.
If False(Default) return 1 Point and 1 Normal vector.
Returns
-------
a, b, c, d : float
The coefficients solving the plane equation.
or
point, normal: array
The plane defined by 1 Point and 1 Normal vector. With format:
array([Px,Py,Pz]), array([Nx,Ny,Nz])
"""
w, v = PCA(points)
#: the normal of the plane is the last eigenvector
normal = v[:,2]
#: get a point from the plane
point = np.mean(points, axis=0)
if equation:
a, b, c = normal
d = -(np.dot(normal, point))
return a, b, c, d
else:
return point, normal
然而,由于此方法对异常值敏感,您可以使用 RANSAC使拟合对异常值具有鲁棒性。
有一个 ransac 的 Python 实现 here .
并且您只需要定义一个平面模型类,以便使用它来将平面拟合到 3D 点。
在任何情况下,如果您可以从异常值中清除 3D 点(也许您可以使用 KD-Tree S.O.R 过滤器),您应该使用 PCA 获得非常好的结果。
这是一个 S.O.R 的实现:
def statistical_outilier_removal(kdtree, k=8, z_max=2 ):
""" Compute a Statistical Outlier Removal filter on the given KDTree.
Parameters
----------
kdtree: scipy's KDTree instance
The KDTree's structure which will be used to
compute the filter.
k(Optional): int
The number of nearest neighbors wich will be used to estimate the
mean distance from each point to his nearest neighbors.
Default : 8
z_max(Optional): int
The maximum Z score wich determines if the point is an outlier or
not.
Returns
-------
sor_filter : boolean array
The boolean mask indicating wherever a point should be keeped or not.
The size of the boolean mask will be the same as the number of points
in the KDTree.
Notes
-----
The 2 optional parameters (k and z_max) should be used in order to adjust
the filter to the desired result.
A HIGHER 'k' value will result(normally) in a HIGHER number of points trimmed.
A LOWER 'z_max' value will result(normally) in a HIGHER number of points trimmed.
"""
distances, i = kdtree.query(kdtree.data, k=k, n_jobs=-1)
z_distances = stats.zscore(np.mean(distances, axis=1))
sor_filter = abs(z_distances) < z_max
return sor_filter
您可以使用可能使用 this implementation 计算的 3D 点的 KDtree 为函数提供数据
关于python - 3d 点云中的平面拟合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38754668/
就目前情况而言,这个问题不太适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、民意调查或扩展讨论。如果您觉得这个问题可以改进并可能重新开放,visit
我计划使用 python 开发一个 Web/云应用程序,它执行以下操作, 1.上传Perl/Python抓取脚本并执行。 2. 上传脚本以按计划运行。 3. 使用不同的输入参数运行同一脚本的多个实例。
我正在开发一个应用程序,我想实现一个功能,可以在相同的用户设备之间共享,比方说,收藏夹、书签等。所以,我想实现类似 iCloud 的东西。 我想到了 2 个可能的想法:Backup Manager 和
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我正在尝试从一系列短语中使一个单词云成为一个词云,而不是从单个单词中重复很多短语。我的数据看起来像这样,数据框的一列是短语列表。 df$names <- c("John", "John", "Jose
对于配置AWS服务(EC2/R53/VPC/S3/..),Terraform等技术在执行回滚、错误处理等方面的方法不可靠。 AWS CloudFormation 模板解决了这些问题。 CloudFor
我无法使用我的 Azure 帐户执行任何操作,例如创建服务器或数据库或任何操作。看起来这一切都围绕着我无法创建的资源组>我收到此错误: 这特别困难,因为我什至无法使用云外壳,因为我得到了这个:请求 C
是否有在客户端使用 socket.io 的云/托管推送系统?据我所知,没有一个系统使用 socket.io AFAIK: http://beaconpush.com/ http://pusher.co
有没有办法在我的计算机上本地运行 RStudio,但使用运行 R 作为引擎的远程计算机而不是本地 R 安装? 需要明确的是,我知道可以将 RStudio 服务器与 Web GUI 一起使用,但我问的是
我正在寻找在这种情况下可以使用的合适服务: 在视频模式下打开相机并将其流式传输到 azure 云。 并从另一方聆听(也包括客户)。 我读到了有关 Azure 媒体服务的信息。 但根据this我知道客户
这个问题已经有答案了: 已关闭12 年前。 Possible Duplicate: Google App Engine, getting started 如何将 Java 应用程序部署到 Google
我有一个用 Java 7 编写的相当大的控制台应用程序,它管理大量的订单处理。 该应用程序使用大量订单 Web 服务、与数据库交互并将数据插入 ERP 系统。该应用程序的要求没有指定用户交互,因此在项
我已经阅读过有关 Windows Azure 的内容,但为了深入了解这项技术,我(显然)需要使用它。我有一个小型 ASP.NET 网站,流量很少,我认为在 Azure 上托管该网站会节省我的钱。除此之
我的 Activity 中有 3 个编辑文本(姓名、手机号码、职业)和一个按钮(保存)。每次用户单击按钮时,我都想将这三个数据保存到 Parse-cloud。然后新 Activity 在 imagev
我正在尝试通过node.js 将传感器数据发送到artik cloud。 (使用网络套接字和串行端口)。但它发送空。有人知道原因吗?我刚刚复制了教程中的代码,因此没有语法错误。 var webSock
我对 docker hub 和 docker cloud 有一点困惑。我有需要安装在客户端服务器中并运行容器的 docker 镜像。我相信这可以使用 docker hub 来完成,它允许在我的私有(p
晋城,华夏文化发祥地之一。两万年前留下高都遗址、塔水河、下川等人类遗址,女娲补天、愚公移山等神话传说,如今在云上有了崭新的魅力。 9月3日,阿里云数字中国行•晋城峰会期间,晋城市人民政府公布了
我刚开始使用 Airflow 插件,有点困惑。 我在 GCP (composer-1.13.4-airflow-1.10.12) 上使用 Cloud Composer 作为托管服务运行它 我按照文档编
据我所知,PHP 分析工具 XDebug 将其结果保存到文件中。然而,当应用程序运行在云分布式环境中时,处理此类文件是很困难的。处理这种情况的最佳做法是什么? XDebug 中是否有任何方法(最好是可
我们正在将 PHP 网站迁移到 Azure 云 Web 服务(Web 角色)。 目前,该网站通过驱动器盘符访问将用户提交的图像文件保存到文件系统。然后通过 URL 提供这些图像,例如content.e
我是一名优秀的程序员,十分优秀!