Author: 瑯琊土肥圓
E-mail: wt_lor@163.com
Date: 2018-09-21
上回書(shū)說(shuō)道窝剖,如何讀取PCD文件攻锰,本回則來(lái)講講如何將一個(gè)PointCloud結(jié)構(gòu)寫(xiě)入pcd文件。閑言少敘吃衅,先上代碼,然后一點(diǎn)點(diǎn)的講解。代碼如下阴挣。
/* pcd_write.cpp */
#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
int main(int argc, char **argv)
{
pcl::PointCloud<pcl::PointXYZ> cloud; // This point cloud should be filled with points.
pcl::PCDWriter writer
writer.write<pcl::PointXYZ>("filename.pcd", cloud);
return 0;
}
關(guān)于點(diǎn)云點(diǎn)類(lèi)型的問(wèn)題,此處不再贅述纺腊,可以查閱上篇文章畔咧,或者到pcl的官網(wǎng)查閱相關(guān)文檔茎芭。
不同于讀取PCD文件,在寫(xiě)入PCD文件時(shí)誓沸,主要使用了如下兩行代碼梅桩。
pcl::PCDWriter writer;
writer.write<pcl::PointXYZ>("filenamepcd", cloud);
在上一節(jié)的CMakeLists.txt文件中,添加如下兩行拜隧,用于添加編譯pcd_write.cpp的內(nèi)容宿百。
add_executable(pcd_writer ./pcd_write.cpp)
target_link_libraries(pcd_writer ${PCL_LIBRARIES})
完整的CMakeLists.txt文件如下所示。
cmake_minimum_required(VERSION 3.0)
project(pcd_read)
find_package(
PCL 1.2 REQUIRED
)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_executable(pcd_read ./pcd_read.cpp)
target_link_libraries(pcd_read ${PCL_LIBRARIES})
add_executable(pcd_write ./pcd_write.cpp)
target_link_libraries(pcd_write ${PCL_LIBRARIES})