ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

Flaw with compute3DCentroid and getMinMax3D

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

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"; = 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


hello can i get the full version of your code ?

Thank you in advance

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

1 Answer

Sort by ยป oldest newest most voted

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

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


thanks a bunch

th6262 gravatar image th6262  ( 2018-11-26 10:10:18 -0600 )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 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



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

Seen: 2,111 times

Last updated: Apr 08 '22