Incorrect orientation of the cube to be applied to CropBox filter

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Incorrect orientation of the cube to be applied to CropBox filter

ravijoshi
This post was updated on .
Hi,

I have a PCD of a scene containing a ball captured from Kinect v2. Please see below a screenshot of the PCD-
<http://www.pcl-users.org/file/t499210/pcd-screenshot.png

I have defined a 2D rectangle which contains the ball. The two diagonal points of this rectangle are 's1' and 's2'. Below is the value of these points in image space (2D) and point cloud space (3D)-

Point s1: [2D] (441, 171) [3D] (0.774406, 0.295306, 2.703)
Point s2: [2D] (540,  78) [3D] ( 1.37865,0.845276, 2.834)

In order to segment the region of this rectangle, I planned to use CropBox filter. Hence, first I planned to draw a cube which can be applied to CropBox filter later on. Below are the parameters of the cube-

x_min: 0.774406, x_max: 1.37865
y_min: 0.295306, y_max: 0.845276
z_min: 0.2, z_max: 3.0

The minimum and maximum for 'x' and 'y' are derived by comparing the 3D values of point 's1' and 's2'. The 'z' limit is kept as per the environment configuration. Using the above minimum and maximum values, I decided to draw a cube on the point cloud and expected the ball to be inside this cube. For better understanding, I also plotted points 's1' and 's2'. Please see the screenshot of PCLVisualizer below-
<http://www.pcl-users.org/file/t499210/pcd-cube.png

Point 's1' is colored red and point 's2' is colored green. Although the ball looks in-between 's1' and 's2' but it is not. Please see the screenshot of rotated view below-
<http://www.pcl-users.org/file/t499210/rotate-view.png

Notice the yellow ball is now outside the box. Below is the code snippet
-------------------------------------------------------
//values are assigned to it later on but not shown here
pcl::visualization::Camera camera;

pcl::visualization::PCLVisualizer viewer("Cloud Viewer");
viewer.addPointCloud("scene.pcd", "cloud");

// point 's1'
pcl::PointXYZ s1(0.774406, 0.295306, 2.703);
viewer.addSphere(s1, 0.05, 255, 0, 0, "s1");
viewer.addText("s1", 441, 171, 20, 1, 0, 0, "s1_text");

// point 's1'
pcl::PointXYZ s2(1.37865, 0.845276, 2.834);
viewer.addSphere(s2, 0.05, 0, 255, 0, "s2");
viewer.addText("s2", 540, 78, 20, 0, 1, 0, "s2_text");

// cube values are derived by comparing points 's1' and 's2'
viewer.addCube(0.774406, 1.37865, 0.295306, 0.845276, 0.2, 3, 1, 0, 0, "cube");

viewer.initCameraParameters();
viewer.setCameraParameters(camera);
viewer.spin();
------------------------------------------------------

I want to crop the region which is outside the ball (or rectangle). Thanks
Reply | Threaded
Open this post in threaded view
|

Re: Incorrect orientation of the cube to be applied to CropBox filter

ravijoshi
Dear all,

I have edited the previous post since it was not rendered properly. I
apologize for the inconvenience.

Please let me know if the post is not visible correctly.

-
Thanks
Ravi



--
Sent from: http://www.pcl-users.org/
_______________________________________________
[hidden email] / http://pointclouds.org
http://pointclouds.org/mailman/listinfo/pcl-users
Reply | Threaded
Open this post in threaded view
|

Re: Incorrect orientation of the cube to be applied to CropBox filter

ravijoshi
I drilled down into the problem and found that defining a transformation
should suffice the need. Below is the code snippet-

--------------------------------------------------------------------------
Eigen::Affine3f transformation(Eigen::Affine3f::Identity());

pcl::CropBox<pcl::PointXYZRGB> box_filter;
box_filter.setMin(Eigen::Vector4f(x_min, y_min, z_min, 1.0));
box_filter.setMax(Eigen::Vector4f(x_max, y_max, z_max, 1.0));
box_filter.setInputCloud(cloud);
box_filter.setTransform (transformation);
box_filter.filter(*seg_cloud);
--------------------------------------------------------------------------

This transformation should be calculated by incorporating the camera object,
's1' and 's2' points. So that the segmented cloud contains the ball.

Any suggestions, please?



--
Sent from: http://www.pcl-users.org/
_______________________________________________
[hidden email] / http://pointclouds.org
http://pointclouds.org/mailman/listinfo/pcl-users
Reply | Threaded
Open this post in threaded view
|

Re: Incorrect orientation of the cube to be applied to CropBox filter

ravijoshi
I believe that the problem is related to the "perspective view". Please see
the sample image below-


<http://www.pcl-users.org/file/t499210/Orthographic_Perspective.png>


The yellow ball is kept in the middle of the scene. The points 's1' and 's2'
are located at far. Due to the "perspective view", the ball can only be
inside the box only if seen from the camera view.

I calculated the projection matrix and assigned it to CropBox filter. It
didn't work! Am I missing something obvious? I definitely appreciate your
suggestions. below is the code snippet-

--------------------------------------------------------
Eigen::Matrix4d proj_mat;
camera.computeProjectionMatrix(proj_mat);

Eigen::Affine3f transformation;
transformation.matrix() = proj_mat.cast<float>();

pcl::CropBox<pcl::PointXYZRGB> box_filter;
box_filter.setMin(Eigen::Vector4f(x_min, y_min, z_min, 1.0));
box_filter.setMax(Eigen::Vector4f(x_max, y_max, z_max, 1.0));
box_filter.setInputCloud(cloud);
box_filter.setTransform (transformation);
box_filter.filter(*seg_cloud);
--------------------------------------------------------



--
Sent from: http://www.pcl-users.org/
_______________________________________________
[hidden email] / http://pointclouds.org
http://pointclouds.org/mailman/listinfo/pcl-users