@@ -12,6 +12,7 @@ add_executable(ground_plane_segmentation src/ground_plane_segmentation.cpp)
12
12
target_link_libraries(ground_plane_segmentation ${catkin_LIBRARIES})
13
13
*/
14
14
15
+ #include < cmath>
15
16
#include " object_detection/boost.h"
16
17
#include < visualization_msgs/Marker.h>
17
18
@@ -76,9 +77,10 @@ sensor_msgs::PointCloud2 template_msg;
76
77
tf::TransformListener* listener;
77
78
geometry_msgs::Pose pose_msg;
78
79
Eigen::Affine3d pose_transform;
79
- double dimensions[] = { 0.02 , 0.15 , 0.02 };
80
+ double dimensions[] = { 0.02 , 0.02 , 0.15 };
80
81
double icp_fitness_score;
81
82
pcl::PCLPointCloud2::Ptr input_pcl (new pcl::PCLPointCloud2);
83
+ vector<pcl::PointCloud<pcl::PointXYZ>::Ptr > output_pcls;
82
84
83
85
// Template paths
84
86
string template_path;
@@ -207,7 +209,7 @@ void publish_bounding_box(Eigen::Matrix4d H)
207
209
bbox_pub.publish (bbox_msg);
208
210
}
209
211
210
- double icp_registration (pcl::PointCloud<pcl::PointXYZ>::Ptr input_pcl , pcl::PointCloud<pcl::PointXYZ>::Ptr template_pcl)
212
+ double icp_registration (pcl::PointCloud<pcl::PointXYZ>::Ptr object_pcl , pcl::PointCloud<pcl::PointXYZ>::Ptr template_pcl)
211
213
{
212
214
int max_iter = 0 ;
213
215
while (1 ) {
@@ -216,7 +218,7 @@ double icp_registration(pcl::PointCloud<pcl::PointXYZ>::Ptr input_pcl, pcl::Poin
216
218
217
219
// Run ICP
218
220
pcl::IterativeClosestPoint<pcl::PointXYZ, pcl::PointXYZ> icp;
219
- icp.setInputSource (input_pcl );
221
+ icp.setInputSource (object_pcl );
220
222
icp.setInputTarget (template_pcl);
221
223
icp.setMaximumIterations (5000 );
222
224
icp.setTransformationEpsilon (1e-9 );
@@ -227,7 +229,7 @@ double icp_registration(pcl::PointCloud<pcl::PointXYZ>::Ptr input_pcl, pcl::Poin
227
229
Eigen::Matrix4d icp_transform_local = icp.getFinalTransformation ().cast <double >().inverse ();
228
230
icp_transforms.push_back (icp_transform_local);
229
231
230
- cerr << " ICP Score Before: " << icp.getFitnessScore () << endl;
232
+ // cerr << "ICP Score Before: " << icp.getFitnessScore() << endl;
231
233
max_iter++;
232
234
233
235
if ((icp.hasConverged () && icp.getFitnessScore () < icp_fitness_score) || (max_iter > 10 )) {
@@ -237,8 +239,8 @@ double icp_registration(pcl::PointCloud<pcl::PointXYZ>::Ptr input_pcl, pcl::Poin
237
239
<< icp_transform_local << endl;
238
240
239
241
// Convert to ROS data type
240
- pcl::toROSMsg (*output_cloud, output_msg);
241
242
pcl::toROSMsg (*template_pcl, template_msg);
243
+ output_pcls.push_back (output_cloud);
242
244
return icp.getFitnessScore ();
243
245
}
244
246
}
@@ -253,6 +255,10 @@ void pcl_callback(const sensor_msgs::PointCloud2ConstPtr& input)
253
255
254
256
// Publish template point cloud
255
257
if (ICP_SUCCESS and argmin != -1 ) {
258
+ // Convert to ROS data type
259
+ pcl::toROSMsg (*output_pcls[argmin], output_msg);
260
+
261
+ // Publish topics
256
262
icp_pub.publish (output_msg);
257
263
template_msg.header .frame_id = " camera_depth_optical_frame" ;
258
264
template_pub.publish (template_msg);
@@ -362,6 +368,8 @@ bool service_callback(object_detection::ObjectDetection::Request& req,
362
368
// Find the best registered object
363
369
int obj_id = req.object_id ;
364
370
vector<double > icp_scores;
371
+ vector<double > diff_scores;
372
+ output_pcls.clear ();
365
373
icp_transforms.clear ();
366
374
ICP_SUCCESS = false ;
367
375
@@ -396,29 +404,36 @@ bool service_callback(object_detection::ObjectDetection::Request& req,
396
404
// Register using ICP and broadcast TF
397
405
double score = icp_registration (object_cluster_pcl, template_pcl);
398
406
icp_scores.push_back (score);
407
+
408
+ // Check number of points
409
+ // cerr << "Object Points: " << (int)object_cluster_pcl->size() << endl;
410
+ // cerr << "Template Points: " << (int)template_pcl->size() << endl;
411
+ cerr << " Difference Score: " << abs ((int )object_cluster_pcl->size () - (int )template_pcl->size ()) << endl;
412
+ diff_scores.push_back (abs ((int )object_cluster_pcl->size () - (int )template_pcl->size ()));
399
413
}
400
414
401
415
// Find the object with best ICP score
402
416
double min_score = 1000 ;
403
417
argmin = -1 ;
404
- for (int i = 0 ; i < icp_scores .size (); i++) {
405
- if (icp_scores [i] < min_score) {
418
+ for (int i = 0 ; i < diff_scores .size (); i++) {
419
+ if (diff_scores [i] < min_score) {
406
420
argmin = i;
407
- min_score = icp_scores [i];
421
+ min_score = diff_scores [i];
408
422
}
409
423
}
410
424
411
425
cerr << " \n Lowest Object Index: " << argmin << " with Score: " << min_score << endl;
412
426
icp_transform = icp_transforms[argmin];
413
427
414
- if (min_score < icp_fitness_score) {
415
- cerr << " ICP Registration Success!\n "
428
+ // if (min_score < icp_fitness_score) {
429
+ if (min_score < 250 ) {
430
+ cerr << " Object Registration Success!\n "
416
431
<< endl;
417
432
ICP_SUCCESS = true ;
418
433
res.success = true ;
419
434
return true ;
420
435
} else {
421
- cerr << " ICP Registration Failed to Converge within Threshold!\n "
436
+ cerr << " Object Registration Failed to Converge within Threshold!\n "
422
437
<< endl;
423
438
ICP_SUCCESS = false ;
424
439
res.success = false ;
0 commit comments