博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PCL 三维点云轮廓提取
阅读量:4167 次
发布时间:2019-05-26

本文共 3114 字,大约阅读时间需要 10 分钟。

PCL 三维点云轮廓提取

建一个pclfive文件夹,建一个pclfive.cpp文档如下:

#include 
#include
//深度图有关文件#include
//点云可视化头文件#include
//pcd文件输入/输出#include
//rangeImage可视化头文件#include
#include
//命令行参数解析#include
//多线程文件#include
//保存深度图像#include
//保存深度图像 int main (int argc, char** argv) { //读入点云数据 // pcl::PointCloud
::Ptr cloud_in(new pcl::PointCloud
); // pcl::io::loadPCDFile("room_scan1.pcd",*cloud_in); pcl::PointCloud
::Ptr cloud_in(new pcl::PointCloud
); //生成数据 for (float y=-0.5f; y<=0.5f; y+=0.01f) { for (float z=-0.5f; z<=0.5f; z+=0.01f) { pcl::PointXYZ point; point.x = 2.0f - y; point.y = y; point.z = z; cloud_in->points.push_back(point); } } cloud_in->width = (uint32_t) cloud_in->points.size(); cloud_in->height = 1; //以1度为角分辨率,从上面创建的点云创建深度图像。 float angularResolution = (float) ( 1.0f * (M_PI/180.0f)); // 1度转弧度 float maxAngleWidth = (float) (360.0f * (M_PI/180.0f)); // 360.0度转弧度 float maxAngleHeight = (float) (180.0f * (M_PI/180.0f)); // 180.0度转弧度 Eigen::Affine3f sensorPose = (Eigen::Affine3f)Eigen::Translation3f(0.0f, 0.0f, 0.0f); pcl::RangeImage::CoordinateFrame coordinate_frame = pcl::RangeImage::CAMERA_FRAME; float noiseLevel=0.00; float minRange = 0.0f; int borderSize = 1; pcl::RangeImage rangeImage; rangeImage.createFromPointCloud(*cloud_in, angularResolution, maxAngleWidth, maxAngleHeight, sensorPose, coordinate_frame, noiseLevel, minRange, borderSize);std::cout << rangeImage << "\n";//重载运算符<< pcl::visualization::PCLVisualizer::Ptr viewer(new pcl::visualization::PCLVisualizer("CloudPointView"));viewer->initCameraParameters(); int v1(0);//viewer->createViewPort(0,0,0.5,1,v1);viewer->setBackgroundColor(255,255,255,v1);pcl::visualization::PointCloudColorHandlerCustom
color1(cloud_in->makeShared(),255,0,0);viewer->addPointCloud(cloud_in->makeShared(),color1,"pointCloud",v1); viewer->addCoordinateSystem();//viewer->spin();//这句话不注释掉会导致只显示点云图而不显示深度图的窗口 //save depth picture float *ranges = rangeImage.getRangesArray(); unsigned char* rgb_image = pcl::visualization::FloatImageUtils::getVisualImage(ranges,rangeImage.width,rangeImage.height); pcl::io::saveRgbPNGFile("saveRangeImageRGB.png",rgb_image,rangeImage.width,rangeImage.height); std::cerr << "Picture Saved!" << std::endl; //可视化深度图像rangeImagepcl::visualization::RangeImageVisualizer range_image_widget("Range image");//创建Range image显示的对象range_image_widget.setWindowTitle("RangeImage");range_image_widget.showRangeImage(rangeImage); while (!range_image_widget.wasStopped ()&& !viewer->wasStopped()) { range_image_widget.spinOnce (); viewer->spinOnce(); pcl_sleep (0.01); } return 0 ;}

在同文件夹下写入配置文件:CMakeLists.txt,如下:

cmake_minimum_required(VERSION 2.6)project(pclfive) find_package(PCL 1.2 REQUIRED) include_directories(${
PCL_INCLUDE_DIRS})link_directories(${
PCL_LIBRARY_DIRS})add_definitions(${
PCL_DEFINITIONS}) add_executable(pclfive pclfive.cpp) target_link_libraries (pclfive ${
PCL_LIBRARIES}) install(TARGETS pclfive RUNTIME DESTINATION bin)

在同文件夹下建立build建一个build文件夹。

开始编译:
1、在build文件夹中打开终端(在文件夹下右键+T)
2、终端输入

cmake ..

3、终端输入

make

4、终端输入

./pclfive

转载地址:http://ujexi.baihongyu.com/

你可能感兴趣的文章
HTTP状态管理
查看>>
HTTP认证教程(四)
查看>>
HTTP客户端服务
查看>>
HTTPClient六 高级主题
查看>>
java 调用WebService服务接口
查看>>
Http Basic Authorizaition验证
查看>>
为自己三日来的懒惰忏悔
查看>>
Python3.2官方文档教程--其余参数形式
查看>>
Python3.2 官方文档教程---编码风格
查看>>
Python3.2 官方文档教程--列表
查看>>
Python3.2 官方文档教程---列表当做栈、队列和递推式列表
查看>>
乐队设备--功放的学习和使用
查看>>
乐队设备--反馈抑制器学习笔记
查看>>
构建RESTful Web Service - 验证的实现和使用(HTTP 基本认证)
查看>>
Python3.2官方文档教程--嵌套列表推导式和del关键字
查看>>
Python3.2官方文档教程---元组与序列
查看>>
有一种幸福,就是看着自己的博文阅读量不断上升, 感恩生命
查看>>
Python3.2官方文档教程---Set集合
查看>>
Python中global用法详解
查看>>
MySQL按年龄段查询
查看>>