Different result from pcl::MomentOfInertiaEstimation and pcl::CropBox?

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

Different result from pcl::MomentOfInertiaEstimation and pcl::CropBox?

duyu
I am trying to get an OBB from a point cloud, and I have got a right result
using pcl::MomentOfInertiaEstimation method .I want to extract the points
from the OBB using CropBox, but I got much less points than original point
cloud ,maybe there's something wrong in my rotation vector:v, I'm not quiet
sure. Can anyone help me?

struct BoundingBox{
        pcl::PointXYZ min_point_OBB;
        pcl::PointXYZ max_point_OBB;
        pcl::PointXYZ position_OBB;
        Eigen::Matrix3f rotational_matrix_OBB;
        pcl::PointXYZ center;
        pcl::PointXYZ x_axis;
        pcl::PointXYZ y_axis;
        pcl::PointXYZ z_axis;

};
BoundingBox getOBB(pcl::PointCloud<pcl::PointXYZ>::Ptr  cloud,BoundingBox
OBB )
{
  pcl::MomentOfInertiaEstimation <pcl::PointXYZ> feature_extractor;
  feature_extractor.setInputCloud (cloud);
  feature_extractor.compute ();
  feature_extractor.getOBB (OBB.min_point_OBB, OBB.max_point_OBB,
OBB.position_OBB, OBB.rotational_matrix_OBB);
 return OBB;
}  

int main(void){
BoundingBox OBB;
OBB=getOBB(Npoints,OBB);                   //Npoints is a part of the whole
cloud
Eigen::Quaternionf quat (OBB.rotational_matrix_OBB);
Eigen::Vector3f position (OBB.position_OBB.x, OBB.position_OBB.y,
OBB.position_OBB.z);
 pcl::visualization::PCLVisualizer viewer;
pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ>
points_color_handler (cloud, 255, 255, 255);
 viewer.addCube (position, quat, OBB.max_point_OBB.x - OBB.min_point_OBB.x,
OBB.max_point_OBB.y - OBB.min_point_OBB.y, OBB.max_point_OBB.z -
OBB.min_point_OBB.z,"OBB");
viewer.setShapeRenderingProperties(pcl::visualization::PCL_VISUALIZER_REPRESENTATION,
pcl::visualization::PCL_VISUALIZER_REPRESENTATION_WIREFRAME,"OBB");
////////////////above result is correct////////////////////
 Eigen::Vector4f
max_point_OBB(OBB.max_point_OBB.x,OBB.max_point_OBB.y,OBB.max_point_OBB.z,1.0);
Eigen::Vector4f
min_point_OBB(OBB.min_point_OBB.x,OBB.min_point_OBB.y,OBB.min_point_OBB.z,1.0);
pcl::PointCloud<pcl::PointXYZ>::Ptr cloudOut (new
pcl::PointCloud<pcl::PointXYZ>);
pcl::CropBox<pcl::PointXYZ> boxfilter;
boxfilter.setMax(max_point_OBB);        
boxfilter.setMin(min_point_OBB);
Eigen::Vector3f v = quat.vec();
boxfilter.setTranslation(position);
boxfilter.setRotation(v);
boxfilter.setInputCloud(cloud);
boxfilter.filter (*cloudOut);
 /////////cloulOut includes much less points than Npoints/////////

looking for an answer!





--
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: Different result from pcl::MomentOfInertiaEstimation and pcl::CropBox?

MarkL
CropBox::setRotation() expect a vector (rx, ry, rz) that represents the
rotation around x axis, y axis and z axis, and *not a Quaternion*.

I'm not familiar with any methods that help you with this convertion in
pcl/eigen.

Manual calculation (from rotation matrix / quaternion):
http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/
http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/

Alternatively, a simpler and less error prone approach you can try is to
transform the point cloud instead.
void pcl::CropBox< PointT >::setTransform (const Eigen::Affine3f &
transform)



duyu wrote
> I am trying to get an OBB from a point cloud, and I have got a right
> result
> using pcl::MomentOfInertiaEstimation method .I want to extract the points
> from the OBB using CropBox, but I got much less points than original point
> cloud ,maybe there's something wrong in my rotation vector:v, I'm not
> quiet
> sure. Can anyone help me?





--
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: Different result from pcl::MomentOfInertiaEstimation and pcl::CropBox?

lasdasdas
With Eigen simply

Eigen::Quaterniond q  = Eigen::Quaterniond(0.0,0.0,0.0,1.0);
Eigen::Vector3d rpy = q.toRotationMatrix().eulerAngles(0, 1, 2);

Where (0,1,2) are the axis conventions XYZ in this case.


On 11/26/2017 04:33 PM, MarkL wrote:

> CropBox::setRotation() expect a vector (rx, ry, rz) that represents the
> rotation around x axis, y axis and z axis, and *not a Quaternion*.
>
> I'm not familiar with any methods that help you with this convertion in
> pcl/eigen.
>
> Manual calculation (from rotation matrix / quaternion):
> http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/
> http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/
>
> Alternatively, a simpler and less error prone approach you can try is to
> transform the point cloud instead.
> void pcl::CropBox< PointT >::setTransform (const Eigen::Affine3f &
> transform)
>
>
>
> duyu wrote
>> I am trying to get an OBB from a point cloud, and I have got a right
>> result
>> using pcl::MomentOfInertiaEstimation method .I want to extract the points
>> from the OBB using CropBox, but I got much less points than original point
>> cloud ,maybe there's something wrong in my rotation vector:v, I'm not
>> quiet
>> sure. Can anyone help me?
>
>
>
>
> --
> Sent from: http://www.pcl-users.org/
> _______________________________________________
> [hidden email] / http://pointclouds.org
> http://pointclouds.org/mailman/listinfo/pcl-users

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

Re: Different result from pcl::MomentOfInertiaEstimation and pcl::CropBox?

duyu
I have try your method, but I still get a wrong result. There is my code and
result following, appreciate for your more help.
<http://www.pcl-users.org/file/t499113/1.png>
<http://www.pcl-users.org/file/t499113/2.png>
The first image shows I get a OBB , the second shows the result of trying to
get points from OBB, which turns wrong.
  pcl::CropBox<pcl::PointXYZ> boxfilter;
boxfilter.setMax(max_point_OBB);        
boxfilter.setMin(min_point_OBB);    
Eigen::Vector3f v =OBB.rotational_matrix_OBB.eulerAngles(0, 1, 2);
boxfilter.setTranslation(position);
boxfilter.setRotation(v);
boxfilter.setInputCloud(cloud);
boxfilter.filter (*cloudOut);

I change this part of my code follow your suggestion, but still the same.  
Otherwise, can I implement to extract points with other method. Thank you
very much.
                   



--
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: Different result from pcl::MomentOfInertiaEstimation and pcl::CropBox?

duyu
In reply to this post by lasdasdas
I have rotated my whole point cloud at the beginning, will that have
influence on it?



--
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: Different result from pcl::MomentOfInertiaEstimation and pcl::CropBox?

lasdasdas
The rotation should not be a problem. Can you pass me a PCD so I can check out what you mean. I can't really see what you mean in the pictures...


2017-11-27 4:01 GMT+01:00 duyu <[hidden email]>:
I have rotated my whole point cloud at the beginning, will that have
influence on it?



--
Atentamente,
David Serret Mayer

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