使用 pcl::CropBox 过滤器裁剪点云后,无法显示裁剪后的点云

After copping a Point Cloud using pcl::CropBox filter, can't visualize that cropped Point Cloud

我一直在努力理解 pcl::CropBoX 过滤器,这就是我一直在尝试使用它的原因。 但是,在这样做的同时,我遇到了这个问题:

  1. 我正在创建一个具有立方体形状的点云
  2. 可视化
  3. 使用 pcl::CropBox 过滤器裁剪原始点云
  4. 尝试可视化裁剪的点云

但是,在可视化工具中,对于第 4 步,我只能看到一个空白屏幕!

这是我的代码,main.cpp:

#include <iostream>
#include <string>
#include <vector>
#include <pcl/ModelCoefficients.h>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/sample_consensus/method_types.h>
#include <pcl/sample_consensus/model_types.h>
#include <pcl/segmentation/sac_segmentation.h>
#include <pcl/filters/voxel_grid.h>
#include <pcl/filters/extract_indices.h>
#include <pcl/visualization/cloud_viewer.h>
#include <pcl/common/common.h>
#include <pcl/filters/crop_box.h>

int main()
{
    pcl::PointCloud<pcl::PointXYZRGB>::Ptr
        main_cloud_ptr(new pcl::PointCloud<pcl::PointXYZRGB>),
        cropped_cloud_ptr(new pcl::PointCloud<pcl::PointXYZRGB>);
    
    // setting the dimension of a point cloud
    float x_start = 0.25, x_end = 1.25, x_resolution = 0.05;
    float y_start = 0.5, y_end = 2.0, y_resolution = 0.05;
    float z_start = 0.0, z_end = 1.25, z_resolution = 0.05;

    pcl::PointXYZRGB pt;

    // generating a point cloud
    for (float i = x_start; i < x_end; i += x_resolution)
    {
        for (float j = y_start; j < y_end; j += y_resolution)
        {
            for (float k = z_start; k < z_end; k += z_resolution)
            {
                pt.x = i;
                pt.y = j;
                pt.z = k;
                pt.r = i * 100;
                pt.g = 200;
                pt.b = j * 100;
                main_cloud_ptr->points.push_back(pt);
            }
        }
    }

    std::cout << main_cloud_ptr->points.size() << "\n";

    // visualizing a main point cloud
    pcl::visualization::CloudViewer viewer1("main_cloud_ptr viewer - cube");
    viewer1.showCloud(main_cloud_ptr);
    while (!viewer1.wasStopped())
    {
    }

    // getting minimum & maximum x, y, and z values of a point cloud
    pcl::PointXYZRGB min_pt, max_pt;
    pcl::getMinMax3D(*main_cloud_ptr, min_pt, max_pt);
    std::cout << "minimum " << min_pt.x << " " << min_pt.y << " " << min_pt.z << "\n";
    std::cout << "maximum " << max_pt.x << " " << max_pt.y << " " << max_pt.z << "\n";

    // setting pcl::CropBox filter
    pcl::CropBox<pcl::PointXYZRGB> box_filter;
    box_filter.setMin(Eigen::Vector4f(0.25, 0.5, 0.25, 1.0));
    box_filter.setMin(Eigen::Vector4f(1.25, 2.0, 0.75, 1.0));

    box_filter.setInputCloud(main_cloud_ptr);
    box_filter.filter(*cropped_cloud_ptr);

    // visualizing a cropped point cloud
    pcl::visualization::CloudViewer viewer2("cropped_cloud_ptr");
    viewer2.showCloud(cropped_cloud_ptr);
    while (!viewer2.wasStopped())
    {
    }

    return 0;
}

我的CMakeLists.txt:

cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR)

project(cropbox_experiment)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)

find_package(PCL 1.3 REQUIRED)

include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})

add_executable (${PROJECT_NAME} main.cpp)

target_link_libraries (${PROJECT_NAME} ${PCL_LIBRARIES})

这是 main point cloud 的输出:

这是 cropped point cloud 的输出(如您所见,它是空白的!!):

你能告诉我我在哪里犯错以及为什么我得到裁剪点云的空白输出吗?据我所知,xyz 轴的 minimummaximum 值在 setMinsetMax pcl::CropBox 过滤器的方法是正确的。

看来你设置了两次Min:

box_filter.setMin(Eigen::Vector4f(0.25, 0.5, 0.25, 1.0));
box_filter.setMin(Eigen::Vector4f(1.25, 2.0, 0.75, 1.0));