How to use CropBox on PointCloud2
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?
Asked by S.Yildiz on 2019-03-11 03:12:29 UTC
Answers
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);
Asked by ran cheng on 2020-04-23 10:51:09 UTC
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?
Asked by dvy on 2022-09-29 12:53:29 UTC
@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.
Asked by panosmer on 2023-08-06 22:32:11 UTC
Comments