Removing point clouds inside a given box

拜拜、爱过 提交于 2021-01-29 20:00:52

问题


I would like to implement a code where I can remove certain points of the point clouds inside a given box. This is what I have so far:

void removePoints(){

    pcl::CropBox<pcl::PointXYZI> boxFilter;
    float x_min = -0.15, y_min = -0.5, z_min = -0.7;
    float x_max = +1, y_max = +2, z_max = +5;
    boxFilter.setMin(Eigen::Vector4f(x_min, y_min, z_min, 1.0));
    boxFilter.setMax(Eigen::Vector4f(x_max, y_max, z_max, 1.0));

    boxFilter.setInputCloud(cloud);
    boxFilter.filter(*newCloud);

    viewer->removeAllPointClouds();

    cloudLabel=new int[newCloud->size()];
    memset(cloudLabel, 0, newCloud->size()*sizeof(int));

    ui->label_filename->setText(QString::fromStdString(pointcloudFileName));
    colorHandler.setInputCloud(newCloud);
    colorHandler.setLabel(cloudLabel);
    viewer->addPointCloud<PointT>(newCloud,colorHandler,"cloud",0);


    viewer->resetCamera();
    viewer->updatePointCloud<PointT>(newCloud,"cloud");

    ui->qvtkWidget->update();


    std::cout<<"Removal done"<<std::endl;
    viewer->addCube(x_min, x_max, y_min, y_max, z_min, z_max, 1, 0, 0, "cube");
    viewer->setShapeRenderingProperties(pcl::visualization::PCL_VISUALIZER_COLOR,
    0.7, 0.7, 0, "cube");
     viewer->setRepresentationToWireframeForAllActors();
}

This code remove the points outside the box rather than the inside. Is there a way to inverse pcl::CropBox process?


回答1:


Almost all filters in PCL inherit pcl::FilterIndices, where the function setNegative is exposed.
Use boxFilter.setNegative(true) to filter the points inside the box.



来源:https://stackoverflow.com/questions/57185703/removing-point-clouds-inside-a-given-box

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!