ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

How to use CropBox on PointCloud2

asked 2019-03-11 03:12:29 -0600

S.Yildiz gravatar image

I have a tof camera with the type PointCloud2. I have looked a bit and found the cropbox function. I am a beginner in ros and I don't know how to use it. I found this code:

pcl::CropBox<pcl::PointXYZRGBA> boxFilter;
boxFilter.setMin(Eigen::Vector4f(minX, minY, minZ, 1.0));
boxFilter.setMax(Eigen::Vector4f(maxX, maxY, maxZ, 1.0));
boxFilter.setInputCloud(body);
boxFilter.filter(*bodyFiltered);

But now I don't know further. I have also seen this code:

int main (int argc, char** argv)
{
    pcl::visualization::PCLVisualizer viewer("Cloud Viewer");

    pcl::PointCloud<pcl::PointXYZRGBA>::Ptr body (new pcl::PointCloud<pcl::PointXYZRGBA>);
    pcl::io::loadPCDFile ("body.pcd", *body);

    pcl::PointCloud<pcl::PointXYZRGBA>::Ptr bodyFiltered (new pcl::PointCloud<pcl::PointXYZRGBA>);

    pcl::PassThrough<pcl::PointXYZRGBA> filter;
    filter.setInputCloud (body);
    filter.setFilterFieldName ("x");
    filter.setFilterLimits (minX, maxX);
    filter.setFilterFieldName ("y");
    filter.setFilterLimits (minY, maxY);
    filter.setFilterFieldName ("z");
    filter.setFilterLimits (minZ, maxZ);
    filter.filter (*bodyFiltered);

    viewer.addPointCloud (bodyFiltered,"body");
    viewer.spin();
    return 0;
}

Do I just have to replace the part with filter. ?

And I also want that the box is rotating with the imu. Would it be enough to set this box as a child of the imu?

And do I have to do a remap?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2020-04-23 10:51:09 -0600

ran cheng gravatar image

You can always check about the examples in the test code of PCL official library. Here is the code introduce how to use the filter: cropBox filter

And here is the code:

  // Test the PointCloud<PointT> method
 CropBox<PointXYZ> cropBoxFilter (true);
 cropBoxFilter.setInputCloud (input);
 Eigen::Vector4f min_pt (-1.0f, -1.0f, -1.0f, 1.0f);
 Eigen::Vector4f max_pt (1.0f, 1.0f, 1.0f, 1.0f);

 // Cropbox slighlty bigger then bounding box of points
 cropBoxFilter.setMin (min_pt);
 cropBoxFilter.setMax (max_pt);

 // Indices
 vector<int> indices;
 cropBoxFilter.filter (indices);

 // Cloud
 PointCloud<PointXYZ> cloud_out;
 cropBoxFilter.filter (cloud_out);
edit flag offensive delete link more

Comments

@ran cheng: Thanks a lot! It works. By the way, I don't know understand why to include the 4th/ last argument (1.0f) in min_pt/ max_pt. The reason why I say so is because we only need three coordinates (x,y,z) to define either min/ min. Can you please also explain the last 4 lines of the code where you apply filter: once on indices and second to output the cloud. How are they related?

dvy gravatar image dvy  ( 2022-09-29 12:53:29 -0600 )edit

@dvy They are homogeneous coordinates in the projective space P^3. To go from the space of real numbers R^3 to P^3 you add a 4th coordinate of 1. To go backwards you divide all elements with the 4th element, e.g (2,4,8,2) in P^3 -> (1,2,4) in R^3. The homogeneous representation has benefits that help to linearize a lot of equations in 2D and 3D space.

panosmer gravatar image panosmer  ( 2023-08-06 22:32:11 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2019-03-11 03:12:29 -0600

Seen: 5,589 times

Last updated: Mar 11 '19