点对点配准
两个点云中对应的要进行点对点配准的顶点进行严格的点对点配准。
API接口
def registration_ransac_based_on_correspondence(source, target, corres, max_correspondence_distance, estimation_method=None, *args, **kwargs): # real signature unknown; NOTE: unreliably restored from __doc__
"""
registration_ransac_based_on_correspondence(source, target, corres, max_correspondence_distance, estimation_method=TransformationEstimationPointToPoint without scaling., ransac_n=3, checkers=[], criteria=RANSACConvergenceCriteria class with max_iteration=100000, and confidence=9.990000e-01)
Function for global RANSAC registration based on a set of correspondences
Args:
source (open3d.geometry.PointCloud): 源点云.
target (open3d.geometry.PointCloud): 目标点云.
corres (open3d.utility.Vector2iVector): o3d.utility.Vector2iVector 特征点索引对.
max_correspondence_distance (float): 最大点对响应距离.
estimation_method (open3d.pipelines.registration.TransformationEstimation, optional, default=TransformationEstimationPointToPoint without scaling.): 评估方法. One of (``TransformationEstimationPointToPoint``, ``TransformationEstimationPointToPlane``, ``TransformationEstimationForGeneralizedICP``, ``TransformationEstimationForColoredICP``)
ransac_n (int, optional, default=3): Fit ransac with ``ransac_n`` correspondences
checkers (List[open3d.pipelines.registration.CorrespondenceChecker], optional, default=[]): Vector of Checker class to check if two point clouds can be aligned. One of (``CorrespondenceCheckerBasedOnEdgeLength``, ``CorrespondenceCheckerBasedOnDistance``, ``CorrespondenceCheckerBasedOnNormal``)
criteria (open3d.pipelines.registration.RANSACConvergenceCriteria, optional, default=RANSACConvergenceCriteria class with max_iteration=100000, and confidence=9.990000e-01): Convergence criteria
Returns:
open3d.pipelines.registration.RegistrationResult
"""
pass
案例
import copy
from open3d.cpu.pybind.pipelines import *
from open3d.cpu.pybind import io, geometry, visualization, utility
def draw_registration_result_original_color(source, target, transformation, show_coord=False, coord_length=200):
"""
:param source:
:param target:
:param transformation:
:param show_coord: 是否显示坐标轴网格
"""
source_temp = copy.deepcopy(source)
source_temp.transform(transformation)
geomes = [source_temp, target]
if show_coord:
# 坐标系网格
mesh = geometry.TriangleMesh().create_coordinate_frame(size=coord_length)
geomes.append(mesh)
visualization.draw_geometries(geomes,
point_show_normal=False,
mesh_show_wireframe=True)
pass
if __name__ == '__main__':
# 原点云,要被进行矩阵变换的点云
pcd_source = io.read_point_cloud(f'./pcd_source.ply')
# 目标点云,希望变换到该点云位置的点云
pcd_target = io.read_point_cloud(f'./pcd_target.ply')
# 要进行点对点配准的 顶点索引对, 最少3个索引对(一定概率失败),建议4个索引对及以上!
corres = [[0, 0], [1, 1], [2, 2], [7, 23]]
corres = utility.Vector2iVector(corres) # 进行格式转换
# 该参数根据具体点云特征进行适当变更,如果值太小两点云会无法重合!
max_correspondence_distance = 10
# 调用点对点配准接口
result_icp = registration.registration_ransac_based_on_correspondence(
pcd_source, pcd_target,
corres, max_correspondence_distance)
# 获取变换矩阵
transformation = result_icp.transformation
print(result_icp)
# 给点云上色
pcd_source.paint_uniform_color([1, 0.706, 0]) # source 为黄色
pcd_target.paint_uniform_color([0, 0.651, 0.929]) # target 为蓝色
draw_registration_result_original_color(pcd_source, pcd_target, transformation)
pass
注释
案例中是分别将 源点云的 第 0,1,2,7
个点和目标点云的第 0,1,2,23
个点进行点对点配准!