Skip to content
Open
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
14 changes: 9 additions & 5 deletions nanoowl/tree_drawing.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ def draw_tree_output(image, output: TreeOutput, tree: Tree, draw_text=True, num_
detections = output.detections
is_pil = not isinstance(image, np.ndarray)
if is_pil:
image = np.asarray(image)
image_np = np.asarray(image).copy()
else:
image_np = image.copy()

font = cv2.FONT_HERSHEY_SIMPLEX
font_scale = 0.75
colors = get_colors(num_colors)
Expand All @@ -50,7 +53,7 @@ def draw_tree_output(image, output: TreeOutput, tree: Tree, draw_text=True, num_
pt1 = (box[2], box[3])
box_depth = min(label_depths[i] for i in detection.labels)
cv2.rectangle(
image,
image_np,
pt0,
pt1,
colors[box_depth % num_colors],
Expand All @@ -62,7 +65,7 @@ def draw_tree_output(image, output: TreeOutput, tree: Tree, draw_text=True, num_
for label in detection.labels:
label_text = label_map[label]
cv2.putText(
image,
image_np,
label_text,
(box[0] + offset_x, box[1] + offset_y),
font,
Expand All @@ -73,5 +76,6 @@ def draw_tree_output(image, output: TreeOutput, tree: Tree, draw_text=True, num_
)
offset_y += 18
if is_pil:
image = PIL.Image.fromarray(image)
return image
return PIL.Image.fromarray(image_np)
else:
return image_np