Skip to content

Commit 1afc4b9

Browse files
author
Teodor
committed
Fiducial_msgs migration to vision_msgs
1 parent 982cf2b commit 1afc4b9

File tree

8 files changed

+336
-31
lines changed

8 files changed

+336
-31
lines changed

aruco_detect/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ find_package(catkin REQUIRED COMPONENTS
88
tf2_ros
99
tf2
1010
visualization_msgs
11+
vision_msgs
1112
image_transport
1213
cv_bridge
1314
sensor_msgs

aruco_detect/package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<depend>tf2_ros</depend>
1919
<depend>tf2</depend>
2020
<depend>visualization_msgs</depend>
21+
<depend>vision_msgs</depend>
2122
<depend>image_transport</depend>
2223
<depend>sensor_msgs</depend>
2324
<depend>cv_bridge</depend>

aruco_detect/src/aruco_detect.cpp

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <assert.h>
3333
#include <sys/time.h>
3434
#include <unistd.h>
35+
#include <math.h>
3536

3637
#include <ros/ros.h>
3738
#include <tf/transform_datatypes.h>
@@ -54,6 +55,10 @@
5455
#include "fiducial_msgs/FiducialTransformArray.h"
5556
#include "aruco_detect/DetectorParamsConfig.h"
5657

58+
#include <vision_msgs/Detection3D.h>
59+
#include <vision_msgs/Detection3DArray.h>
60+
#include <vision_msgs/ObjectHypothesisWithPose.h>
61+
5762
#include <opencv2/highgui.hpp>
5863
#include <opencv2/aruco.hpp>
5964
#include <opencv2/calib3d.hpp>
@@ -379,10 +384,10 @@ void FiducialsNode::poseEstimateCallback(const FiducialArrayConstPtr & msg)
379384
{
380385
vector <Vec3d> rvecs, tvecs;
381386

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;
386391
frameNum++;
387392

388393
if (doPoseEstimation) {
@@ -417,39 +422,40 @@ void FiducialsNode::poseEstimateCallback(const FiducialArrayConstPtr & msg)
417422
Vec3d axis = rvecs[i] / angle;
418423
ROS_INFO("angle %f axis %f %f %f",
419424
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];
428437
tf2::Quaternion q;
429438
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);
445445

446446
// Publish tf for the fiducial relative to the camera
447447
if (publishFiducialTf) {
448448
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();
450456
ts.header.frame_id = frameId;
451457
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]);
453459
broadcaster.sendTransform(ts);
454460
}
455461
}
@@ -461,7 +467,7 @@ void FiducialsNode::poseEstimateCallback(const FiducialArrayConstPtr & msg)
461467
ROS_ERROR("cv exception: %s", e.what());
462468
}
463469
}
464-
pose_pub.publish(fta);
470+
pose_pub.publish(vma);
465471
}
466472

467473
void FiducialsNode::handleIgnoreString(const std::string& str)
@@ -587,7 +593,7 @@ FiducialsNode::FiducialsNode() : nh(), pnh("~"), it(nh)
587593

588594
vertices_pub = nh.advertise<fiducial_msgs::FiducialArray>("fiducial_vertices", 1);
589595

590-
pose_pub = nh.advertise<fiducial_msgs::FiducialTransformArray>("fiducial_transforms", 1);
596+
pose_pub = nh.advertise<vision_msgs::Detection3DArray>("fiducial_transforms", 1);
591597

592598
dictionary = aruco::getPredefinedDictionary(dicno);
593599

aruco_gazebo/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
cmake_minimum_required(VERSION 3.0.2)
2+
project(aruco_gazebo)
3+
4+
find_package(catkin REQUIRED COMPONENTS
5+
rospy
6+
vision_msgs
7+
)
8+
9+
include_directories(
10+
${catkin_INCLUDE_DIRS}
11+
)

aruco_gazebo/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# aruco_gazebo
2+
An emulator for aruco_detect that uses gazebo pose data instead of image processing to reduce cpu load and work around aliasing problems.
3+
4+
In an effort to provide as much of a drop in replacement as possible most of the launch file include params remain the same.
5+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!-- Run the aruco_gazebo node -->
2+
<launch>
3+
<!-- namespace for camera input -->
4+
<arg name="camera" default="raspicam_node"/>
5+
<arg name="image" default="image"/>
6+
<arg name="transport" default="compressed"/>
7+
<arg name="camera_tf_frame" default="raspicam"/>
8+
<arg name="framerate" default="10"/>
9+
<arg name="fiducial_len" default="0.14"/>
10+
11+
<node pkg="aruco_gazebo" name="aruco_gazebo" type="aruco.py" output="screen" respawn="false">
12+
<param name="camera_frame" value="$(arg camera_tf_frame)" />
13+
<param name="framerate" value="$(arg framerate)" />
14+
<param name="fiducial_len" value="$(arg fiducial_len)" />
15+
<remap from="/camera/compressed" to="/$(arg camera)/$(arg image)/$(arg transport)"/>
16+
<remap from="/camera_info" to="$(arg camera)/camera_info"/>
17+
</node>
18+
</launch>

aruco_gazebo/package.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0"?>
2+
<package format="2">
3+
<name>aruco_gazebo</name>
4+
<version>0.0.0</version>
5+
<description>The aruco_gazebo package</description>
6+
7+
<maintainer email="[email protected]">Teodor Janez Podobnik</maintainer>
8+
9+
<license>TODO</license>
10+
11+
<buildtool_depend>catkin</buildtool_depend>
12+
<build_depend>rospy</build_depend>
13+
<build_depend>vision_msgs</build_depend>
14+
<build_export_depend>rospy</build_export_depend>
15+
<build_export_depend>vision_msgs</build_export_depend>
16+
<exec_depend>rospy</exec_depend>
17+
<exec_depend>vision_msgs</exec_depend>
18+
19+
<export>
20+
</export>
21+
</package>

0 commit comments

Comments
 (0)