Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
parkpow
GitHub Repository: parkpow/deep-license-plate-recognition
Path: blob/master/video-editor/utils.py
641 views
1
import cv2
2
import numpy as np
3
4
5
def draw_bounding_box_on_image(
6
image, ymin, xmin, ymax, xmax, display_str, color=(255, 234, 32), thickness=4
7
):
8
(left, right, top, bottom) = (xmin, xmax, ymin, ymax)
9
pts = np.array(
10
[[left, top], [left, bottom], [right, bottom], [right, top]], np.int32
11
)
12
pts = pts.reshape((-1, 1, 2))
13
cv2.polylines(image, [pts], True, color, thickness)
14
font = cv2.FONT_HERSHEY_SIMPLEX
15
font_scale = 0.7
16
thickness_text = 2
17
text_size, baseline = cv2.getTextSize(display_str, font, font_scale, thickness_text)
18
text_width, text_height = text_size
19
margin = np.ceil(0.2 * text_height)
20
thickness_fill = -1
21
start_point = (int(left - margin), int(top - text_height - 2 * margin))
22
end_point = (int(left + text_width + 2 * margin), int(top))
23
24
cv2.rectangle(image, start_point, end_point, color, thickness_fill)
25
26
org = (int(left + margin), int(top - text_height + 3 * margin))
27
cv2.putText(
28
image,
29
display_str,
30
org,
31
font,
32
font_scale,
33
(255, 255, 255),
34
thickness_text,
35
cv2.LINE_AA,
36
)
37
38