From 82f225aa364d2f4540f8fe8cde1d74f50c4c5e75 Mon Sep 17 00:00:00 2001 From: Thomas Reidemeister Date: Tue, 30 Jan 2024 15:42:29 -0500 Subject: [PATCH 1/2] Modified topics to bottlenose published topics --- detection_visualizer/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/detection_visualizer/__init__.py b/detection_visualizer/__init__.py index 24c0006..76b9ff6 100644 --- a/detection_visualizer/__init__.py +++ b/detection_visualizer/__init__.py @@ -40,10 +40,10 @@ def __init__(self): reliability=QoSReliabilityPolicy.RELIABLE, depth=1) - self._image_pub = self.create_publisher(Image, '~/dbg_images', output_image_qos) + self._image_pub = self.create_publisher(Image, '/dbg_images', output_image_qos) - self._image_sub = message_filters.Subscriber(self, Image, '~/images') - self._detections_sub = message_filters.Subscriber(self, Detection2DArray, '~/detections') + self._image_sub = message_filters.Subscriber(self, Image, '/image_color') + self._detections_sub = message_filters.Subscriber(self, Detection2DArray, '/detections') self._synchronizer = message_filters.ApproximateTimeSynchronizer( (self._image_sub, self._detections_sub), 5, 0.01) From 31ca33e22cb28141edfd68695345eaf8b78c042a Mon Sep 17 00:00:00 2001 From: Thomas Reidemeister Date: Wed, 31 Jan 2024 16:01:46 -0500 Subject: [PATCH 2/2] foxy support and bottlenose topics --- README.md | 4 ++-- detection_visualizer/__init__.py | 22 ++++++++++++++++------ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 7f36ce1..d3ad469 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,8 @@ The output topic can be visualized in rviz. # Topics -* `~/images` (Type `sensor_msgs/msg/Image`) - Input topic with images that have been given to a computer vision node -* `~/detections` (Type `vision_msgs/msg/Detection2DArray`) - Input topic with detections on the given image +* `/image_color` (Type `sensor_msgs/msg/Image`) - Input topic with images that have been given to a computer vision node +* `/detections` (Type `vision_msgs/msg/Detection2DArray`) - Input topic with detections on the given image * `~/dbg_image` (Type `sensor_msgs/msg/Image`) - Output topic which has bounding boxes drawn on it It is assumed the image message and detections message have identical timestamps. diff --git a/detection_visualizer/__init__.py b/detection_visualizer/__init__.py index 76b9ff6..d9d9be7 100644 --- a/detection_visualizer/__init__.py +++ b/detection_visualizer/__init__.py @@ -57,16 +57,26 @@ def on_detections(self, image_msg, detections_msg): max_class = None max_score = 0.0 for result in detection.results: - hypothesis = result.hypothesis - if hypothesis.score > max_score: - max_score = hypothesis.score - max_class = hypothesis.class_id + if hasattr(result, 'hypothesis'): # humble + hypothesis = result.hypothesis + if hypothesis.score > max_score: + max_score = hypothesis.score + max_class = hypothesis.class_id + else: # foxy fallback + score = result.score + if score > max_score: + max_score = score + max_class = result.id if max_class is None: print("Failed to find class with highest score", file=sys.stderr) return - cx = detection.bbox.center.position.x - cy = detection.bbox.center.position.y + if hasattr(detection.bbox.center, 'position'): # humble + cx = detection.bbox.center.position.x + cy = detection.bbox.center.position.y + else: # foxy fallback + cx = detection.bbox.center.x + cy = detection.bbox.center.y sx = detection.bbox.size_x sy = detection.bbox.size_y