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

相关文章

AI绘图怎么变现?想做点副业的小白必看!

在科技飞速发展的今天,AI绘图作为一种新兴技术,不仅改变了艺术创作的方式,也为创作者提供了多种变现途径。本文将详细探讨几种常见的AI绘图变现方式,帮助创作者更好地利用这一技术实现经济收益。 更多实操教程和AI绘画工具,可以扫描下方,免费获取 定制服务:个性化的创意商机 个性化定制 AI绘图技术能够根据用户需求生成个性化的头像、壁纸、插画等作品。例如,姓氏头像在电商平台上非常受欢迎,

中文分词jieba库的使用与实景应用(一)

知识星球:https://articles.zsxq.com/id_fxvgc803qmr2.html 目录 一.定义: 精确模式(默认模式): 全模式: 搜索引擎模式: paddle 模式(基于深度学习的分词模式): 二 自定义词典 三.文本解析   调整词出现的频率 四. 关键词提取 A. 基于TF-IDF算法的关键词提取 B. 基于TextRank算法的关键词提取

使用SecondaryNameNode恢复NameNode的数据

1)需求: NameNode进程挂了并且存储的数据也丢失了,如何恢复NameNode 此种方式恢复的数据可能存在小部分数据的丢失。 2)故障模拟 (1)kill -9 NameNode进程 [lytfly@hadoop102 current]$ kill -9 19886 (2)删除NameNode存储的数据(/opt/module/hadoop-3.1.4/data/tmp/dfs/na

Hadoop数据压缩使用介绍

一、压缩原则 (1)运算密集型的Job,少用压缩 (2)IO密集型的Job,多用压缩 二、压缩算法比较 三、压缩位置选择 四、压缩参数配置 1)为了支持多种压缩/解压缩算法,Hadoop引入了编码/解码器 2)要在Hadoop中启用压缩,可以配置如下参数

Makefile简明使用教程

文章目录 规则makefile文件的基本语法:加在命令前的特殊符号:.PHONY伪目标: Makefilev1 直观写法v2 加上中间过程v3 伪目标v4 变量 make 选项-f-n-C Make 是一种流行的构建工具,常用于将源代码转换成可执行文件或者其他形式的输出文件(如库文件、文档等)。Make 可以自动化地执行编译、链接等一系列操作。 规则 makefile文件

使用opencv优化图片(画面变清晰)

文章目录 需求影响照片清晰度的因素 实现降噪测试代码 锐化空间锐化Unsharp Masking频率域锐化对比测试 对比度增强常用算法对比测试 需求 对图像进行优化,使其看起来更清晰,同时保持尺寸不变,通常涉及到图像处理技术如锐化、降噪、对比度增强等 影响照片清晰度的因素 影响照片清晰度的因素有很多,主要可以从以下几个方面来分析 1. 拍摄设备 相机传感器:相机传

Open3D 基于法线的双边滤波

目录 一、概述 1.1原理 1.2实现步骤 1.3应用场景 二、代码实现 2.1关键函数 输入参数: 输出参数: 参数影响: 2.2完整代码 三、实现效果 3.1原始点云 3.2滤波后点云 Open3D点云算法汇总及实战案例汇总的目录地址: Open3D点云算法与点云深度学习案例汇总(长期更新)-CSDN博客 一、概述         基于法线的双边

pdfmake生成pdf的使用

实际项目中有时会有根据填写的表单数据或者其他格式的数据,将数据自动填充到pdf文件中根据固定模板生成pdf文件的需求 文章目录 利用pdfmake生成pdf文件1.下载安装pdfmake第三方包2.封装生成pdf文件的共用配置3.生成pdf文件的文件模板内容4.调用方法生成pdf 利用pdfmake生成pdf文件 1.下载安装pdfmake第三方包 npm i pdfma

零基础学习Redis(10) -- zset类型命令使用

zset是有序集合,内部除了存储元素外,还会存储一个score,存储在zset中的元素会按照score的大小升序排列,不同元素的score可以重复,score相同的元素会按照元素的字典序排列。 1. zset常用命令 1.1 zadd  zadd key [NX | XX] [GT | LT]   [CH] [INCR] score member [score member ...]

git使用的说明总结

Git使用说明 下载安装(下载地址) macOS: Git - Downloading macOS Windows: Git - Downloading Windows Linux/Unix: Git (git-scm.com) 创建新仓库 本地创建新仓库:创建新文件夹,进入文件夹目录,执行指令 git init ,用以创建新的git 克隆仓库 执行指令用以创建一个本地仓库的