Skip to content

Commit

Permalink
add spacing
Browse files Browse the repository at this point in the history
  • Loading branch information
Louis-Dupont committed Aug 10, 2023
1 parent 8b3d7de commit 0e9153a
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@ def draw_label(image: np.ndarray, label: str, confidence: float) -> np.ndarray:
fontScale = 0.8
thickness = 1

# Define additional spacing between the two lines
line_spacing = 5

# Determine the size of the label and confidence text
label_size = cv2.getTextSize(label, cv2.FONT_HERSHEY_SIMPLEX, fontScale, thickness)[0]
confidence_size = cv2.getTextSize(confidence_str, cv2.FONT_HERSHEY_SIMPLEX, fontScale, thickness)[0]

# Determine the size of the bounding rectangle
text_width = max(label_size[0], confidence_size[0])
text_height = label_size[1] + confidence_size[1] + thickness * 3
text_height = label_size[1] + confidence_size[1] + thickness * 3 + line_spacing

# Calculate the position to draw the label, centered horizontally and at the top
start_x = (image.shape[1] - text_width) // 2
Expand All @@ -38,7 +41,7 @@ def draw_label(image: np.ndarray, label: str, confidence: float) -> np.ndarray:
alpha = 0.6
cv2.addWeighted(overlay, alpha, image, 1 - alpha, 0, image)

# Center the label and confidence text within the bounding rectangle
# Center the label and confidence text within the bounding rectangle, with additional spacing
text_color = (0, 0, 0) # Black
cv2.putText(
image,
Expand All @@ -53,7 +56,7 @@ def draw_label(image: np.ndarray, label: str, confidence: float) -> np.ndarray:
cv2.putText(
image,
confidence_str,
(start_x + (text_width - confidence_size[0]) // 2, start_y + label_size[1] + confidence_size[1] + thickness),
(start_x + (text_width - confidence_size[0]) // 2, start_y + label_size[1] + confidence_size[1] + thickness + line_spacing),
cv2.FONT_HERSHEY_SIMPLEX,
fontScale,
text_color,
Expand Down

0 comments on commit 0e9153a

Please sign in to comment.