[ubuntu][C++][qt]qt配置pcl并测试

测试环境:

qt5.12.9

ubuntu16.04

pcl为系统apt默认库

代码:

#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;
int main(int argc, char** argv)
{
    srand((unsigned int)time(NULL));
    pcl::PointCloud::Ptr cloud(new pcl::PointCloud);
    // 创建点云数据
    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 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);
    //半径内近邻搜索
    vectorpointIdxRadiusSearch;
    vectorpointRadiusSquaredDistance;
    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_ptrviewer(new pcl::visualization::PCLVisualizer("pcl cloud point"));
    viewer->setBackgroundColor(0, 0, 0); //设置背景颜色为黑色
    // 对点云着色可视化 (red).
    pcl::visualization::PointCloudColorHandlerCustomtarget_color(cloud, 255, 0, 0);
    viewer->addPointCloud(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);
}

pro配置:

DEPATH += /usr/include/eigen3

INCLUDEPATH += /usr/include/vtk-6.2

LIBS += /usr/lib/x86_64-linux-gnu/libvtk*.so



INCLUDEPATH += /usr/include/boost

LIBS += /usr/lib/x86_64-linux-gnu/libboost_*.so

你可能感兴趣的:(pcl,ubuntu,c++,qt)