3d激光雷达开发(旋转和位移)
【 声明:版权所有,欢迎转载,请勿用于商业用途。 联系信箱:feixiaoxing @163.com】
对于点云数据来说,旋转和位移的计算是十分必要的。比如数据匹配、识别、定位,如果需要查看获得的旋转矩阵对不对,那么就可以将原来的数据和旋转矩阵做一个乘积,这样就可以立刻看到对应的效果了。
1、准备transform.cpp文件
#include <iostream>#include <pcl/io/pcd_io.h>
#include <pcl/io/ply_io.h>
#include <pcl/point_cloud.h>
#include <pcl/console/parse.h>
#include <pcl/common/transforms.h>
#include <pcl/visualization/pcl_visualizer.h>// This function displays the help
void
showHelp(char * program_name)
{std::cout << std::endl;std::cout << "Usage: " << program_name << " cloud_filename.[pcd|ply]" << std::endl;std::cout << "-h: Show this help." << std::endl;
}// This is the main function
int
main (int argc, char** argv)
{// Show helpif (pcl::console::find_switch (argc, argv, "-h") || pcl::console::find_switch (argc, argv, "--help")) {showHelp (argv[0]);return 0;}// Fetch point cloud filename in arguments | Works with PCD and PLY filesstd::vector<int> filenames;bool file_is_pcd = false;filenames = pcl::console::parse_file_extension_argument (argc, argv, ".ply");if (filenames.size () != 1) {filenames = pcl::console::parse_file_extension_argument (argc, argv, ".pcd");if (filenames.size () != 1) {showHelp (argv[0]);return -1;} else {file_is_pcd = true;}}// Load file | Works with PCD and PLY filespcl::PointCloud<pcl::PointXYZ>::Ptr source_cloud (new pcl::PointCloud<pcl::PointXYZ> ());if (file_is_pcd) {if (pcl::io::loadPCDFile (argv[filenames[0]], *source_cloud) < 0) {std::cout << "Error loading point cloud " << argv[filenames[0]] << std::endl << std::endl;showHelp (argv[0]);return -1;}} else {if (pcl::io::loadPLYFile (argv[filenames[0]], *source_cloud) < 0) {std::cout << "Error loading point cloud " << argv[filenames[0]] << std::endl << std::endl;showHelp (argv[0]);return -1;}}/* Reminder: how transformation matrices work :|-------> This column is the translation| 1 0 0 x | \| 0 1 0 y | }-> The identity 3x3 matrix (no rotation) on the left| 0 0 1 z | /| 0 0 0 1 | -> We do not use this line (and it has to stay 0,0,0,1)METHOD #1: Using a Matrix4fThis is the "manual" method, perfect to understand but error prone !*/Eigen::Matrix4f transform_1 = Eigen::Matrix4f::Identity();// Define a rotation matrix (see https://en.wikipedia.org/wiki/Rotation_matrix)float theta = M_PI/4; // The angle of rotation in radianstransform_1 (0,0) = std::cos (theta);transform_1 (0,1) = -sin(theta);transform_1 (1,0) = sin (theta);transform_1 (1,1) = std::cos (theta);// (row, column)// Define a translation of 2.5 meters on the x axis.transform_1 (0,3) = 2.5;// Print the transformationprintf ("Method #1: using a Matrix4f\n");std::cout << transform_1 << std::endl;/* METHOD #2: Using a Affine3fThis method is easier and less error prone*/Eigen::Affine3f transform_2 = Eigen::Affine3f::Identity();// Define a translation of 2.5 meters on the x axis.transform_2.translation() << 2.5, 0.0, 0.0;// The same rotation matrix as before; theta radians around Z axistransform_2.rotate (Eigen::AngleAxisf (theta, Eigen::Vector3f::UnitZ()));// Print the transformationprintf ("\nMethod #2: using an Affine3f\n");std::cout << transform_2.matrix() << std::endl;// Executing the transformationpcl::PointCloud<pcl::PointXYZ>::Ptr transformed_cloud (new pcl::PointCloud<pcl::PointXYZ> ());// You can either apply transform_1 or transform_2; they are the samepcl::transformPointCloud (*source_cloud, *transformed_cloud, transform_2);// Visualizationprintf( "\nPoint cloud colors : white = original point cloud\n"" red = transformed point cloud\n");pcl::visualization::PCLVisualizer viewer ("Matrix transformation example");// Define R,G,B colors for the point cloudpcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> source_cloud_color_handler (source_cloud, 255, 255, 255);// We add the point cloud to the viewer and pass the color handlerviewer.addPointCloud (source_cloud, source_cloud_color_handler, "original_cloud");pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> transformed_cloud_color_handler (transformed_cloud, 230, 20, 20); // Redviewer.addPointCloud (transformed_cloud, transformed_cloud_color_handler, "transformed_cloud");viewer.addCoordinateSystem (1.0, "cloud", 0);viewer.setBackgroundColor(0.05, 0.05, 0.05, 0); // Setting background to a dark greyviewer.setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 2, "original_cloud");viewer.setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 2, "transformed_cloud");//viewer.setPosition(800, 400); // Setting visualiser window positionwhile (!viewer.wasStopped ()) { // Display the visualiser until 'q' key is pressedviewer.spinOnce ();}return 0;
}
2、代码说明
代码里面主要说明了两种构建旋转矩阵的方法。不管是哪一种,本质上都是要把yaw、pitch、roll、x、y、z通过计算映射到矩阵里面。
3、准备CMakeLists.txt
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)project(transform)find_package(PCL 1.2 REQUIRED)include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})add_executable (transform transform.cpp)
target_link_libraries (transform ${PCL_LIBRARIES})
4、开始生成sln工程,准备编译,
5、执行transform.exe
执行过程中,注意输入参数,即transform.exe bunny.pcd。
另外,代码中应该是对点云数据x轴偏移2.5米,z轴旋转theta角度,工作台的打印如下,
实际效果如下,
3d激光雷达开发(旋转和位移)相关推荐
- 3d激光雷达开发(入门)
[ 声明:版权所有,欢迎转载,请勿用于商业用途. 联系信箱:feixiaoxing @163.com] 大约在2017年的时候,学习百度的apollo系统的时候,就知道3d激光雷达了.3d激光雷达和普 ...
- 3d激光雷达开发(pcl安装和使用)
[ 声明:版权所有,欢迎转载,请勿用于商业用途. 联系信箱:feixiaoxing @163.com] 之前讨论过,目前3d激光雷达这块,算法部分用的最多的就是pcl库.网上很多教程都是讲pcl在li ...
- 3d激光雷达开发(从halcon看点云pcl库)
[ 声明:版权所有,欢迎转载,请勿用于商业用途. 联系信箱:feixiaoxing @163.com] 做点云开发的,很少有不知道pcl库的,这一点就有点像做数字图像处理的,很少有不知道opencv的 ...
- 3d激光雷达开发(多雷达标定)
[ 声明:版权所有,欢迎转载,请勿用于商业用途. 联系信箱:feixiaoxing @163.com] 有过camera开发经验的朋友都知道,camera有两种标定.一种是内参标定,主要是标定切向畸变 ...
- 3d激光雷达开发(平面映射)
[ 声明:版权所有,欢迎转载,请勿用于商业用途. 联系信箱:feixiaoxing @163.com] 3d点云当中,一个经常用到的方法就是先找到一个平面,然后将点映射到平面上面.这个里面用到的数据结 ...
- 3d激光雷达开发(绘制长方体)
[ 声明:版权所有,欢迎转载,请勿用于商业用途. 联系信箱:feixiaoxing @163.com] 不管是测量,或者是识别,一般在算法执行的过程当中,都要把相关得物体锁定出来,这个时候,绘制一个长 ...
- 3d激光雷达开发(ndt匹配)
[ 声明:版权所有,欢迎转载,请勿用于商业用途. 联系信箱:feixiaoxing @163.com] 除了icp匹配之外,ndt匹配也是使用比较多的一种方法.相比较icp而言,ndt匹配花的时间要少 ...
- 3d激光雷达开发(icp匹配)
[ 声明:版权所有,欢迎转载,请勿用于商业用途. 联系信箱:feixiaoxing @163.com] 所谓匹配,其实就是看两个点云数据里面,哪些关键点是一样的.这样就可以把一个点云移动到另外合适的位 ...
- 3d激光雷达开发(法向量预测)
[ 声明:版权所有,欢迎转载,请勿用于商业用途. 联系信箱:feixiaoxing @163.com] 法向量在3d点云当中扮演很重要的一个角色.一个三维数据点的特征,不仅和它自己有关,还和它周围的点 ...
最新文章
- hvie struct 怎么查训_hive的数据类型
- 多线程之:用户态和内核态的区别
- 抢滩“体验经济”,“真快乐”布局娱乐化零售的野心
- React Hook “useState“ is called in function xx which is neither a React function component or
- lmbs PHP,PHP 清空 MySql 指定数据表中的所有数据
- 【机器学习】sklearn k-近邻算法
- ATP-EMTP谁懂啊,急!!
- java 离线版语音转文字
- [2020-07]如何获取百度访客搜索关键字(竞价、推广、SEO)
- DDD原著 -- 第一章 知识消化
- The transaction timeout is larger than the maximum value allowed by the broker
- relative的使用
- git:历史版本回滚、重新回到最新版本及取消修改内容
- poco c++感性认识
- php获取实时汇率,php获取sinajs股票/汇率/期货实时价格
- debian下切换内核
- python图片换脸_用Python实现简单的‘换脸’
- MySQL连接查询练习
- prism 创建ViewModel
- 2014年11月3日至2014年12月29日