Skip to content

Commit 6ce2015

Browse files
committed
use cv2.putText if font is not found
1 parent 7d5d682 commit 6ce2015

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

jsk_perception/node_scripts/draw_rects.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,19 +148,29 @@ def draw_rects_callback(self, img_msg, rects_msg, class_msg=None):
148148
color=color.tolist(),
149149
thickness=self.rect_boldness,
150150
lineType=cv2.LINE_AA)
151-
if self.use_classification_result and osp.exists(self.font_path):
151+
if self.use_classification_result:
152152
text = class_msg.label_names[i]
153153
if self.show_proba and len(class_msg.label_proba) > i:
154154
text += ' ({0:.2f})'.format(class_msg.label_proba[i])
155155
pos_x = int(rect.x * self.resolution_factor)
156156
pos_y = int(rect.y * self.resolution_factor)
157157
pos = (pos_x, pos_y)
158-
img = put_text_to_image(
159-
img, text, pos, self.font_path,
160-
self.label_size,
161-
color=(255, 255, 255),
162-
background_color=tuple(color),
163-
offset_x=self.rect_boldness / 2.0)
158+
if osp.exists(self.font_path):
159+
img = put_text_to_image(
160+
img, text, pos, self.font_path,
161+
self.label_size,
162+
color=(255, 255, 255),
163+
background_color=tuple(color),
164+
offset_x=self.rect_boldness / 2.0)
165+
else:
166+
pt1=(int(pos_x), int(pos_y - 16))
167+
pt2=(int(pos_x + rect.width * self.resolution_factor)-10, int(pos_y))
168+
cv2.rectangle(img, pt1, pt2,
169+
color.tolist(), -1)
170+
cv2.putText(img, text, (pos_x, pos_y - 4),
171+
cv2.FONT_HERSHEY_PLAIN,
172+
fontScale=1, color=(255, 255, 255),
173+
thickness=1, lineType=cv2.LINE_AA)
164174
if self.transport_hint == 'compressed':
165175
viz_msg = sensor_msgs.msg.CompressedImage()
166176
viz_msg.format = "jpeg"

0 commit comments

Comments
 (0)