32
32
#include < assert.h>
33
33
#include < sys/time.h>
34
34
#include < unistd.h>
35
+ #include < math.h>
35
36
36
37
#include < ros/ros.h>
37
38
#include < tf/transform_datatypes.h>
54
55
#include " fiducial_msgs/FiducialTransformArray.h"
55
56
#include " aruco_detect/DetectorParamsConfig.h"
56
57
58
+ #include < vision_msgs/Detection3D.h>
59
+ #include < vision_msgs/Detection3DArray.h>
60
+ #include < vision_msgs/ObjectHypothesisWithPose.h>
61
+
57
62
#include < opencv2/highgui.hpp>
58
63
#include < opencv2/aruco.hpp>
59
64
#include < opencv2/calib3d.hpp>
@@ -379,10 +384,10 @@ void FiducialsNode::poseEstimateCallback(const FiducialArrayConstPtr & msg)
379
384
{
380
385
vector <Vec3d> rvecs, tvecs;
381
386
382
- fiducial_msgs::FiducialTransformArray fta ;
383
- fta .header .stamp = msg->header .stamp ;
384
- fta .header .frame_id = frameId;
385
- fta. image_seq = msg->header .seq ;
387
+ vision_msgs::Detection3DArray vma ;
388
+ vma .header .stamp = msg->header .stamp ;
389
+ vma .header .frame_id = frameId;
390
+ vma. header . seq = msg->header .seq ;
386
391
frameNum++;
387
392
388
393
if (doPoseEstimation) {
@@ -417,39 +422,40 @@ void FiducialsNode::poseEstimateCallback(const FiducialArrayConstPtr & msg)
417
422
Vec3d axis = rvecs[i] / angle;
418
423
ROS_INFO (" angle %f axis %f %f %f" ,
419
424
angle, axis[0 ], axis[1 ], axis[2 ]);
420
-
421
- fiducial_msgs::FiducialTransform ft;
422
- ft.fiducial_id = ids[i];
423
-
424
- ft.transform .translation .x = tvecs[i][0 ];
425
- ft.transform .translation .y = tvecs[i][1 ];
426
- ft.transform .translation .z = tvecs[i][2 ];
427
-
425
+ double object_error =
426
+ (reprojectionError[i] / dist (corners[i][0 ], corners[i][2 ])) *
427
+ (norm (tvecs[i]) / fiducial_len);
428
+
429
+ // Standard ROS vision_msgs
430
+ vision_msgs::Detection3D vm;
431
+ vision_msgs::ObjectHypothesisWithPose vmh;
432
+ vmh.id = ids[i];
433
+ vmh.score = exp (-object_error);
434
+ vmh.pose .pose .position .x = tvecs[i][0 ];
435
+ vmh.pose .pose .position .y = tvecs[i][1 ];
436
+ vmh.pose .pose .position .z = tvecs[i][2 ];
428
437
tf2::Quaternion q;
429
438
q.setRotation (tf2::Vector3 (axis[0 ], axis[1 ], axis[2 ]), angle);
430
-
431
- ft.transform .rotation .w = q.w ();
432
- ft.transform .rotation .x = q.x ();
433
- ft.transform .rotation .y = q.y ();
434
- ft.transform .rotation .z = q.z ();
435
-
436
- ft.fiducial_area = calcFiducialArea (corners[i]);
437
- ft.image_error = reprojectionError[i];
438
-
439
- // Convert image_error (in pixels) to object_error (in meters)
440
- ft.object_error =
441
- (reprojectionError[i] / dist (corners[i][0 ], corners[i][2 ])) *
442
- (norm (tvecs[i]) / fiducial_len);
443
-
444
- fta.transforms .push_back (ft);
439
+ vmh.pose .pose .orientation .w = q.w ();
440
+ vmh.pose .pose .orientation .x = q.x ();
441
+ vmh.pose .pose .orientation .y = q.y ();
442
+ vmh.pose .pose .orientation .z = q.z ();
443
+ vm.results .push_back (vmh);
444
+ vma.detections .push_back (vm);
445
445
446
446
// Publish tf for the fiducial relative to the camera
447
447
if (publishFiducialTf) {
448
448
geometry_msgs::TransformStamped ts;
449
- ts.transform = ft.transform ;
449
+ ts.transform .translation .x = tvecs[i][0 ];
450
+ ts.transform .translation .y = tvecs[i][1 ];
451
+ ts.transform .translation .z = tvecs[i][2 ];
452
+ ts.transform .rotation .w = q.w ();
453
+ ts.transform .rotation .x = q.x ();
454
+ ts.transform .rotation .y = q.y ();
455
+ ts.transform .rotation .z = q.z ();
450
456
ts.header .frame_id = frameId;
451
457
ts.header .stamp = msg->header .stamp ;
452
- ts.child_frame_id = " fiducial_" + std::to_string (ft. fiducial_id );
458
+ ts.child_frame_id = " fiducial_" + std::to_string (ids[i] );
453
459
broadcaster.sendTransform (ts);
454
460
}
455
461
}
@@ -461,7 +467,7 @@ void FiducialsNode::poseEstimateCallback(const FiducialArrayConstPtr & msg)
461
467
ROS_ERROR (" cv exception: %s" , e.what ());
462
468
}
463
469
}
464
- pose_pub.publish (fta );
470
+ pose_pub.publish (vma );
465
471
}
466
472
467
473
void FiducialsNode::handleIgnoreString (const std::string& str)
@@ -587,7 +593,7 @@ FiducialsNode::FiducialsNode() : nh(), pnh("~"), it(nh)
587
593
588
594
vertices_pub = nh.advertise <fiducial_msgs::FiducialArray>(" fiducial_vertices" , 1 );
589
595
590
- pose_pub = nh.advertise <fiducial_msgs::FiducialTransformArray >(" fiducial_transforms" , 1 );
596
+ pose_pub = nh.advertise <vision_msgs::Detection3DArray >(" fiducial_transforms" , 1 );
591
597
592
598
dictionary = aruco::getPredefinedDictionary (dicno);
593
599
0 commit comments