Finding oriented bounding box of a cloud

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

Finding oriented bounding box of a cloud

Guido
Hi all,

   I'm trying to compute the oriented bounding box of a pointcloud.
I'm using PCA and getMinMax :

pcl::PCA< PointType > pca;
pcl::PointCloud< PointType >::ConstPtr cloud;
pcl::PointCloud< PointType > proj;

Cloud proj;
pca.setInputCloud (cloud);
pca.project (*cloud, proj);

PointType proj_min;
PointType proj_max;
pcl::getMinMax3D (proj, proj_min, proj_max);

PointType min;
PointType max;
pca.reconstruct (proj_min, min);
pca.reconstruct (proj_max, max);

However, when adding the bounding box to a viewer :

boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer;
viewer->addCube (min.x, max.x, min.y, max.y, min.z, max.z);

I get a correctly centered but weirdly oriented flat square.

Anyone got the same problem ? Maybe I'm wrong somewhere, someone has an
idea about how to do this correctly ?

Guido

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

Re: Finding oriented bounding box of a cloud

Radu B. Rusu
Administrator
Guido,

Have you checked your min/max points to see if they make sense?

Cheers,
Radu.
--
http://openperception.org

On 12/11/2012 05:42 AM, guido wrote:

> Hi all,
>
>    I'm trying to compute the oriented bounding box of a pointcloud.
> I'm using PCA and getMinMax :
>
> pcl::PCA< PointType > pca;
> pcl::PointCloud< PointType >::ConstPtr cloud;
> pcl::PointCloud< PointType > proj;
>
> Cloud proj;
> pca.setInputCloud (cloud);
> pca.project (*cloud, proj);
>
> PointType proj_min;
> PointType proj_max;
> pcl::getMinMax3D (proj, proj_min, proj_max);
>
> PointType min;
> PointType max;
> pca.reconstruct (proj_min, min);
> pca.reconstruct (proj_max, max);
>
> However, when adding the bounding box to a viewer :
>
> boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer;
> viewer->addCube (min.x, max.x, min.y, max.y, min.z, max.z);
>
> I get a correctly centered but weirdly oriented flat square.
>
> Anyone got the same problem ? Maybe I'm wrong somewhere, someone has an idea about how to do this correctly ?
>
> Guido
>
> _______________________________________________
> [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: Finding oriented bounding box of a cloud

Guido
The considered object is the one on the table in this tutorial :
http://pointclouds.org/documentation/tutorials/extract_indices.php#extract-indices

I've printed the min and max points.

In object frame (i.e. after projection) :
Proj_min: -0.0788761 -0.0376409 -0.0266807
Proj_max: 0.0869685 0.0808181 0.0791911

In camera frame (i.e. after reconstruction) :
min: -0.185806 0.35545 -1.2483
max: -0.126961 0.275855 -1.45554

The values doesn't look plain wrong.
The distance between the min and max points is coherent after reconstruction. Maybe a problem during the projection ?
Reply | Threaded
Open this post in threaded view
|

Re: Finding oriented bounding box of a cloud

Pat Marion
Hi Guido,

In the code you pasted:

viewer->addCube (min.x, max.x, min.y, max.y, min.z, max.z);

That's going to create an axis aligned bounding box.  There are three overloads of addCube(), you should use one of the other ones that take orientation information to create an oriented bounding box.

Pat

On Mon, Dec 17, 2012 at 7:07 AM, Guido <[hidden email]> wrote:
The considered object is the one on the table in this tutorial :
http://pointclouds.org/documentation/tutorials/extract_indices.php#extract-indices

I've printed the min and max points.

In object frame (i.e. after projection) :
Proj_min: -0.0788761 -0.0376409 -0.0266807
Proj_max: 0.0869685 0.0808181 0.0791911

In camera frame (i.e. after reconstruction) :
min: -0.185806 0.35545 -1.2483
max: -0.126961 0.275855 -1.45554

The values doesn't look plain wrong.
The distance between the min and max points is coherent after
reconstruction. Maybe a problem during the projection ?



--
View this message in context: http://www.pcl-users.org/Finding-oriented-bounding-box-of-a-cloud-tp4024616p4024787.html
Sent from the Point Cloud Library (PCL) Users mailing list mailing list archive at Nabble.com.


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

Re: Finding oriented bounding box of a cloud

Guido
Radu and Pat thank you for your answers.

Pat,

  It works better with a addCube function that takes orientation as input.
However I still got some trouble. I get the various information for addCube as follows :

quaternion = Eigen::Quaternionf (pca.getEigenVectors ());

Eigen::Vector4f t = pca.getMean();
translation = Eigen::Vector3f (t.x(), t.y(), t.z());

width = fabs(proj_max.x-proj_min.x);
height = fabs(proj_max.y-proj_min.y);
depth = fabs(proj_max.z-proj_min.z);

While bounding box are not flat anymore, they still have funny orientations. What could be wrong ? Should I use the EigenVectors inverse ?

Guido
Reply | Threaded
Open this post in threaded view
|

Re: Finding oriented bounding box of a cloud

Guido
Hey,

  After some testing, I can tell that this is definitely a rotation problem.

I tested it on the pointcloud used for the visualization tutorial : a cylinder along z axis. The resulting box has its main axis along x (orthogonal to the cylinder) while it should be along z.

The box is well centered and its dimensions are correct. However the orientation is wrong.
Could it be because of a swap between rotation axis ? Has someone experimented something similar and knows how to solve this ?

Best regards,

Guido
Reply | Threaded
Open this post in threaded view
|

Re: Finding oriented bounding box of a cloud

Radu B. Rusu
Administrator
Guido,

If you think that you found a bug, the best way for us to investigate it is via an issue on http://dev.pointclouds.org,
with a minimal code snippet that best reproduces the problem.

Cheers,
Radu.
--
http://openperception.org

On 12/19/2012 02:37 PM, Guido wrote:

> Hey,
>
>    After some testing, I can tell that this is definitely a rotation problem.
>
> I tested it on the pointcloud used for the visualization tutorial : a
> cylinder along z axis. The resulting box has its main axis along x
> (orthogonal to the cylinder) while it should be along z.
>
> The box is well centered and its dimensions are correct. However the
> orientation is wrong.
> Could it be because of a swap between rotation axis ? Has someone
> experimented something similar and knows how to solve this ?
>
> Best regards,
>
> Guido
>
>
>
> --
> View this message in context: http://www.pcl-users.org/Finding-oriented-bounding-box-of-a-cloud-tp4024616p4024886.html
> Sent from the Point Cloud Library (PCL) Users mailing list mailing list archive at Nabble.com.
> _______________________________________________
> [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: Finding oriented bounding box of a cloud

Guido
I don't believe there is a bug; I rather think that I missunderstand a concept about PCA or Oriented Bounding Boxes and/or their implementation. I'm surprised no one ever used pcl's PCA in order to compute obbs.
RB
Reply | Threaded
Open this post in threaded view
|

Re: Finding oriented bounding box of a cloud

RB
PCA works fine for me though I've used pca.getEigenVectors() and custom calculated oriented min, max.

Best,
fed
Reply | Threaded
Open this post in threaded view
|

Re: Finding oriented bounding box of a cloud

fed
This post has NOT been accepted by the mailing list yet.
In reply to this post by Guido
Hi,
I'm experimenting the same problem;
Have you found a solution?
Reply | Threaded
Open this post in threaded view
|

Re: Finding oriented bounding box of a cloud

Altella
In reply to this post by RB
Hi ;

I am very interested in computing an oriented bounding box for my 3D object. I am very interested in dimensions along the three axis and the orientation of the principal axis.
PCA seem to be the "easiest" solution for doing this with PCL withount using other libraries.

Could you provide a little bit more information on your code if its works fine?

Thank you very much in advance,
Reply | Threaded
Open this post in threaded view
|

Re: Finding oriented bounding box of a cloud

xelda1988
This post has NOT been accepted by the mailing list yet.
I also tried to solve the oriented bounding box problem!
The problem was that you directly put the pca.eigenvectors into the quaternion.
But if you compute the determinant of the pca.eigenvectors() its -1, so no pure rotation matrix.
So you need to reorder the vectors.
I solved it like this:

  //Rotation of PCA
  Eigen::Matrix3f rot_mat = pca.getEigenVectors ();

  //translation of PCA
  Eigen::Vector3f cl_translation = pca.getMean().head(3);

  Eigen::Matrix4f affine_trans;

  //Reordering of principal components
  affine_trans.col(0) << (rot_mat.col(0).cross(rot_mat.col(1))).normalized(),0;
  affine_trans.col(1) << rot_mat.col(0),0;
  affine_trans.col(2) << rot_mat.col(1),0;
  affine_trans.col(3) << cl_translation,1;
Reply | Threaded
Open this post in threaded view
|

Re: Finding oriented bounding box of a cloud

Zoid
In reply to this post by Altella
Hello all,

Since I am relatively new at this, I was wandering if you finally found a solution to the problem of fitting a bounding box to a cloud. If so, will someone be so kind to provide me with some working code example to test it with my data?

Thank you in advance and best regards,

Akis  
Reply | Threaded
Open this post in threaded view
|

Re: Finding oriented bounding box of a cloud

Nicola Fioraio
In reply to this post by Guido
Hi,

here it is some hints:
{{{
    // your point cloud
    pcl::PointCloud<PointT>::Ptr point_cloud_ptr = ...;

    // compute principal direction
    Eigen::Vector4f centroid;
    pcl::compute3DCentroid(*point_cloud_ptr, centroid);
    Eigen::Matrix3f covariance;
    computeCovarianceMatrixNormalized(*point_cloud_ptr, centroid, covariance);
    Eigen::SelfAdjointEigenSolver<Eigen::Matrix3f> eigen_solver(covariance, Eigen::ComputeEigenvectors);
    Eigen::Matrix3f eigDx = eigen_solver.eigenvectors();
    eigDx.col(2) = eigDx.col(0).cross(eigDx.col(1));

    // move the points to the that reference frame
    Eigen::Matrix4f p2w(Eigen::Matrix4f::Identity());
    p2w.block<3,3>(0,0) = eigDx.transpose();
    p2w.block<3,1>(0,3) = -1.f * (p2w.block<3,3>(0,0) * centroid.head<3>());
    pcl::PointCloud<PointT> cPoints;
    pcl::transformPointCloud(*point_cloud_ptr, cPoints, p2w);

    PointT min_pt, max_pt;
    pcl::getMinMax3D(cPoints, min_pt, max_pt);
    const Eigen::Vector3f mean_diag = 0.5f*(max_pt.getVector3fMap() + min_pt.getVector3fMap());

    // final transform
    const Eigen::Quaternionf qfinal(eigDx);
    const Eigen::Vector3f tfinal = eigDx*mean_diag + centroid.head<3>();

    // draw the cloud and the box
    pcl::visualization::PCLVisualizer viewer;
    viewer.addPointCloud(point_cloud_ptr);
    viewer.addCube(tfinal, qfinal, max_pt.x - min_pt.x, max_pt.y - min_pt.y, max_pt.z - min_pt.z);
    viewer.spin();
}}}

cheers
--N



On Tue, Sep 3, 2013 at 3:15 PM, Polychronis Kondaxakis <[hidden email]> wrote:
Hello all,

Since I am relatively new at this, I was wandering if you finally found a solution to the problem of fitting a bounding box to a cloud. If so, will someone be so kind to provide me with some working code example to test it with my data?

Thank you in advance and best regards,

Akis 

_______________________________________________
[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: Finding oriented bounding box of a cloud

Zoid
In reply to this post by Zoid
Hello all,

After my initial email, I have tried to fit a bounding box to my point cloud data following the previous correspondence of this thread. Unfortunately, I still have not managed to have a proper rotational alignment of my point data inside the bounding box.

Can anybody help me with that please?

My code so far is the following:

int
main (int argc, char* argv[])
{
  // Initialize ROS
  ros::init (argc, argv, "Binding_Box");
  ros::NodeHandle nh;
 
  if (argc < 2)
  {
    printf ("No target PCD file given!\n");
    return (-1);
  }

  // Load the target cloud PCD file
  pcl17::PointCloud<pcl17::PointXYZ>::Ptr cloud (new pcl17::PointCloud<pcl17::PointXYZ>);
  pcl17::io::loadPCDFile (argv[1], *cloud);
  std::cout << "PointCloud before filtering has: " << cloud->points.size () << " data points." << std::endl; //*

  pcl17::PCA<pcl17::PointXYZ> pca;
  pcl17::PointCloud<pcl17::PointXYZ> proj;

  pca.setInputCloud (cloud);
  pca.project (*cloud, proj);

  pcl17::PointXYZ proj_min;
  pcl17::PointXYZ proj_max;
  pcl17::getMinMax3D (proj, proj_min, proj_max);

  pcl17::PointXYZ min;
  pcl17::PointXYZ max;
  pca.reconstruct (proj_min, min);
  pca.reconstruct (proj_max, max);
  std::cout << " min.x= " << min.x << " max.x= " << max.x << " min.y= " << min.y << " max.y= " << max.y << " min.z= " << min.z << " max.z= " << max.z << std::endl;
 
  //Rotation of PCA
  Eigen::Matrix3f rot_mat = pca.getEigenVectors ();

  //translation of PCA
  Eigen::Vector3f cl_translation = pca.getMean().head(3);

  Eigen::Matrix3f affine_trans;
  std::cout << rot_mat << std::endl;
  //Reordering of principal components
  affine_trans.col(0) << (rot_mat.col(0).cross(rot_mat.col(1))).normalized();
  affine_trans.col(1) << rot_mat.col(0);
  affine_trans.col(2) << rot_mat.col(1);
  //affine_trans.col(3) << cl_translation,1;/**/

  std::cout << affine_trans << std::endl;

  Eigen::Quaternionf rotation = Eigen::Quaternionf (affine_trans);
  Eigen::Vector4f t = pca.getMean();

  Eigen::Vector3f translation = Eigen::Vector3f (t.x(), t.y(), t.z());

  double width = fabs(proj_max.x-proj_min.x);
  double height = fabs(proj_max.y-proj_min.y);
  double depth = fabs(proj_max.z-proj_min.z);

  //adding the bounding box to a viewer :
  boost::shared_ptr<pcl17::visualization::PCLVisualizer> viewer (new pcl17::visualization::PCLVisualizer ("3D Viewer"));
  viewer->setBackgroundColor (0, 0, 0);
  viewer->addPointCloud<pcl17::PointXYZ> (cloud, "NAO arm cloud");
  viewer->setPointCloudRenderingProperties (pcl17::visualization::PCL17_VISUALIZER_POINT_SIZE, 1, "NAO arm cloud");
  viewer->addCoordinateSystem (1.0);
  viewer->initCameraParameters ();
  //viewer->addCube (min.x, max.x, min.y, max.y, min.z, max.z);/**/
  viewer->addCube (translation, rotation, width, height, depth);
  //--------------------
  // -----Main loop-----
  //--------------------
  while (!viewer->wasStopped ())
  {
    viewer->spinOnce (100);
    boost::this_thread::sleep (boost::posix_time::microseconds (100000));
  }

  ros::shutdown();
  return 0;

}

So if I use the rotational matrix as "xelda1988" suggests I am getting the following alignment:



Else if I use the rotational matrix as "Guido" suggested, I am getting the following alignment:



Any Ideas?

Akis

Reply | Threaded
Open this post in threaded view
|

Re: Finding oriented bounding box of a cloud

Nicola Fioraio
Hi all again,

the code I posted works; it basically does:
1) compute the centroid (c0, c1, c2) and the normalized covariance
2) compute the eigenvectors e0, e1, e2. The reference system will be (e0, e1, e0 X e1) --- note: e0 X e1 = +/- e2
3) move the points in that RF --- note: the transformation given by the rotation matrix (e0, e1, e0 X e1) & (c0, c1, c2) must be inverted
4) compute the max, the min and the center of the diagonal
5) given a box centered at the origin with size (max_pt.x - min_pt.x, max_pt.y - min_pt.y, max_pt.z - min_pt.z) the transformation you have to apply is Rotation = (e0, e1, e0 X e1) & Translation = Rotation * center_diag + (c0, c1, c2)

cheers
--N

 


On Thu, Sep 5, 2013 at 4:11 PM, Zoid <[hidden email]> wrote:
Hello all,

After my initial email, I have tried to fit a bounding box to my point cloud
data following the previous correspondence of this thread. Unfortunately, I
still have not managed to have a proper rotational alignment of my point
data inside the bounding box.

Can anybody help me with that please?

My code so far is the following:

int
main (int argc, char* argv[])
{
  // Initialize ROS
  ros::init (argc, argv, "Binding_Box");
  ros::NodeHandle nh;

  if (argc < 2)
  {
    printf ("No target PCD file given!\n");
    return (-1);
  }

  // Load the target cloud PCD file
  pcl17::PointCloud<pcl17::PointXYZ>::Ptr cloud (new
pcl17::PointCloud<pcl17::PointXYZ>);
  pcl17::io::loadPCDFile (argv[1], *cloud);
  std::cout << "PointCloud before filtering has: " << cloud->points.size ()
<< " data points." << std::endl; //*

  pcl17::PCA<pcl17::PointXYZ> pca;
  pcl17::PointCloud<pcl17::PointXYZ> proj;

  pca.setInputCloud (cloud);
  pca.project (*cloud, proj);

  pcl17::PointXYZ proj_min;
  pcl17::PointXYZ proj_max;
  pcl17::getMinMax3D (proj, proj_min, proj_max);

  pcl17::PointXYZ min;
  pcl17::PointXYZ max;
  pca.reconstruct (proj_min, min);
  pca.reconstruct (proj_max, max);
  std::cout << " min.x= " << min.x << " max.x= " << max.x << " min.y= " <<
min.y << " max.y= " << max.y << " min.z= " << min.z << " max.z= " << max.z
<< std::endl;

  //Rotation of PCA
  Eigen::Matrix3f rot_mat = pca.getEigenVectors ();

  //translation of PCA
  Eigen::Vector3f cl_translation = pca.getMean().head(3);

  Eigen::Matrix3f affine_trans;
  std::cout << rot_mat << std::endl;
  //Reordering of principal components
  affine_trans.col(0) <<
(rot_mat.col(0).cross(rot_mat.col(1))).normalized();
  affine_trans.col(1) << rot_mat.col(0);
  affine_trans.col(2) << rot_mat.col(1);
  //affine_trans.col(3) << cl_translation,1;/**/

  std::cout << affine_trans << std::endl;

  Eigen::Quaternionf rotation = Eigen::Quaternionf (affine_trans);
  Eigen::Vector4f t = pca.getMean();

  Eigen::Vector3f translation = Eigen::Vector3f (t.x(), t.y(), t.z());

  double width = fabs(proj_max.x-proj_min.x);
  double height = fabs(proj_max.y-proj_min.y);
  double depth = fabs(proj_max.z-proj_min.z);

  //adding the bounding box to a viewer :
  boost::shared_ptr<pcl17::visualization::PCLVisualizer> viewer (new
pcl17::visualization::PCLVisualizer ("3D Viewer"));
  viewer->setBackgroundColor (0, 0, 0);
  viewer->addPointCloud<pcl17::PointXYZ> (cloud, "NAO arm cloud");
  viewer->setPointCloudRenderingProperties
(pcl17::visualization::PCL17_VISUALIZER_POINT_SIZE, 1, "NAO arm cloud");
  viewer->addCoordinateSystem (1.0);
  viewer->initCameraParameters ();
  //viewer->addCube (min.x, max.x, min.y, max.y, min.z, max.z);/**/
  viewer->addCube (translation, rotation, width, height, depth);
  //--------------------
  // -----Main loop-----
  //--------------------
  while (!viewer->wasStopped ())
  {
    viewer->spinOnce (100);
    boost::this_thread::sleep (boost::posix_time::microseconds (100000));
  }

  ros::shutdown();
  return 0;

}

So if I use the rotational matrix as "xelda1988" suggests I am getting the
following alignment:

<http://www.pcl-users.org/file/n4029495/06.png>

Else if I use the rotational matrix as "Guido" suggested, I am getting the
following alignment:

<http://www.pcl-users.org/file/n4029495/21.png>

Any Ideas?

Akis





--
View this message in context: http://www.pcl-users.org/Finding-oriented-bounding-box-of-a-cloud-tp4024616p4029495.html
Sent from the Point Cloud Library (PCL) Users mailing list mailing list archive at Nabble.com.
_______________________________________________
[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: Finding oriented bounding box of a cloud

Zoid
In reply to this post by Nicola Fioraio
Yes it Works!!!!!

Thank you so much Nicola!

Best,

Akis
Reply | Threaded
Open this post in threaded view
|

Re: Finding oriented bounding box of a cloud

Zoid
Hello all again,

Ok now I have my bounding box of a point cloud thanks to Nicola's code! Based on that code, I am trying to find the midpoints of the two sides of the box and connect these points with a line-arrow as shown in the picture below. I have tried to do that with the viewer's addArrow, addLine functions but I am not getting it right.

Any help you could provide would be greatly appreciate it.  

Best,

Akis

 
Reply | Threaded
Open this post in threaded view
|

Re: Finding oriented bounding box of a cloud

Zoid
Hello,

Here is some code on how I am trying to solve the problem:

{{{
    // your point cloud
    pcl::PointCloud<PointT>::Ptr point_cloud_ptr = ...;

    // compute principal direction
    Eigen::Vector4f centroid;
    pcl::compute3DCentroid(*point_cloud_ptr, centroid);
    Eigen::Matrix3f covariance;
    computeCovarianceMatrixNormalized(*point_cloud_ptr, centroid, covariance);
    Eigen::SelfAdjointEigenSolver<Eigen::Matrix3f> eigen_solver(covariance, Eigen::ComputeEigenvectors);
    Eigen::Matrix3f eigDx = eigen_solver.eigenvectors();
    eigDx.col(2) = eigDx.col(0).cross(eigDx.col(1));

    // move the points to the that reference frame
    Eigen::Matrix4f p2w(Eigen::Matrix4f::Identity());
    p2w.block<3,3>(0,0) = eigDx.transpose();
    p2w.block<3,1>(0,3) = -1.f * (p2w.block<3,3>(0,0) * centroid.head<3>());
    pcl::PointCloud<PointT> cPoints;
    pcl::transformPointCloud(*point_cloud_ptr, cPoints, p2w);

    PointT min_pt, max_pt;
    pcl::getMinMax3D(cPoints, min_pt, max_pt);
    const Eigen::Vector3f mean_diag = 0.5f*(max_pt.getVector3fMap() + min_pt.getVector3fMap());

    // final transform
    const Eigen::Quaternionf qfinal(eigDx);
    const Eigen::Vector3f tfinal = eigDx*mean_diag + centroid.head<3>();

//------------------------------------------------------------------------------------------------------------------
    // getting the two points for the arrow
    pcl17::PointXYZ front_midpoint, back_midpoint;
    front_midpoint.x= (max_pt.x + min_pt.x)/2;
    front_midpoint.y= (max_pt.y + min_pt.y)/2;
    front_midpoint.z= max_pt.z;
    back_midpoint.x= (max_pt.x + min_pt.x)/2;
    back_midpoint.y= (max_pt.y + min_pt.y)/2;
    back_midpoint.z= min_pt.z;
//------------------------------------------------------------------------------------------------------------------

    // draw the cloud, the box and the arrow
    pcl::visualization::PCLVisualizer viewer;
    viewer.addPointCloud(point_cloud_ptr);
    viewer.addCube(tfinal, qfinal, max_pt.x - min_pt.x, max_pt.y - min_pt.y, max_pt.z - min_pt.z);
    viewer->addArrow(front_midpoint, back_midpoint, 1.0, 0.7, 0.0, false, "arrow_box");
    viewer.spin();
}}}

Basically, I am using the max_pt, min_pt points (I assume they are the minimum and maximum points of my box) extracted by the getMinMax3D function to set the arrow at the sides of my box. Unfortunately the arrow appears pointing at the 0,0,0 position.

Any ideas?

Best,

Akis
Reply | Threaded
Open this post in threaded view
|

Re: Finding oriented bounding box of a cloud

ramanan1991
This post has NOT been accepted by the mailing list yet.
In reply to this post by Nicola Fioraio
Hi!
I have two carton boxes moving on a conveyor. After segmentation, there are two point clouds each belonging to a carton box. Can i fit a "bounding box"  each to the point clouds of these carton boxes at the same time and measure the dimensions of the boxes in real time (bcos the boxes are moving) ?

Also my main goal is object tracking. So after  fitting a bounded box to these point clouds and measuring the dimensions of the box, can i get the pose of the box continuously?
12