Skip to content

Commit 1d7c32f

Browse files
committed
Robust object detection 🔨
1 parent c929fb7 commit 1d7c32f

File tree

2 files changed

+40
-26
lines changed

2 files changed

+40
-26
lines changed

object_detection/perception.rviz

+14-15
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ Panels:
33
Help Height: 75
44
Name: Displays
55
Property Tree Widget:
6-
Expanded:
7-
- /Axes1
6+
Expanded: ~
87
Splitter Ratio: 0.5
98
Tree Height: 371
109
- Class: rviz/Selection
@@ -25,7 +24,7 @@ Panels:
2524
Experimental: false
2625
Name: Time
2726
SyncMode: 0
28-
SyncSource: ""
27+
SyncSource: Camera View
2928
Visualization Manager:
3029
Class: ""
3130
Displays:
@@ -56,11 +55,11 @@ Visualization Manager:
5655
Value: true
5756
- Class: rviz/Image
5857
Enabled: true
59-
Image Topic: /draw_bbox/image
58+
Image Topic: /camera/color/image_raw
6059
Max Value: 1
6160
Median window: 5
6261
Min Value: 0
63-
Name: 3D Bounding Box Image
62+
Name: Camera View
6463
Normalize Range: true
6564
Queue Size: 2
6665
Transport Hint: raw
@@ -114,7 +113,7 @@ Visualization Manager:
114113
Max Intensity: 4096
115114
Min Color: 0; 0; 0
116115
Min Intensity: 0
117-
Name: ICP Registered PCL
116+
Name: Detected ICP
118117
Position Transformer: XYZ
119118
Queue Size: 10
120119
Selectable: true
@@ -221,7 +220,7 @@ Visualization Manager:
221220
Marker Topic: /object_pose_detection/object_pose_detection/grasp_pose
222221
Name: Marker
223222
Namespaces:
224-
{}
223+
grasp_pose: true
225224
Queue Size: 100
226225
Value: true
227226
Enabled: true
@@ -249,35 +248,35 @@ Visualization Manager:
249248
Views:
250249
Current:
251250
Class: rviz/Orbit
252-
Distance: 0.911043346
251+
Distance: 0.904538155
253252
Enable Stereo Rendering:
254253
Stereo Eye Separation: 0.0599999987
255254
Stereo Focal Distance: 1
256255
Swap Stereo Eyes: false
257256
Value: false
258257
Focal Point:
259-
X: -0.012347864
260-
Y: -0.153358907
261-
Z: -0.142543241
258+
X: 0.232943743
259+
Y: -0.0362719707
260+
Z: -0.0569765195
262261
Focal Shape Fixed Size: true
263262
Focal Shape Size: 0.0500000007
264263
Invert Z Axis: false
265264
Name: Current View
266265
Near Clip Distance: 0.00999999978
267-
Pitch: 0.550203443
266+
Pitch: 0.834797025
268267
Target Frame: <Fixed Frame>
269268
Value: Orbit (rviz)
270-
Yaw: 2.59425759
269+
Yaw: 2.36926389
271270
Saved: ~
272271
Window Geometry:
273-
3D Bounding Box Image:
272+
Camera View:
274273
collapsed: false
275274
Displays:
276275
collapsed: false
277276
Height: 1056
278277
Hide Left Dock: false
279278
Hide Right Dock: true
280-
QMainWindow State: 000000ff00000000fd00000004000000000000022200000396fc020000000afb0000001200530065006c0065006300740069006f006e00000001e10000009b0000006100fffffffb0000001e0054006f006f006c002000500072006f007000650072007400690065007302000001ed000001df00000185000000a3fb000000120056006900650077007300200054006f006f02000001df000002110000018500000122fb000000200054006f006f006c002000500072006f0070006500720074006900650073003203000002880000011d000002210000017afb000000100044006900730070006c0061007900730100000028000001ff000000d700fffffffb0000002000730065006c0065006300740069006f006e00200062007500660066006500720200000138000000aa0000023a00000294fb00000014005700690064006500530074006500720065006f02000000e6000000d2000003ee0000030bfb0000000c004b0069006e0065006300740200000186000001060000030c00000261fb0000002a0033004400200042006f0075006e00640069006e006700200042006f007800200049006d006100670065010000022d000001910000001600fffffffb0000000a0049006d006100670065000000028d000001310000000000000000000000010000010f00000396fc0200000003fb0000001e0054006f006f006c002000500072006f00700065007200740069006500730100000041000000780000000000000000fb0000000a00560069006500770073000000002800000396000000ad00fffffffb0000001200530065006c0065006300740069006f006e010000025a000000b200000000000000000000000200000490000000a9fc0100000001fb0000000a00560069006500770073030000004e00000080000002e10000019700000003000007410000003efc0100000002fb0000000800540069006d00650100000000000007410000030000fffffffb0000000800540069006d00650100000000000004500000000000000000000005190000039600000004000000040000000800000008fc0000000100000002000000010000000a0054006f006f006c00730100000000ffffffff0000000000000000
279+
QMainWindow State: 000000ff00000000fd00000004000000000000022200000396fc020000000afb0000001200530065006c0065006300740069006f006e00000001e10000009b0000006100fffffffb0000001e0054006f006f006c002000500072006f007000650072007400690065007302000001ed000001df00000185000000a3fb000000120056006900650077007300200054006f006f02000001df000002110000018500000122fb000000200054006f006f006c002000500072006f0070006500720074006900650073003203000002880000011d000002210000017afb000000100044006900730070006c0061007900730100000028000001ff000000d700fffffffb0000002000730065006c0065006300740069006f006e00200062007500660066006500720200000138000000aa0000023a00000294fb00000014005700690064006500530074006500720065006f02000000e6000000d2000003ee0000030bfb0000000c004b0069006e0065006300740200000186000001060000030c00000261fb0000001600430061006d00650072006100200056006900650077010000022d000001910000001600fffffffb0000000a0049006d006100670065000000028d000001310000000000000000000000010000010f00000396fc0200000003fb0000001e0054006f006f006c002000500072006f00700065007200740069006500730100000041000000780000000000000000fb0000000a00560069006500770073000000002800000396000000ad00fffffffb0000001200530065006c0065006300740069006f006e010000025a000000b200000000000000000000000200000490000000a9fc0100000001fb0000000a00560069006500770073030000004e00000080000002e10000019700000003000007410000003efc0100000002fb0000000800540069006d00650100000000000007410000030000fffffffb0000000800540069006d00650100000000000004500000000000000000000005190000039600000004000000040000000800000008fc0000000100000002000000010000000a0054006f006f006c00730100000000ffffffff0000000000000000
281280
Selection:
282281
collapsed: false
283282
Time:

object_detection/src/object_pose_detection.cpp

+26-11
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ add_executable(ground_plane_segmentation src/ground_plane_segmentation.cpp)
1212
target_link_libraries(ground_plane_segmentation ${catkin_LIBRARIES})
1313
*/
1414

15+
#include <cmath>
1516
#include "object_detection/boost.h"
1617
#include <visualization_msgs/Marker.h>
1718

@@ -76,9 +77,10 @@ sensor_msgs::PointCloud2 template_msg;
7677
tf::TransformListener* listener;
7778
geometry_msgs::Pose pose_msg;
7879
Eigen::Affine3d pose_transform;
79-
double dimensions[] = { 0.02, 0.15, 0.02 };
80+
double dimensions[] = { 0.02, 0.02, 0.15 };
8081
double icp_fitness_score;
8182
pcl::PCLPointCloud2::Ptr input_pcl(new pcl::PCLPointCloud2);
83+
vector<pcl::PointCloud<pcl::PointXYZ>::Ptr> output_pcls;
8284

8385
// Template paths
8486
string template_path;
@@ -207,7 +209,7 @@ void publish_bounding_box(Eigen::Matrix4d H)
207209
bbox_pub.publish(bbox_msg);
208210
}
209211

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)
211213
{
212214
int max_iter = 0;
213215
while (1) {
@@ -216,7 +218,7 @@ double icp_registration(pcl::PointCloud<pcl::PointXYZ>::Ptr input_pcl, pcl::Poin
216218

217219
// Run ICP
218220
pcl::IterativeClosestPoint<pcl::PointXYZ, pcl::PointXYZ> icp;
219-
icp.setInputSource(input_pcl);
221+
icp.setInputSource(object_pcl);
220222
icp.setInputTarget(template_pcl);
221223
icp.setMaximumIterations(5000);
222224
icp.setTransformationEpsilon(1e-9);
@@ -227,7 +229,7 @@ double icp_registration(pcl::PointCloud<pcl::PointXYZ>::Ptr input_pcl, pcl::Poin
227229
Eigen::Matrix4d icp_transform_local = icp.getFinalTransformation().cast<double>().inverse();
228230
icp_transforms.push_back(icp_transform_local);
229231

230-
cerr << "ICP Score Before: " << icp.getFitnessScore() << endl;
232+
// cerr << "ICP Score Before: " << icp.getFitnessScore() << endl;
231233
max_iter++;
232234

233235
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
237239
<< icp_transform_local << endl;
238240

239241
// Convert to ROS data type
240-
pcl::toROSMsg(*output_cloud, output_msg);
241242
pcl::toROSMsg(*template_pcl, template_msg);
243+
output_pcls.push_back(output_cloud);
242244
return icp.getFitnessScore();
243245
}
244246
}
@@ -253,6 +255,10 @@ void pcl_callback(const sensor_msgs::PointCloud2ConstPtr& input)
253255

254256
// Publish template point cloud
255257
if (ICP_SUCCESS and argmin != -1) {
258+
// Convert to ROS data type
259+
pcl::toROSMsg(*output_pcls[argmin], output_msg);
260+
261+
// Publish topics
256262
icp_pub.publish(output_msg);
257263
template_msg.header.frame_id = "camera_depth_optical_frame";
258264
template_pub.publish(template_msg);
@@ -362,6 +368,8 @@ bool service_callback(object_detection::ObjectDetection::Request& req,
362368
// Find the best registered object
363369
int obj_id = req.object_id;
364370
vector<double> icp_scores;
371+
vector<double> diff_scores;
372+
output_pcls.clear();
365373
icp_transforms.clear();
366374
ICP_SUCCESS = false;
367375

@@ -396,29 +404,36 @@ bool service_callback(object_detection::ObjectDetection::Request& req,
396404
// Register using ICP and broadcast TF
397405
double score = icp_registration(object_cluster_pcl, template_pcl);
398406
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()));
399413
}
400414

401415
// Find the object with best ICP score
402416
double min_score = 1000;
403417
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) {
406420
argmin = i;
407-
min_score = icp_scores[i];
421+
min_score = diff_scores[i];
408422
}
409423
}
410424

411425
cerr << "\nLowest Object Index: " << argmin << " with Score: " << min_score << endl;
412426
icp_transform = icp_transforms[argmin];
413427

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"
416431
<< endl;
417432
ICP_SUCCESS = true;
418433
res.success = true;
419434
return true;
420435
} else {
421-
cerr << "ICP Registration Failed to Converge within Threshold!\n"
436+
cerr << "Object Registration Failed to Converge within Threshold!\n"
422437
<< endl;
423438
ICP_SUCCESS = false;
424439
res.success = false;

0 commit comments

Comments
 (0)