open3d使用fpfh做点云配准

2024-02-12 00:10
文章标签 使用 配准 做点 fpfh open3d

本文主要是介绍open3d使用fpfh做点云配准,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

目录

  • 写在前面
  • 准备
    • 编译open3d
    • 配准example
  • 编译demo
  • 配准测试
  • 参考

写在前面

1、环境:win10,cmake3.22.0-rc1,环境:win10,cmake3.22.0-rc1,已编译好的open3d 0.13
2、源码使用的是官方example
https://github.com/isl-org/Open3D/blob/master/examples/cpp/RegistrationRANSAC.cpp
3、建议先看一下open3d的demo:
open3d 0.13的c++版本使用demo https://blog.csdn.net/qq_41102371/article/details/12106527
4、所有资源已给出链接

准备

编译open3d

windows10编译open3d 0.13 https://blog.csdn.net/qq_41102371/article/details/121014372

配准example

将官方demo的CMakeLists.txt与配准源码RegistrationRANSAC.cpp
下载下来,放在文件夹open3d_fpfh_registration下
https://github.com/isl-org/open3d-cmake-find-package/blob/master/CMakeLists.txt
https://github.com/isl-org/Open3D/blob/master/examples/cpp/RegistrationRANSAC.cpp
并将CMakeLists.txt里面的Draw全部换成RegistrationRANSAC
CMakeLists.txt

# On Ubuntu 18.04, get the latest CMake from https://apt.kitware.com/.
cmake_minimum_required(VERSION 3.18)project(Open3DCMakeFindPackage LANGUAGES C CXX)# The options need to be the same as Open3D's default
# If Open3D is configured and built with custom options, you'll also need to
# specify the same custom options.
option(STATIC_WINDOWS_RUNTIME "Use static (MT/MTd) Windows runtime" ON)
if(STATIC_WINDOWS_RUNTIME)set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
else()set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
endif()# Find installed Open3D, which exports Open3D::Open3D
find_package(Open3D REQUIRED)add_executable(RegistrationRANSAC)
target_sources(RegistrationRANSAC PRIVATE RegistrationRANSAC.cpp)
target_link_libraries(RegistrationRANSAC PRIVATE Open3D::Open3D)# On Windows if BUILD_SHARED_LIBS is enabled, copy .dll files to the executable directory
if(WIN32)get_target_property(open3d_type Open3D::Open3D TYPE)if(open3d_type STREQUAL "SHARED_LIBRARY")message(STATUS "Copying Open3D.dll to ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>")add_custom_command(TARGET RegistrationRANSAC POST_BUILDCOMMAND ${CMAKE_COMMAND} -E copy${CMAKE_INSTALL_PREFIX}/bin/Open3D.dll${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>)endif()
endif()

RegistrationRANSAC.cpp,我在官方代码上做了些修改

// ----------------------------------------------------------------------------
// -                        Open3D: www.open3d.org                            -
// ----------------------------------------------------------------------------
// The MIT License (MIT)
//
// Copyright (c) 2018 www.open3d.org
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
// ----------------------------------------------------------------------------#include <Eigen/Dense>
#include <iostream>
#include <memory>#include "open3d/Open3D.h"using namespace open3d;
using namespace std;
std::tuple<std::shared_ptr<geometry::PointCloud>,std::shared_ptr<pipelines::registration::Feature>>
PreprocessPointCloud(const char *file_name, float voxel_size = 2.0) {//从文件读取点云auto pcd = open3d::io::CreatePointCloudFromFile(file_name);//降采样auto pcd_down = pcd->VoxelDownSample(voxel_size);std::cout << "read " << pcd->points_.size() << " points from " << file_name<< std::endl;std::cout << "voxel_size=" << voxel_size << ", after downsample "<< pcd_down->points_.size() << "points left" << endl;//计算法向量pcd_down->EstimateNormals(open3d::geometry::KDTreeSearchParamHybrid(voxel_size * 2, 30));//计算fpfh特征auto pcd_fpfh = pipelines::registration::ComputeFPFHFeature(*pcd_down,open3d::geometry::KDTreeSearchParamHybrid(voxel_size * 5, 100));return std::make_tuple(pcd_down, pcd_fpfh);
}void PrintHelp() {using namespace open3d;PrintOpen3DVersion();// clang-format offutility::LogInfo("Usage:");utility::LogInfo("    > RegistrationRANSAC source_pcd target_pcd  voxel_size [--method=feature_matching] [--mutual_filter] [--visualize]");// clang-format onutility::LogInfo("");
}int main(int argc, char *argv[]) {using namespace open3d;utility::SetVerbosityLevel(utility::VerbosityLevel::Debug);if (argc < 4 ||utility::ProgramOptionExistsAny(argc, argv, {"-h", "--help"})) {PrintHelp();return 1;}bool visualize = false;if (utility::ProgramOptionExists(argc, argv, "--visualize")) {visualize = true;}//visualize = true;bool mutual_filter = false;//if (utility::ProgramOptionExists(argc, argv, "--mutual_filter")) {//    mutual_filter = true;//}mutual_filter = true;// Prepare inputstd::shared_ptr<geometry::PointCloud> source, target;std::shared_ptr<pipelines::registration::Feature> source_fpfh, target_fpfh;//set voxel_sizefloat voxel_size = std::atof(argv[3]);std::cout << voxel_size << std::endl;float distance_threshold = voxel_size * 1.5;std::tie(source, source_fpfh) = PreprocessPointCloud(argv[1], voxel_size);std::tie(target, target_fpfh) = PreprocessPointCloud(argv[2], voxel_size);pipelines::registration::RegistrationResult registration_result;// Prepare checkersstd::vector<std::reference_wrapper<const pipelines::registration::CorrespondenceChecker>>correspondence_checker;auto correspondence_checker_edge_length =pipelines::registration::CorrespondenceCheckerBasedOnEdgeLength(0.9);auto correspondence_checker_distance =pipelines::registration::CorrespondenceCheckerBasedOnDistance(distance_threshold);correspondence_checker.push_back(correspondence_checker_edge_length);correspondence_checker.push_back(correspondence_checker_distance);registration_result = pipelines::registration::RegistrationRANSACBasedOnFeatureMatching(*source, *target, *source_fpfh, *target_fpfh,mutual_filter, distance_threshold,pipelines::registration::TransformationEstimationPointToPoint(false),3, correspondence_checker,pipelines::registration::RANSACConvergenceCriteria(1000000, 0.999));cout << endl<< "fpfh matrix:" << endl<< registration_result.transformation_ << endl;cout << "inlier(correspondence_set size):"<< registration_result.correspondence_set_.size() << endl;std::vector<std::pair<int, int>> correspondences_ransac;for (int m = 0; m < registration_result.correspondence_set_.size();++m) {std::pair<int, int> pair_(0, 0);pair_.first = registration_result.correspondence_set_[m][0];pair_.second = registration_result.correspondence_set_[m][1];correspondences_ransac.push_back(pair_);}// std::shared_ptr<open3d::geometry::LineSet>auto ransac_lineset =geometry::LineSet::CreateFromPointCloudCorrespondences(*source, *target, correspondences_ransac);std::shared_ptr<geometry::PointCloud> source_transformed_ptr(new geometry::PointCloud);std::shared_ptr<geometry::PointCloud> source_ptr(new geometry::PointCloud);std::shared_ptr<geometry::PointCloud> target_ptr(new geometry::PointCloud);*source_transformed_ptr = *source;*target_ptr = *target;*source_ptr = *source;target->PaintUniformColor({1, 0, 0});                  //红source->PaintUniformColor({0, 1, 0});                  //绿source_transformed_ptr->PaintUniformColor({0, 0, 1});  //蓝source_transformed_ptr->Transform(registration_result.transformation_);if (visualize) {visualization::DrawGeometries({target, source, source_transformed_ptr, ransac_lineset},"Registration result", 960, 900, 960, 100);}return 0;
}

编译demo

cd open3d_fpfh_registration
mkdir build
cd build
cmake -DOpen3D_ROOT="D:/Program Files/open3d" ..
cmake --build . --config Debug

成功生成RegistrationRANSAC.exe
在这里插入图片描述

配准测试

数据就用斯坦福的兔兔,http://graphics.stanford.edu/pub/3Dscanrep/bunny.tar.gz
解压后把bun000.ply和bun045.ply放在open3d_fpfh_registration目录下
回到命令行窗口:

start ./Debug/RegistrationRANSAC.exe ../bun045.ply ../bun000.ply 0.005 --visualize

若是其他数据,改一下…/bun045.ply …/bun000.ply 0.005 --visualize这几个参数就好,分别是source点云路径,target点云路径,降采样网格大小(根据点云大小和数据量来自行调节),–visualize加可视化

配准结果,红色是bun000,绿色是bun045,蓝色是bun045配准至bun000的结果,连线是连接的匹配上的fpfh特征
在这里插入图片描述

参考

文中已列出

--------------------------------------------------------------------------------------------诺有缸的高飞鸟202110

这篇关于open3d使用fpfh做点云配准的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/701183

相关文章

Android kotlin中 Channel 和 Flow 的区别和选择使用场景分析

《Androidkotlin中Channel和Flow的区别和选择使用场景分析》Kotlin协程中,Flow是冷数据流,按需触发,适合响应式数据处理;Channel是热数据流,持续发送,支持... 目录一、基本概念界定FlowChannel二、核心特性对比数据生产触发条件生产与消费的关系背压处理机制生命周期

java使用protobuf-maven-plugin的插件编译proto文件详解

《java使用protobuf-maven-plugin的插件编译proto文件详解》:本文主要介绍java使用protobuf-maven-plugin的插件编译proto文件,具有很好的参考价... 目录protobuf文件作为数据传输和存储的协议主要介绍在Java使用maven编译proto文件的插件

SpringBoot线程池配置使用示例详解

《SpringBoot线程池配置使用示例详解》SpringBoot集成@Async注解,支持线程池参数配置(核心数、队列容量、拒绝策略等)及生命周期管理,结合监控与任务装饰器,提升异步处理效率与系统... 目录一、核心特性二、添加依赖三、参数详解四、配置线程池五、应用实践代码说明拒绝策略(Rejected

C++ Log4cpp跨平台日志库的使用小结

《C++Log4cpp跨平台日志库的使用小结》Log4cpp是c++类库,本文详细介绍了C++日志库log4cpp的使用方法,及设置日志输出格式和优先级,具有一定的参考价值,感兴趣的可以了解一下... 目录一、介绍1. log4cpp的日志方式2.设置日志输出的格式3. 设置日志的输出优先级二、Window

Ubuntu如何分配​​未使用的空间

《Ubuntu如何分配​​未使用的空间》Ubuntu磁盘空间不足,实际未分配空间8.2G因LVM卷组名称格式差异(双破折号误写)导致无法扩展,确认正确卷组名后,使用lvextend和resize2fs... 目录1:原因2:操作3:报错5:解决问题:确认卷组名称​6:再次操作7:验证扩展是否成功8:问题已解

Qt使用QSqlDatabase连接MySQL实现增删改查功能

《Qt使用QSqlDatabase连接MySQL实现增删改查功能》这篇文章主要为大家详细介绍了Qt如何使用QSqlDatabase连接MySQL实现增删改查功能,文中的示例代码讲解详细,感兴趣的小伙伴... 目录一、创建数据表二、连接mysql数据库三、封装成一个完整的轻量级 ORM 风格类3.1 表结构

使用Docker构建Python Flask程序的详细教程

《使用Docker构建PythonFlask程序的详细教程》在当今的软件开发领域,容器化技术正变得越来越流行,而Docker无疑是其中的佼佼者,本文我们就来聊聊如何使用Docker构建一个简单的Py... 目录引言一、准备工作二、创建 Flask 应用程序三、创建 dockerfile四、构建 Docker

Python使用vllm处理多模态数据的预处理技巧

《Python使用vllm处理多模态数据的预处理技巧》本文深入探讨了在Python环境下使用vLLM处理多模态数据的预处理技巧,我们将从基础概念出发,详细讲解文本、图像、音频等多模态数据的预处理方法,... 目录1. 背景介绍1.1 目的和范围1.2 预期读者1.3 文档结构概述1.4 术语表1.4.1 核

Python使用pip工具实现包自动更新的多种方法

《Python使用pip工具实现包自动更新的多种方法》本文深入探讨了使用Python的pip工具实现包自动更新的各种方法和技术,我们将从基础概念开始,逐步介绍手动更新方法、自动化脚本编写、结合CI/C... 目录1. 背景介绍1.1 目的和范围1.2 预期读者1.3 文档结构概述1.4 术语表1.4.1 核

Conda与Python venv虚拟环境的区别与使用方法详解

《Conda与Pythonvenv虚拟环境的区别与使用方法详解》随着Python社区的成长,虚拟环境的概念和技术也在不断发展,:本文主要介绍Conda与Pythonvenv虚拟环境的区别与使用... 目录前言一、Conda 与 python venv 的核心区别1. Conda 的特点2. Python v