Skip to content

SE 2601 #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
28 changes: 19 additions & 9 deletions detection_visualizer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down