VS配置PCL点云库的一些操作
解决方案配置选择Debug,解决方案平台选择x64。
1.配置属性—调试—环境—添加:
PATH=D:\PCL 1.11.0\\bin;D:\PCL 1.11.0\\3rdParty\FLANN\bin;D:\PCL 1.11.0\\3rdParty\VTK\bin;D:\PCL 1.11.0\\3rdParty\OpenNI2\Tools
2.C/C++—语言—符合模式:否
3.C/C++—常规—SDL检查:否
加一个测试程序:
#include <iostream> #include <vector> #include <ctime> #include <pcl/point_cloud.h> #include <pcl/octree/octree.h> #include <boost/thread/thread.hpp> #include <pcl/visualization/pcl_visualizer.h> using namespace std; int main(int argc, char** argv) { srand((unsigned int)time(NULL)); pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>); // 创建点云数据 cloud->width = 1000; cloud->height = 1; cloud->points.resize(cloud->width * cloud->height); for (size_t i = 0; i < cloud->points.size(); ++i) { cloud->points[i].x = 1024.0f * rand() / (RAND_MAX + 1.0f); cloud->points[i].y = 1024.0f * rand() / (RAND_MAX + 1.0f); cloud->points[i].z = 1024.0f * rand() / (RAND_MAX + 1.0f); } pcl::octree::OctreePointCloudSearch<pcl::PointXYZ> octree(0.1); octree.setInputCloud(cloud); octree.addPointsFromInputCloud(); pcl::PointXYZ searchPoint; searchPoint.x = 1024.0f * rand() / (RAND_MAX + 1.0f); searchPoint.y = 1024.0f * rand() / (RAND_MAX + 1.0f); searchPoint.z = 1024.0f * rand() / (RAND_MAX + 1.0f); //半径内近邻搜索 vector<int>pointIdxRadiusSearch; vector<float>pointRadiusSquaredDistance; float radius = 256.0f * rand() / (RAND_MAX + 1.0f); cout << "Neighbors within radius search at (" << searchPoint.x << " " << searchPoint.y << " " << searchPoint.z << ") with radius=" << radius << endl; if (octree.radiusSearch(searchPoint, radius, pointIdxRadiusSearch, pointRadiusSquaredDistance) > 0) { for (size_t i = 0; i < pointIdxRadiusSearch.size(); ++i) cout << " " << cloud->points[pointIdxRadiusSearch[i]].x << " " << cloud->points[pointIdxRadiusSearch[i]].y << " " << cloud->points[pointIdxRadiusSearch[i]].z << " (squared distance: " << pointRadiusSquaredDistance[i] << ")" << endl; } // 初始化点云可视化对象 boost::shared_ptr<pcl::visualization::PCLVisualizer>viewer(new pcl::visualization::PCLVisualizer("显示点云")); viewer->setBackgroundColor(0, 0, 0); //设置背景颜色为黑色 // 对点云着色可视化 (red). pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ>target_color(cloud, 255, 0, 0); viewer->addPointCloud<pcl::PointXYZ>(cloud, target_color, "target cloud"); viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "target cloud"); // 等待直到可视化窗口关闭 while (!viewer->wasStopped()) { viewer->spinOnce(100); boost::this_thread::sleep(boost::posix_time::microseconds(1000)); } return (0); }