Skip to content

Commit 8f024bb

Browse files
committed
feat: add landmark topic publishing and configurable detection outputs
1 parent db5e7ae commit 8f024bb

File tree

5 files changed

+63
-9
lines changed

5 files changed

+63
-9
lines changed

aruco-detector/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ find_package(rclcpp_components REQUIRED)
1515
find_package(OpenCV 4.5.4 REQUIRED)
1616
find_package(sensor_msgs REQUIRED)
1717
find_package(geometry_msgs REQUIRED)
18+
find_package(vortex_msgs REQUIRED)
1819
find_package(cv_bridge REQUIRED)
1920
find_package(tf2 REQUIRED)
2021
find_package(Eigen3 REQUIRED)
@@ -50,6 +51,7 @@ ament_target_dependencies(${LIB_NAME} PUBLIC
5051
rclcpp_components
5152
sensor_msgs
5253
geometry_msgs
54+
vortex_msgs
5355
tf2
5456
cv_bridge
5557
std_srvs

aruco-detector/config/aruco_detector_params.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,22 @@
33
ros__parameters:
44

55
subs:
6-
image_topic: "/image"
7-
camera_info_topic: "/camera_info"
6+
image_topic: "/cam/image_color"
7+
camera_info_topic: "/cam/camera_info"
88

99
pubs:
1010
aruco_image: "/aruco_detector/image"
1111
aruco_poses: "/aruco_detector/markers"
1212
board_pose: "/aruco_detector/board"
13+
landmarks: "/aruco_detector/landmarks"
1314

1415
logger_service_name: "/toggle_marker_logger"
1516

1617
detect_board: true # Set to true to detect aruco boards
1718
visualize: true # Set to true to draw the detected markers and board on the image
1819
log_markers: false # Set to true to log the detected markers
20+
publish_detections: false
21+
publish_landmarks: true
1922

2023
# TAC ARUCO PARAMETERS
2124
aruco:

aruco-detector/include/aruco_detector/aruco_detector_ros.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
#include <map>
1919
#include <string>
2020

21+
#include <vortex_msgs/msg/landmark.hpp>
22+
#include <vortex_msgs/msg/landmark_array.hpp>
23+
2124
#include <cv_bridge/cv_bridge.h>
2225

2326
#include "aruco_detector.hpp"
@@ -94,6 +97,10 @@ class ArucoDetectorNode : public rclcpp::Node {
9497
*/
9598
rclcpp::Publisher<geometry_msgs::msg::PoseStamped>::SharedPtr
9699
board_pose_pub_;
100+
/**
101+
* @brief Publishes detected landmarks as a LandmarkArray
102+
*/
103+
rclcpp::Publisher<vortex_msgs::msg::LandmarkArray>::SharedPtr landmark_pub_;
97104

98105
/**
99106
* @brief Initialize the detector. Sets dictionary from ros param. Also
@@ -151,6 +158,8 @@ class ArucoDetectorNode : public rclcpp::Node {
151158
bool detect_board_;
152159
bool visualize_;
153160
bool log_markers_;
161+
bool publish_detections_;
162+
bool publish_landmarks_;
154163

155164
float marker_size_;
156165
float xDist_, yDist_;

aruco-detector/package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<depend>std_srvs</depend>
1818
<depend>tf2</depend>
1919
<depend>eigen</depend>
20+
<depend>vortex_msgs</depend>
2021

2122

2223
<export>

aruco-detector/src/aruco_detector_ros.cpp

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ ArucoDetectorNode::ArucoDetectorNode(const rclcpp::NodeOptions& options)
1212
detect_board_ = this->declare_parameter<bool>("detect_board");
1313
visualize_ = this->declare_parameter<bool>("visualize");
1414
log_markers_ = this->declare_parameter<bool>("log_markers");
15+
publish_detections_ =
16+
this->declare_parameter<bool>("publish_detections", true);
17+
publish_landmarks_ =
18+
this->declare_parameter<bool>("publish_landmarks", true);
1519

1620
this->declare_parameter<float>("aruco.marker_size");
1721
this->declare_parameter<std::string>("aruco.dictionary");
@@ -46,6 +50,9 @@ ArucoDetectorNode::ArucoDetectorNode(const rclcpp::NodeOptions& options)
4650
std::string board_pose_topic =
4751
this->declare_parameter<std::string>("pubs.board_pose");
4852

53+
std::string landmarks_topic =
54+
this->declare_parameter<std::string>("pubs.landmarks");
55+
4956
marker_image_pub_ = this->create_publisher<sensor_msgs::msg::Image>(
5057
aruco_image_topic, qos_sensor_data);
5158

@@ -55,6 +62,9 @@ ArucoDetectorNode::ArucoDetectorNode(const rclcpp::NodeOptions& options)
5562
board_pose_pub_ = this->create_publisher<geometry_msgs::msg::PoseStamped>(
5663
board_pose_topic, qos_sensor_data);
5764

65+
landmark_pub_ = this->create_publisher<vortex_msgs::msg::LandmarkArray>(
66+
landmarks_topic, qos_sensor_data);
67+
5868
std::string logger_service_name =
5969
this->declare_parameter<std::string>("logger_service_name");
6070

@@ -154,6 +164,7 @@ void ArucoDetectorNode::imageCallback(
154164
}
155165
cv::Mat input_image;
156166
cv::Mat input_image_gray;
167+
vortex_msgs::msg::LandmarkArray landmark_array;
157168
try {
158169
auto cv_ptr =
159170
cv_bridge::toCvCopy(msg, sensor_msgs::image_encodings::BGR8);
@@ -201,6 +212,20 @@ void ArucoDetectorNode::imageCallback(
201212
msg->header);
202213
board_pose_pub_->publish(pose_msg);
203214

215+
vortex_msgs::msg::Landmark board_landmark;
216+
board_landmark.header = msg->header;
217+
board_landmark.type = vortex_msgs::msg::Landmark::ARUCO_BOARD;
218+
board_landmark.subtype =
219+
vortex_msgs::msg::Landmark::ARUCO_BOARD_CAMERA;
220+
221+
geometry_msgs::msg::PoseWithCovariance board_pose_cov;
222+
board_pose_cov.pose = pose_msg.pose;
223+
std::fill(board_pose_cov.covariance.begin(),
224+
board_pose_cov.covariance.end(), 0.0);
225+
board_landmark.pose = board_pose_cov;
226+
227+
landmark_array.landmarks.push_back(board_landmark);
228+
204229
if (visualize_) {
205230
float length =
206231
cv::norm(board_->objPoints[0][0] - board_->objPoints[0][1]);
@@ -221,9 +246,8 @@ void ArucoDetectorNode::imageCallback(
221246
geometry_msgs::msg::PoseArray pose_array;
222247

223248
for (size_t i = 0; i < marker_ids.size(); i++) {
249+
int id = marker_ids[i];
224250
if (log_markers_) {
225-
int id = marker_ids[i];
226-
227251
// id 0 is blacklisted, too many false positives
228252
if (id == 0) {
229253
continue;
@@ -233,17 +257,32 @@ void ArucoDetectorNode::imageCallback(
233257
log_marker_ids(id, time);
234258
}
235259

236-
cv::Vec3d rvec = rvecs[i];
237-
cv::Vec3d tvec = tvecs[i];
238-
tf2::Quaternion quat = rvec_to_quat(rvec);
260+
const cv::Vec3d& rvec = rvecs[i];
261+
const cv::Vec3d& tvec = tvecs[i];
262+
const tf2::Quaternion quat = rvec_to_quat(rvec);
239263

240264
auto pose_msg = cv_pose_to_ros_pose_stamped(tvec, quat, msg->header);
241265
pose_array.poses.push_back(pose_msg.pose);
266+
267+
vortex_msgs::msg::Landmark landmark;
268+
landmark.header = msg->header;
269+
landmark.type = vortex_msgs::msg::Landmark::ARUCO_MARKER;
270+
landmark.subtype = static_cast<uint16_t>(id);
271+
geometry_msgs::msg::PoseWithCovariance pose_cov;
272+
pose_cov.pose = pose_msg.pose;
273+
std::fill(pose_cov.covariance.begin(), pose_cov.covariance.end(), 0.0);
274+
landmark.pose = pose_cov;
275+
landmark_array.landmarks.push_back(landmark);
242276
}
243277

244278
pose_array.header = msg->header;
245-
marker_pose_pub_->publish(pose_array);
246-
279+
landmark_array.header = msg->header;
280+
if (publish_detections_) {
281+
marker_pose_pub_->publish(pose_array);
282+
}
283+
if (publish_landmarks_ && !landmark_array.landmarks.empty()) {
284+
landmark_pub_->publish(landmark_array);
285+
}
247286
if (visualize_) {
248287
cv::aruco::drawDetectedMarkers(input_image, marker_corners, marker_ids);
249288
cv::aruco::drawDetectedMarkers(input_image, rejected_candidates,

0 commit comments

Comments
 (0)