Skip to content

Commit

Permalink
Merge pull request #4 from gbr1/foxy-dev
Browse files Browse the repository at this point in the history
0.0.4 - fixes centroids and center visualization
  • Loading branch information
gbr1 authored Sep 29, 2022
2 parents 367e486 + 1a64602 commit 497118b
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 6 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

ROS2 wrapper for Edge Impulse on Linux.

![ezgif-4-3cda6ac695](https://user-images.githubusercontent.com/9216366/193153736-fccd9451-2277-42f2-8141-6027a10f0245.gif)


## 1. Topics

Expand All @@ -15,6 +17,7 @@ ROS2 wrapper for Edge Impulse on Linux.
- `frame_id` (**string**), _"base_link"_, frame id of output topics
- `model.filepath` (**string**), _""_, absolute filepath to .eim file
- `show.overlay` (**bool**), _true_, show bounding boxes on output image
- `show.center` (**bool**), _false_, show centroids on output image
- `show.labels` (**bool**), _true_, show labels on bounding boxes,
- `show.classification_info` (**bool**), _true_, show the attendibility (0-1) of the prediction

Expand Down
Binary file modified edgeimpulse_ros/__pycache__/image_classification.cpython-38.pyc
Binary file not shown.
23 changes: 19 additions & 4 deletions edgeimpulse_ros/image_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ def init_parameters(self):
self.declare_parameter('show.overlay', True)
self.show_overlay = self.get_parameter('show.overlay').get_parameter_value().bool_value

self.declare_parameter('show.center', False)
self.show_center = self.get_parameter('show.center').get_parameter_value().bool_value


self.declare_parameter('show.labels',True)
self.show_labels_on_image = self.get_parameter('show.labels').get_parameter_value().bool_value

Expand All @@ -94,6 +98,7 @@ def parameters_callback(self):
self.show_labels_on_image = self.get_parameter('show.labels').get_parameter_value().bool_value
self.show_extra_classification_info = self.get_parameter('show.classification_info').get_parameter_value().bool_value
self.show_overlay = self.get_parameter('show.overlay').get_parameter_value().bool_value
self.show_center= self.get_parameter('show.center').get_parameter_value().bool_value



Expand Down Expand Up @@ -141,6 +146,11 @@ def classify_callback(self):
self.get_logger().info('Found %d bounding boxes (%d ms.)' % (len(res["result"]["bounding_boxes"]), res['timing']['dsp'] + res['timing']['classification']))

for bb in res["result"]["bounding_boxes"]:

centerX=bb['x']+int(bb['width']/2)
centerY=bb['y']+int(bb['height']/2)
center=(centerX, centerY)

result_msg = Detection2D()
result_msg.header.stamp = time_now
result_msg.header.frame_id = self.frame_id
Expand All @@ -149,13 +159,13 @@ def classify_callback(self):
obj_hyp = ObjectHypothesisWithPose()
obj_hyp.id = bb['label'] #str(self.ei_classifier.labels.index(bb['label']))
obj_hyp.score = bb['value']
obj_hyp.pose.pose.position.x = float(bb['x'])
obj_hyp.pose.pose.position.y = float(bb['y'])
obj_hyp.pose.pose.position.x = float(centerX)
obj_hyp.pose.pose.position.y = float(centerY)
result_msg.results.append(obj_hyp)

# bounding box
result_msg.bbox.center.x = float(bb['x'])
result_msg.bbox.center.y = float(bb['y'])
result_msg.bbox.center.x = float(centerX)
result_msg.bbox.center.y = float(centerY)
result_msg.bbox.size_x = float(bb['width'])
result_msg.bbox.size_y = float(bb['height'])

Expand All @@ -170,6 +180,11 @@ def classify_callback(self):
if self.show_labels_on_image:
composed_label = bb['label']+' '+str(round(bb['value'],2))
img_res = cv2.putText(img_res, composed_label, (bb['x'], bb['y']-5), cv2.FONT_HERSHEY_SIMPLEX, 0.4, (255,0,0),1)
if self.show_center:
img_res = cv2.circle(img_res, center, 3, (255, 0, 0), 1)
composed_center = '('+str(centerX)+','+str(centerY)+')'
img_res = cv2.putText(img_res, composed_center, (centerX, centerY-5), cv2.FONT_HERSHEY_SIMPLEX, 0.4, (255,0,0),1)


cropped=cv2.cvtColor(cropped, cv2.COLOR_RGB2BGR)

Expand Down
2 changes: 1 addition & 1 deletion package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>edgeimpulse_ros</name>
<version>0.0.3</version>
<version>0.0.4</version>
<description>ROS2 wrapper for Edge Impulse</description>
<maintainer email="[email protected]">gbr1</maintainer>
<license>Apache 2.0</license>
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
submodules = 'edgeimpulse_ros/submodules'
setup(
name=package_name,
version='0.0.3',
version='0.0.4',
packages=[package_name, submodules],
data_files=[
('share/ament_index/resource_index/packages',
Expand Down

0 comments on commit 497118b

Please sign in to comment.