From 656305cd8abb8446b19c44e221db2e783bdf165a Mon Sep 17 00:00:00 2001 From: Unknown Date: Fri, 29 Jun 2018 14:33:14 +0200 Subject: [PATCH] Detection du centre de l'objet --- my_pcl_tutorial/src/plannar_segmentation.cpp | 54 +++++++++++++++++++- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/my_pcl_tutorial/src/plannar_segmentation.cpp b/my_pcl_tutorial/src/plannar_segmentation.cpp index 4a162c3..1adbf51 100644 --- a/my_pcl_tutorial/src/plannar_segmentation.cpp +++ b/my_pcl_tutorial/src/plannar_segmentation.cpp @@ -11,7 +11,24 @@ #include +#include + +#include + +#include + +// void printinfo() +// { +// std::cout<<"OK"<values[0]<<" / "<values[1]<<" / "<values[2]<<" / "<values[3]); + //ROS_INFO_STREAM("Coeff : "<values[0]<<" / "<values[1]<<" / "<values[2]<<" / "<values[3]); //Créations de l'output pcl::PointCloud::Ptr pcl_output(new pcl::PointCloud); @@ -60,14 +77,45 @@ cloud_cb (const sensor_msgs::PointCloud2ConstPtr& input) extract.setNegative(true); extract.filter(*pcl_output); + //Calcul du centre + // CentroidPoint centroid; + // for (size_t i = 0; i < pcl_output->size (); ++i) + // { + // centroid.add(*pcl_output[i]); + // } + // pcl::PointXYZ c1; + // centroid.get (c1); + Eigen::Vector4f barycentre; + pcl::compute3DCentroid(*pcl_output, barycentre); + geometry_msgs::PointStamped center_msg; + // for (size_t i = 0; i < pcl_output->size (); ++i) + // { + // if( pcl_output->points[i].x) + // center.point.x += pcl_output->points[i]._PointXYZ::data[0]; + // center.point.y += pcl_output->points[i]._PointXYZ::data[1]; + // center.point.z += pcl_output->points[i]._PointXYZ::data[2]; + // ROS_INFO_STREAM("Center clioyf : "<points[i].x<<" / "<points[i].y<<" / "<points[i].z); + // } + // center.point.x = center.point.x/pcl_output->size (); + // center.point.y = center.point.y/pcl_output->size (); + // center.point.z = center.point.z/pcl_output->size (); + center_msg.point.x = barycentre[0]; + center_msg.point.y = barycentre[1]; + center_msg.point.z = barycentre[2]; + center_msg.header.frame_id = input->header.frame_id; + // ROS_INFO_STREAM("Center clioyf : "<points[0]._PointXYZ::data[0]<<" / "<points[0]._PointXYZ::data[1]<<" / "<points[0]._PointXYZ::data[2]); + // ROS_INFO_STREAM("barycentre : "<header.frame_id; // Publish the data. pub.publish (output); + pubc.publish( center_msg); } int main (int argc, char** argv) @@ -81,7 +129,9 @@ int main (int argc, char** argv) // Create a ROS publisher for the output point cloud pub = nh.advertise ("/plane_output", 1); + pubc = nh.advertise ("/object_center", 1); + // printinfo(); // Spin ros::spin (); } \ No newline at end of file