fix drawing script
Browse files
app.py
CHANGED
@@ -50,18 +50,24 @@ def detect(image_path):
|
|
50 |
|
51 |
|
52 |
# 01. DRAW BOUNDING BOX OF OBJECT
|
53 |
-
|
|
|
|
|
|
|
|
|
|
|
54 |
image = cv2.rectangle(img=image,
|
55 |
pt1=start_box,
|
56 |
pt2=end_box,
|
57 |
color=ENTITIES_COLORS[cls],
|
58 |
-
thickness
|
59 |
|
60 |
# 02. DRAW LABEL
|
61 |
text = cls + " " + str(detection_class_conf)
|
62 |
# Get text dimensions to draw wrapping box
|
63 |
-
font_thickness =
|
64 |
-
(
|
|
|
65 |
# Draw wrapping box for text
|
66 |
image = cv2.rectangle(img=image,
|
67 |
pt1=(start_box[0], start_box[1] - text_h - BOX_PADDING*2),
|
@@ -70,7 +76,8 @@ def detect(image_path):
|
|
70 |
thickness=-1)
|
71 |
# Put class name on image
|
72 |
start_text = (start_box[0] + BOX_PADDING, start_box[1] - BOX_PADDING)
|
73 |
-
image = cv2.putText(img=image, text=text, org=start_text, fontFace=0, color=(255,255,255), fontScale=
|
|
|
74 |
|
75 |
return image
|
76 |
|
|
|
50 |
|
51 |
|
52 |
# 01. DRAW BOUNDING BOX OF OBJECT
|
53 |
+
# Adjust the scale factors for bounding box and label
|
54 |
+
box_scale_factor = 0.001 # Reduce this value to make the bounding box thinner
|
55 |
+
label_scale_factor = 0.5 # Reduce this value to make the label smaller
|
56 |
+
|
57 |
+
# 01. DRAW BOUNDING BOX OF OBJECT
|
58 |
+
line_thickness = round(box_scale_factor * (image.shape[0] + image.shape[1]) / 2) + 1
|
59 |
image = cv2.rectangle(img=image,
|
60 |
pt1=start_box,
|
61 |
pt2=end_box,
|
62 |
color=ENTITIES_COLORS[cls],
|
63 |
+
thickness=line_thickness) # Draw the box with predefined colors
|
64 |
|
65 |
# 02. DRAW LABEL
|
66 |
text = cls + " " + str(detection_class_conf)
|
67 |
# Get text dimensions to draw wrapping box
|
68 |
+
font_thickness = max(line_thickness - 1, 1)
|
69 |
+
(font_scale_w, font_scale_h) = (line_thickness * label_scale_factor, line_thickness * label_scale_factor)
|
70 |
+
(text_w, text_h), _ = cv2.getTextSize(text=text, fontFace=2, fontScale=font_scale_w, thickness=font_thickness)
|
71 |
# Draw wrapping box for text
|
72 |
image = cv2.rectangle(img=image,
|
73 |
pt1=(start_box[0], start_box[1] - text_h - BOX_PADDING*2),
|
|
|
76 |
thickness=-1)
|
77 |
# Put class name on image
|
78 |
start_text = (start_box[0] + BOX_PADDING, start_box[1] - BOX_PADDING)
|
79 |
+
image = cv2.putText(img=image, text=text, org=start_text, fontFace=0, color=(255,255,255), fontScale=font_scale_w, thickness=font_thickness)
|
80 |
+
|
81 |
|
82 |
return image
|
83 |
|