PCL手記(貳)——PCD文件寫(xiě)入

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})
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容