gpt4 book ai didi

opencv - 小型二维点集的简单配准算法

转载 作者:太空宇宙 更新时间:2023-11-03 20:55:27 25 4
gpt4 key购买 nike

我正在尝试找到一种简单的算法来找到两组 2D 点(配准)之间的对应关系。一组包含我想要查找的对象的模板,第二组主要包含属于感兴趣对象的点,但它可能有噪声(缺失点以及不属于该对象的附加点) .两组都包含大约 40 个二维点。第二组是第一组的单应性(平移、旋转和透视变换)。

我有兴趣找到一种注册算法以获得点对应。我将使用这些信息来找到两组之间的转换(所有这些都在 OpenCV 中)。

谁能推荐一个算法、库或一小段代码来完成这项工作?由于我处理的是小集,因此不必对其进行 super 优化。目前,我的方法是类似 RANSAC 的算法:

  1. 从第 1 组和第 2 组中随机选择 4 个点。
  2. 计算变换矩阵 H(使用 openCV getPerspective())
  3. 使用 H 扭曲第一组点并测试它们如何与第二组点对齐
  4. 重复 1-3 N 次并根据某些指标(例如平方和)选择最佳变换。

有什么想法吗?感谢您的输入。

最佳答案

通过 python,您可以使用 Open3D 库,在 Anaconda 中安装它非常容易。为了您的目的 ICP 应该工作正常,所以我们将使用经典的 ICP,它最小化每次迭代中最近点之间的点到点距离。这是注册 2 朵云的代码:

import numpy as np
import open3d as o3d

# Parameters:
initial_T = np.identity(4) # Initial transformation for ICP

distance = 0.1 # The threshold distance used for searching correspondences
(closest points between clouds). I'm setting it to 10 cm.

# Read your point clouds:
source = o3d.io.read_point_cloud("point_cloud_1.xyz")
target = o3d.io.read_point_cloud("point_cloud_0.xyz")

# Define the type of registration:
type = o3d.pipelines.registration.TransformationEstimationPointToPoint(False)
# "False" means rigid transformation, scale = 1

# Define the number of iterations (I'll use 100):
iterations = o3d.pipelines.registration.ICPConvergenceCriteria(max_iteration = 100)

# Do the registration:
result = o3d.pipelines.registration.registration_icp(source, target, distance, initial_T, type, iterations)

result 是一个包含 4 个东西的类:转换 T(4x4)、2 个度量(rmse 和适应度)和对应集。

enter image description here

要访问转换:

enter image description here

我经常使用它来处理从地面激光扫描仪 (TLS) 和机器人 (Velodiny LIDAR) 获得的 3D 云。

使用 MATLAB:我们将再次使用点对点 ICP,因为您的数据是二维的。这是一个在三角形内随机生成的两个点云的最小示例:

% Triangle vértices:
V1 = [-20, 0; -10, 10; 0, 0];
V2 = [-10, 0; 0, 10; 10, 0];
% Create clouds and show pair:
points = 5000
N1 = criar_nuvem_triangulo(V1,points);
N2 = criar_nuvem_triangulo(V2,points);
pcshowpair(N1,N2)

% Registrate pair N1->N2 and show:
[T,N1_tranformed,RMSE]=pcregistericp(N1,N2,'Metric','pointToPoint','MaxIterations',100);
pcshowpair(N1_tranformed,N2)

“criar_nuvem_triangulo”是一个在三角形内生成随机点云的函数:

function [cloud] = criar_nuvem_triangulo(V,N)
% Function wich creates 2D point clouds in triangle format using random
% points
% Parameters: V = Triangle vertices (3x2 Matrix)| N = Number of points
t = sqrt(rand(N, 1));
s = rand(N, 1);
P = (1 - t) * V(1, :) + bsxfun(@times, ((1 - s) * V(2, :) + s * V(3, :)), t);
points = [P,zeros(N,1)];
cloud = pointCloud(points)
end

结果: enter image description here

关于opencv - 小型二维点集的简单配准算法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34600917/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com