




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、在ROS系統中使用PCL教程在ROS中點云的數據類型在ROS中表示點云的數據結構有:sensor_msgs:PointCloudsensor_msgs:PointCloud2pcl:PointCloud<T>關于PCL在ros的數據的結構,具體的介紹可查 看 /pcl/Overview關于 sensor_msgs:PointCloud2和 pcl:PointCloud<T> 之間的轉換使用 pcl:fromROSMsg 和 pcl:toROSMsgsensor_msgs:PointCloud和 sensor_msgs:PointCloud2之間的
2、轉1換使用 sensor_msgs:convertPointCloud2ToPointCloud和sensor_msgs:convertPointCloudToPointCloud2.那么女而在ROS中使用PCL呢?(1)在建立的包下的 CMakeLists.txt文件下添加依賴項find_.package(catkin REQUIRE。COMPONENTSroscpprospystdnsgssen50r_msgs匚v_btdgctnage_transportpcl_converston£ pcT_ros在package.xml 文件里添加:<build_depend>l
3、ibpcl-all-dev</build_depend><run_depend>libpcl-all</run_depend>在src文件夾下新建.cpp文件#include<ros/ros.h>/ PCL specific includes#include <sensor_msgs/PointCloud2.h>#include <pcl_conversions/pcl_conversions.h>#include <pcl/point_cloud.h>#include <pcl/point_types.
4、h>ros:Publisher pub; void cloud_cb ( const sensor_msgs:PointCloud2ConstPtr& input) / Create a container for the data.sensor_msgs:PointCloud2 output;/ Do data processing here.output = *input;/ Publish the data.pub.publish (output);int main ( int argc, char* argv) / Initialize ROSros:init (argc
5、, argv, "my_pcl_tutorial" );ros:NodeHandle nh;ros:Subscriber sub = nh.subscribe ( "input" , 1, cloud_cb);pub = nh.advertise<sensor_msgs:PointCloud2> ( "output" , 1); / Spin ros:spin ();在 CMakeLists.txt文件中添加:add_executable(example src/example.cpp)target_link_librar
6、ies(example $catkin_LIBRARIES)catkin_make之后成后執行文作,運行以下命令roslaunch openni_launch openni.launchrosrun ros_slam example input:=/camera/depth/points這是打開kinect發布的命令運行我們生成的文件運行RVIZ可視化以下,添加了程序發布的點云的話題既可以顯示。同時也 可以使用PCL自帶的顯示的函數可視化(這里不再一一贅述)$ rosrun rviz rviz在RVIZ中顯示的點云的數據格式sensor_msgs:PointCloud2;那么如果我們想實現對獲
7、取的點云的數據的濾波的處理,這里就是進行一個簡單的體素網格采樣的實驗同樣在src文件夾下新建.cpp文件,然后我們的程序如下。也就是要在回調 函數中實現對獲取的點云的濾波的處理,但是我們要特別注意每個程序中的點云的數據格式以及我們是如何使用函數實現對 程序如下/* 關于使用 sensor_msgs/PointCloud2 ,*/ROS與PCL的轉化的。#include<ros/ros.h>/ PCL的相關的頭文件#include <sensor_msgs/PointCloud2.h>#include <pcl_conversions/pcl_conversions
8、.h>#include <pcl/point_cloud.h>#include <pcl/point_types.h>#include <pcl/filters/voxel_grid.h>濾波的頭文件申明發布器ros:Publisher pub;回調函數void cloud_cb ( const sensor_msgs:PointCloud2ConstPtr& input)特別注意的是這里面形參的數據格A /聲明存儲原始數據與濾波后的數據的點云的格式pcl:PCLPointCloud2* cloud = new pcl:PCLPointClou
9、d2; 式 pcl:PCLPointCloud2ConstPtr cloudPtr(cloud);原始的點云的數據格pcl:PCLPointCloud2 cloud_filtered;/轉化為PCL中的點云的數據格式pcl_conversions:toPCL(*input, *cloud);pcl:VoxelGrid<pcl:PCLPointCloud2> sor;存儲濾波后的數據格式/進行一個濾波處理實例化濾波sor.setInputCloud (cloudPtr);設置輸入的濾波sor.setLeafSize ( 0.1 , 0.1 , 0.1); 設置體素網格的大小sor.f
10、ilter (cloud_filtered);存儲濾波后的點云/再將濾波后的點云的數據格式轉換為ROS下的數據格式發布出去sensor_msgs:PointCloud2 output;聲明的輸出的點云的格式pcl_conversions:fromPCL(cloud_filtered, output);/發布命令pub.publish (output);第一個參數是輸入,后面的是輸出int main ( int argc, char* argv) /初始化ROS節點ros:init (argc, argv, "my_pcl_tutorial" );ros:NodeHandle
11、 nh; 聲明節點的名稱/為接受點云數據創建一個訂閱節點ros:Subscriber sub = nh.subscribe ( "input" , 1, cloud_cb); /創建 ROS 的發布節點pub = nh.advertise<sensor_msgs:PointCloud2> ( "output" , 1); / 回調 ros:spin ();一看一下結果如圖,這是在 RVIZ中顯示的結果,當然也可以使用 PCL庫實現可視化(注意我們在rviz中顯示的點云的數據格式都是這是PCL點云庫中定義的一種的數據格式,在sensor_msg
12、s:PointCloud2 要區別 pcl:PCLPointCloud2RVIZ中不可顯示,)的舉例應用關于使用 pcl/PointCloud<T>定義的一種數據格式這里面使用了兩次數據轉換從這一類型的數據格式是PCL庫中sensor_msgs/PointCloud2 pcl:ModelCoefficientspcl/PointCloud<T>pcl_msgs:ModelCoefficients.代碼#include <ros/ros.h>/ PCL specific includes#include <sensor_msgs/PointCloud2.
13、h>#include <pcl_conversions/pcl_conversions.h>#include <pcl/ros/conversions.h>#include <pcl/point_cloud.h>#include <pcl/point_types.h>關于平面分割的頭文件#include<pcl/sample_consensus/model_types.h>/分割模型白拉文件一#include <pcl/sample_consensus/method_types.h> 采樣致性的方法#include
14、<pcl/segmentation/sac_segmentation.h> /ransac 分割法ros:Publisher pub; void cloud_cb ( const sensor_msgs:PointCloud2ConstPtr& input)一一/ 將點云格式為sensor_msgs/PointCloud2格式轉為 pcl/PointCloudpcl:PointCloud<pcl:PointXYZ> cloud;pcl:fromROSMsg (*input, cloud);關鍵的一句數據的轉換pcl:ModelCoefficients coeff
15、icients; / 申明模型的參數pcl:PointIndices inliers;/申明存儲模型的內點的索引/創建一個分割方法pcl:SACSegmentation<pcl:PointXYZ> seg; /這一句可以選擇最優化參數的因子seg.setOptimizeCoefficients ( true ); /以下都是強制性的需要設置的seg.setModelType (pcl:SACMODEL_PLANE);平面模型seg.setMethodType (pcl:SAC_RANSAC);分割平面模型所使用的分割方法seg.setDistanceThreshold ( 0.01
16、);設置最小的閥值距離seg.setInputCloud (cloud.makeShared ();設置輸入的點云seg.segment (inliers, coefficients);/cloud.makeShared() 創建個 boost shared_ptr/把提取出來的內點形成的平面模型的參數發布出去pcl_msgs:ModelCoefficients ros_coefficients;pcl_conversions:fromPCL(coefficients, ros_coefficients);pub.publish (ros_coefficients);一int main ( i
17、nt argc, char* argv) / Initialize ROSros:init (argc, argv, "my_pcl_tutorial" );ros:NodeHandle nh;/ Create a ROS subscriber for the input point cloudros:Subscriber sub = nh.subscribe ( "input" , 1, cloud_cb);/ Create a ROS publisher for the output model coefficientspub = nh.advert
18、ise<pcl_msgs:ModelCoefficients> ( "output" , 1);/ Spin ros:spin ();提取點云中平面的參數并且發布出去PCL對ROS的接口的總結比如:pcl:toROSMsg(*cloud,output);實現的功能是將pcl里面的 pcl:PointCloud<pcl:PointXYZ> cloud轉換成ros里面的sensor_msgs:PointCloud2 output這個類型。PCL對ROS的接口提供 PCL數據結構的轉換,通過通過ROS提供的以消息為基礎的轉換系統系統。這有一系列的轉換函數提
19、供用來轉換原始的PCL數據類型成消息型。一些最有用常用的的 message 類型列舉在下面。std_msgs : Header: 這不是真的消息類型,但是用在 Ros消息里面的每一個部分。它包 含了消息被發送的時間和序列號和框名。PCL等于pcl:Header 類型sensor_msgs:PointCloud2:這是最重要的類型。這個消息通常是用來轉換pcl:PointCloud 類型的,pcl:PCLPointCloud2這個類型也很重要,因為前面版本的可能被廢除。 pcl_msgs:PointIndices:這個類型存儲屬于點云里面的點的下標,在 pcl里面等1pcl:PointIndic
20、es pcl_msgs:PolygonMesh這個類型包括消息需要描述多邊形網眼,就是頂點和邊,在pcl 里面等于 pcl:PolygonMesh pcl_msgs:Vertices :這個類型包含了一系列的頂點作為一個數組的下標,來描述一個 多邊形。在 pcl里面等于 pcl:Vertices pcl_msgs:ModelCoefficients:這存儲了一個模型的不同的系數,比如描述一個平面需要4個系數。在 PCL里面等于 pcl:ModelCoefficients 上面的數據可以從PCL轉成ROS里面的PCL。所有的函數有一個類似的特征,意味著一旦我們知道這樣去轉換一個類型,我們就能學會
21、轉換其他的類型。下面的函數是在 pcl_conversions命名空間里面提供的函數下面的函數是在pcl_conversions 命名空間里面提供的函數voidcopyImageMetaData (const sensor_msgs:Image &image, pcl:PCLImage &pcl_image)voidcopyPCLImageMetaData (const pcl:PCLImage &pcl_image, sensor_msgs:Image &image)voidcopyPCLPointCloud2MetaData (const pcl:PCLPo
22、intCloud2 &pcl_pc2, sensor_msgs:PointCloud2 &pc2)voidcopyPointCloud2MetaData (const sensor_msgs:PointCloud2 &pc2, pcl:PCLPointCloud2 &pcl_pc2)voidfromPCL (const pcl:PCLImage &pcl_image, sensor_msgs:Image &image)voidfromPCL (const std:vector< pcl:PCLPointField > &pcl
23、_pfs, std:vector< sensor_msgs:PointField > &pf s)voidfromPCL (const pcl:PCLPointCloud2 &pcl_pc2, sensor_msgs:PointCloud2 &pc2)voidmoveFromPCL (pcl:PCLImage &pcl_image, sensor_msgs:Image &image)voidmoveFromPCL (pcl:PCLPointCloud2 &pcl_pc2, sensor_msgs:PointCloud2 &pc
24、2)voidmoveToPCL (sensor_msgs:Image &image, pcl:PCLImage &pcl_image)voidmoveToPCL (sensor_msgs:PointCloud2 &pc2, pcl:PCLPointCloud2 &pcl_pc2)voidmoveToPCL (pcl_msgs:ModelCoefficients &mc, pcl:ModelCoefficients &pcl_mc)voidtoPCL (const sensor_msgs:Image &image, pcl:PCLImage
25、 &pcl_image)voidtoPCL (const sensor_msgs:PointCloud2 &pc2, pcl:PCLPointCloud2 &pcl_pc2)總結出來就是void fromPCL (const <PCL Type> &, <ROS Message type> &);void moveFromPCL (<PCL Type> &, <ROS Message type> &);void toPCL (const <ROS Message type> &a
26、mp;, <PCL Type> &);void moveToPCL (<ROS Message type> &, <PCL Type> &);PCL類型必須被替換成先前指定的PCL類型和ROS里面相應的類型。sensor_msgs:PointCloud2有一個特定的函數集去執行轉換void toROSMsg (const pcl:PointCloud<T> &, sensor_msgs:PointCloud2 &);轉換為ROS 的點云 sensor_msgs:PointCloud2 類型void from
27、ROSMsg (const sensor_msgs:PointCloud2 &, pcl:PointCloud<T>&);轉為 PCL中的 pcl:PointCloud<T> 類型void moveFromROSMsg (sensor_msgs:PointCloud2 &, pcl:PointCloud<T> &);轉換為pcl:PointCloud<T> 類型記錄關于我們運行roslaunch openni_launch openni.launch命令時生成的話題以及這些話題的數據類型便于后期而處理,只有知道它們
28、的數據結構,才能很好的對數據進行處理,我們觀察到使用rostopic list的所有話題的列表當然其中也有一些不經常使用的話題類型,比如下面這些話題是我們經常使用 的/camera/depth/image/camera/depth/image_raw/camera/depth/points/camera/ir/image_raw/camera/rgb/image_c010r/camera/rgb/image_raw發布的話題:image_raw (sensor_msgs/Image) :未處理的原始圖像使用命令查看 sensor_msgs/Image 的數據rosmsg how sen&
29、;or msgs/Image stdmsgs/Header headerutnt32 seqtime stampstring frane_idjtnt32 heightjtnt32 widthstring encoding jintS is_bigendtanJtnt32 5t叩jintsf1 datacamera_info (sensor_msgs/CameraInfo) :包含了相機標定配置以及相關數 據alngsaln: -$ rosnsg show sensor_Pisgs/CameraInfo td_msgs/Header headerutnt32 seqtime stampstri
30、ng frane_idtnt32 heightint32 widthtrtng distortion_Ddelloat64 DX&at64?) KLoat649 Rloat5412 Ptnt32 btnntngxint32 btnntng_yen£or_Fisgs/RegionOfInterest rotuint32 x_offsetutnt32 offsetuint32 heightLnt32 width bool direct!fy介紹幾個ROS節點運行的幾種工具。他們的作用是ROS&式點云或包與點云數據(PCD文件格式之間的相互轉換。(1) bag_to_pcd
31、用法:rosrun pcl_ros bag_to_pcd <input_file.bag> <topic><output_directory>讀取一個包文件,保存所有ROS點云消息在指定的 PCD文件中。(2) convert_pcd_to_image用法:rosrun pcl_ros convert_pcd_to_image <cloud.pcd>加載一個PCD文作,將其作句ROS圖像消息每秒中發布五次。(3) convert_pointcloud_to_image用法:rosrun pcl_ros convert_pointcloud_to_
32、image input:二/my_cloudoutput:二/my_image查看圖像: rosrun image_view image_view image:二/my_image訂閱一個ROS的點云的話題并以圖像的信息發布出去。(4) pcd_to_pointcloud用法:rosrun pcl_ros pcd_to_pointcloud <file.pcd> <interval> ? <file.pcd> is the (required) file name to read.? <interval> is the (optional) nu
33、mber of seconds to sleep between messages. If <interval> is zero or not specified the message is published once.加載一個PCD文件,發布一次或多次作為ROS點云消息(5) pointcloud_to_pcd例如: rosrun pcl_ros pointcloud_to_pcdinput:二/velodyne/pointcloud2訂閱一個ROS的話題和保存為點云PCD文件。每個消息被保存到一個單獨的文件,名稱是由一個可自定義的前綴參數,ROS寸間的消息,和以 PCD擴展
34、的文件。那么我們使用一個簡單的例子來實現在ROS中進行平面的分割,同時注意到使用的數據轉換的使用/*關于使用 pcl/PointCloud<T>的舉例應用。這一類型的數據格式是定義的種數據格式這里面使用了兩次數據轉換從 sensor_msgs/PointCloud2PCL庫中到到 pcl_msgs:ModelCoefficients.pcl/PointCloud<T> 和 從 pcl:ModelCoefficients*/ #include <iostream> /ROS#include <ros/ros.h>/ PCL specific inc
35、ludes#include <sensor_msgs/PointCloud2.h>#include <pcl_conversions/pcl_conversions.h>#include <pcl/ros/conversions.h>#include <pcl/point_cloud.h>#include <pcl/point_types.h>#include <pcl/io/pcd_io.h>分割模型的頭文件采樣一致性的方法/ransac分割法關于平面分割的頭受件#include <pcl/sample_conse
36、nsus/model_types.h>#include <pcl/sample_consensus/method_types.h>#include <pcl/segmentation/sac_segmentation.h> ros:Publisher pub; void cloud_cb ( const sensor_msgs:PointCloud2ConstPtr& input)一一/ 將點云格式為sensor_msgs/PointCloud2 格式轉為 pcl/PointCloudpcl:PointCloud<pcl:PointXYZ> cloud;pcl:fromROSMsg (*input, cloud);關鍵的一句數據的轉換pcl:ModelCoefficients coefficients;/ 申明模型的參數pcl:PointIndices i
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025至2030掛燙機行業風險投資態勢及投融資策略指引報告
- 2025至2030平板拖車行業發展趨勢分析與未來投資戰略咨詢研究報告
- 2025年工業互聯網平臺生物識別技術在智能工廠生產設備狀態監控中的應用研究報告
- 江西楓林涉外經貿職業學院《大學生就業指導實務》2023-2024學年第一學期期末試卷
- 浙江郵電職業技術學院《城市建設與工程地質》2023-2024學年第一學期期末試卷
- 電工技師試題及答案
- 電大基礎會計試題及答案
- 吉林鐵道職業技術學院《玩教具制作》2023-2024學年第一學期期末試卷
- 道路安全法試題及答案
- 黨校考試試題及答案數學
- 譯林版(2024)七年級下冊英語期末復習:完形填空+閱讀理解 練習題(含答案)
- 第5章 相交線與平行線 復習課件
- 廣東省廣州各區2025屆七下英語期末經典試題含答案
- 企業科技論文管理制度
- 山東卷2025年高考歷史真題
- 2025-2030年中國蝦苗行業市場現狀供需分析及投資評估規劃分析研究報告
- 肺曲霉菌病治療講課件
- 頂端分生組織穩態調控-洞察闡釋
- 2025年農業經濟學考試試題及答案
- 2025至2030年中國硫化橡膠制避孕套行業供需態勢分析及投資機會分析報告
- 2025-2030年“一帶一路”背景下甘肅省區域經濟發展分析及投資前景報告
評論
0/150
提交評論