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

Flaw with compute3DCentroid and getMinMax3D

asked 2018-11-26 07:21:42 -0500

th6262 gravatar image

Hey everyone, I'm using the "standard" way of creating bounding boxes for a point cloud cluster, which most resources online are using. My code posted below. However it seems there is a flaw here, because as seen in the screenshot, the algorithm seems to shift the bounding box a certain amount too far forward. I'm wondering where the offset is coming from?

image description

visualization_msgs::Marker mark_cluster(pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_cluster, int ide)
{
  Eigen::Vector4f centroid;
  Eigen::Vector4f min;
  Eigen::Vector4f max;

  pcl::compute3DCentroid (*cloud_cluster, centroid);
  pcl::getMinMax3D (*cloud_cluster, min, max);

  uint32_t shape = visualization_msgs::Marker::CUBE;
  visualization_msgs::Marker marker;
  marker.header.frame_id = "laser";
  marker.header.stamp = ros::Time::now();

  marker.ns = "objects";
  marker.id = ide;
  marker.type = shape;
  marker.action = visualization_msgs::Marker::ADD;

  marker.pose.position.x = centroid[0];
  marker.pose.position.y = centroid[1];
  marker.pose.position.z = centroid[2];
  marker.pose.orientation.x = 0.0;
  marker.pose.orientation.y = 0.0;
  marker.pose.orientation.z = 0.0;
  marker.pose.orientation.w = 1.0;

  marker.scale.x = (max[0]-min[0]);
  marker.scale.y = (max[1]-min[1]);
  marker.scale.z = (max[2]-min[2]);
   ...
edit retag flag offensive close merge delete

Comments

hello can i get the full version of your code ?

Thank you in advance

hichriayoub gravatar image hichriayoub  ( 2022-04-08 10:01:55 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2018-11-26 09:41:20 -0500

The problem is that the box you're creating to visualise this cluster assumes that the centroid of the cluster is exactly half way between the min and max values in each dimension. This is an invalid assumption, the centroid is the mean position of every point in the cloud.

If you want the box visual to simply show the extents of the cluster then you should set it's position to (min+max)/2 however this will not display the centroid.

I'd recommend using a line array marker instead so you can visualise the extents of the box as well as the centroid do describe the cluster more completely.

edit flag offensive delete link more

Comments

thanks a bunch

th6262 gravatar image th6262  ( 2018-11-26 10:10:18 -0500 )edit

will move my pcl specific question to the pcl forum in future! still massive thanks for all the help

th6262 gravatar image th6262  ( 2018-11-26 10:15:29 -0500 )edit

Question Tools

3 followers

Stats

Asked: 2018-11-26 07:21:42 -0500

Seen: 2,442 times

Last updated: Apr 08 '22