对应点已知时最优变换求解介绍以及SVD代码示例

2024-02-14 05:44

本文主要是介绍对应点已知时最优变换求解介绍以及SVD代码示例,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

一、空间上两组点希望找到一个刚性变换,在最小二乘的意义上最优地对齐两个点集,就是说找到一个旋转矩阵R和一个平移向量t。 

二、SVD代码示例

C++代码

#include <iostream>
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <pcl/io/pcd_io.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <pcl/common/transforms.h>
#include <pcl/registration/transformation_estimation_svd.h>using namespace Eigen;
using namespace std;int main(int argc, char** argv) {pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_in(new pcl::PointCloud<pcl::PointXYZ>());pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_out(new pcl::PointCloud<pcl::PointXYZ>());cloud_in->width = 3;cloud_in->height = 1;cloud_in->is_dense = false;cloud_in->resize(cloud_in->width * cloud_in->height);cloud_out->width = 3;cloud_out->height = 1;cloud_out->is_dense = false;cloud_out->resize(cloud_out->width * cloud_out->height);for (size_t i = 0; i < cloud_in->points.size(); i++){// RAND_MAX = 2^15 - 1cloud_in->points[i].x = 3.0f * rand() / (RAND_MAX + 1.0f);cloud_in->points[i].y = 3.0f * rand() / (RAND_MAX + 1.0f);cloud_in->points[i].z = 3.0f * rand() / (RAND_MAX + 1.0f);cout << cloud_in->points[i].x << "  \t" << cloud_in->points[i].y << "  \t" << cloud_in->points[i].z << endl;}Eigen::Affine3f transform = Eigen::Affine3f::Identity();transform.translation() << 1.0, 2.0, 3.0;float angle_x = 45 * M_PI / 180.0;float angle_y = 45 * M_PI / 180.0;float angle_z = 45 * M_PI / 180.0;transform.rotate(Eigen::AngleAxisf(angle_x, Eigen::Vector3f::UnitX()));transform.rotate(Eigen::AngleAxisf(angle_y, Eigen::Vector3f::UnitY()));transform.rotate(Eigen::AngleAxisf(angle_z, Eigen::Vector3f::UnitZ()));cout << "变换矩阵:\n" << transform.matrix() << endl;pcl::transformPointCloud(*cloud_in, *cloud_out, transform);//---------------------------------利用SVD方法求解变换矩阵--------------------------pcl::registration::TransformationEstimationSVD<pcl::PointXYZ, pcl::PointXYZ> TESVD;pcl::registration::TransformationEstimationSVD<pcl::PointXYZ, pcl::PointXYZ>::Matrix4 transformation2;TESVD.estimateRigidTransformation(*cloud_in, *cloud_out, transformation2);// -----------------------------------输出变换矩阵信息------------------------------cout << "The Estimated Rotation and translation matrices (using getTransformation function) are : \n" << endl;printf("\n");printf("    | %6.3f %6.3f %6.3f | \n", transformation2(0, 0), transformation2(0, 1), transformation2(0, 2));printf("R = | %6.3f %6.3f %6.3f | \n", transformation2(1, 0), transformation2(1, 1), transformation2(1, 2));printf("    | %6.3f %6.3f %6.3f | \n", transformation2(2, 0), transformation2(2, 1), transformation2(2, 2));printf("\n");printf("t = < %0.3f, %0.3f, %0.3f >\n", transformation2(0, 3), transformation2(1, 3), transformation2(2, 3));return 0;
}

 结果:

局部特征描述子-CSDN博客 

这篇关于对应点已知时最优变换求解介绍以及SVD代码示例的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



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

相关文章

前端CSS Grid 布局示例详解

《前端CSSGrid布局示例详解》CSSGrid是一种二维布局系统,可以同时控制行和列,相比Flex(一维布局),更适合用在整体页面布局或复杂模块结构中,:本文主要介绍前端CSSGri... 目录css Grid 布局详解(通俗易懂版)一、概述二、基础概念三、创建 Grid 容器四、定义网格行和列五、设置行

Node.js 数据库 CRUD 项目示例详解(完美解决方案)

《Node.js数据库CRUD项目示例详解(完美解决方案)》:本文主要介绍Node.js数据库CRUD项目示例详解(完美解决方案),本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考... 目录项目结构1. 初始化项目2. 配置数据库连接 (config/db.js)3. 创建模型 (models/

使用Python实现全能手机虚拟键盘的示例代码

《使用Python实现全能手机虚拟键盘的示例代码》在数字化办公时代,你是否遇到过这样的场景:会议室投影电脑突然键盘失灵、躺在沙发上想远程控制书房电脑、或者需要给长辈远程协助操作?今天我要分享的Pyth... 目录一、项目概述:不止于键盘的远程控制方案1.1 创新价值1.2 技术栈全景二、需求实现步骤一、需求

Spring LDAP目录服务的使用示例

《SpringLDAP目录服务的使用示例》本文主要介绍了SpringLDAP目录服务的使用示例... 目录引言一、Spring LDAP基础二、LdapTemplate详解三、LDAP对象映射四、基本LDAP操作4.1 查询操作4.2 添加操作4.3 修改操作4.4 删除操作五、认证与授权六、高级特性与最佳

Java中Date、LocalDate、LocalDateTime、LocalTime、时间戳之间的相互转换代码

《Java中Date、LocalDate、LocalDateTime、LocalTime、时间戳之间的相互转换代码》:本文主要介绍Java中日期时间转换的多种方法,包括将Date转换为LocalD... 目录一、Date转LocalDateTime二、Date转LocalDate三、LocalDateTim

Pytest多环境切换的常见方法介绍

《Pytest多环境切换的常见方法介绍》Pytest作为自动化测试的主力框架,如何实现本地、测试、预发、生产环境的灵活切换,本文总结了通过pytest框架实现自由环境切换的几种方法,大家可以根据需要进... 目录1.pytest-base-url2.hooks函数3.yml和fixture结论你是否也遇到过

jupyter代码块没有运行图标的解决方案

《jupyter代码块没有运行图标的解决方案》:本文主要介绍jupyter代码块没有运行图标的解决方案,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录jupyter代码块没有运行图标的解决1.找到Jupyter notebook的系统配置文件2.这时候一般会搜索到

Python通过模块化开发优化代码的技巧分享

《Python通过模块化开发优化代码的技巧分享》模块化开发就是把代码拆成一个个“零件”,该封装封装,该拆分拆分,下面小编就来和大家简单聊聊python如何用模块化开发进行代码优化吧... 目录什么是模块化开发如何拆分代码改进版:拆分成模块让模块更强大:使用 __init__.py你一定会遇到的问题模www.

CSS will-change 属性示例详解

《CSSwill-change属性示例详解》will-change是一个CSS属性,用于告诉浏览器某个元素在未来可能会发生哪些变化,本文给大家介绍CSSwill-change属性详解,感... will-change 是一个 css 属性,用于告诉浏览器某个元素在未来可能会发生哪些变化。这可以帮助浏览器优化

C++变换迭代器使用方法小结

《C++变换迭代器使用方法小结》本文主要介绍了C++变换迭代器使用方法小结,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧... 目录1、源码2、代码解析代码解析:transform_iterator1. transform_iterat