ultralytics 8.2.5 New 🌟 Parking Management Solution (#10385)
Co-authored-by: UltralyticsAssistant <web@ultralytics.com> Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
This commit is contained in:
parent
156b6be8d3
commit
bc9fd45cdf
10 changed files with 451 additions and 81 deletions
|
|
@ -419,51 +419,63 @@ class Annotator:
|
|||
lineType=cv2.LINE_AA,
|
||||
)
|
||||
|
||||
def display_counts(self, counts=None, count_bg_color=(0, 0, 0), count_txt_color=(255, 255, 255)):
|
||||
### Parking management utils
|
||||
def display_objects_labels(self, im0, text, txt_color, bg_color, x_center, y_center, margin):
|
||||
"""
|
||||
Display counts on im0 with text background and border.
|
||||
Display the bounding boxes labels in parking management app.
|
||||
|
||||
Args:
|
||||
counts (str): objects count data
|
||||
count_bg_color (RGB Color): counts highlighter color
|
||||
count_txt_color (RGB Color): counts display color
|
||||
im0 (ndarray): inference image
|
||||
text (str): object/class name
|
||||
txt_color (bgr color): display color for text foreground
|
||||
bg_color (bgr color): display color for text background
|
||||
x_center (float): x position center point for bounding box
|
||||
y_center (float): y position center point for bounding box
|
||||
margin (int): gap between text and rectangle for better display
|
||||
"""
|
||||
|
||||
tl = self.tf or round(0.002 * (self.im.shape[0] + self.im.shape[1]) / 2) + 1
|
||||
tf = max(tl - 1, 1)
|
||||
text_size = cv2.getTextSize(text, 0, fontScale=self.sf, thickness=self.tf)[0]
|
||||
text_x = x_center - text_size[0] // 2
|
||||
text_y = y_center + text_size[1] // 2
|
||||
|
||||
t_sizes = [cv2.getTextSize(str(count), 0, fontScale=self.sf, thickness=self.tf)[0] for count in counts]
|
||||
rect_x1 = text_x - margin
|
||||
rect_y1 = text_y - text_size[1] - margin
|
||||
rect_x2 = text_x + text_size[0] + margin
|
||||
rect_y2 = text_y + margin
|
||||
cv2.rectangle(im0, (rect_x1, rect_y1), (rect_x2, rect_y2), bg_color, -1)
|
||||
cv2.putText(im0, text, (text_x, text_y), 0, self.sf, txt_color, self.tf, lineType=cv2.LINE_AA)
|
||||
|
||||
max_text_width = max([size[0] for size in t_sizes])
|
||||
max_text_height = max([size[1] for size in t_sizes])
|
||||
# Parking lot and object counting app
|
||||
def display_analytics(self, im0, text, txt_color, bg_color, margin):
|
||||
"""
|
||||
Display the overall statistics for parking lots
|
||||
Args:
|
||||
im0 (ndarray): inference image
|
||||
text (dict): labels dictionary
|
||||
txt_color (bgr color): display color for text foreground
|
||||
bg_color (bgr color): display color for text background
|
||||
margin (int): gap between text and rectangle for better display
|
||||
"""
|
||||
|
||||
text_x = self.im.shape[1] - int(self.im.shape[1] * 0.025 + max_text_width)
|
||||
text_y = int(self.im.shape[0] * 0.025)
|
||||
horizontal_gap = int(im0.shape[1] * 0.02)
|
||||
vertical_gap = int(im0.shape[0] * 0.01)
|
||||
|
||||
for i, count in enumerate(counts):
|
||||
text_x_pos = text_x
|
||||
text_y_pos = text_y + i * (max_text_height + 25 * tf)
|
||||
text_y_offset = 0
|
||||
|
||||
# Draw the border
|
||||
cv2.rectangle(
|
||||
self.im,
|
||||
(text_x_pos - (10 * tf), text_y_pos - (10 * tf)),
|
||||
(text_x_pos + max_text_width + (10 * tf), text_y_pos + max_text_height + (10 * tf)),
|
||||
count_bg_color,
|
||||
-1,
|
||||
)
|
||||
|
||||
# Draw the count text
|
||||
for label, value in text.items():
|
||||
txt = f"{label}: {value}"
|
||||
text_size = cv2.getTextSize(txt, 0, int(self.sf * 1.5), int(self.tf * 1.5))[0]
|
||||
text_x = im0.shape[1] - text_size[0] - margin * 2 - horizontal_gap
|
||||
text_y = text_y_offset + text_size[1] + margin * 2 + vertical_gap
|
||||
rect_x1 = text_x - margin * 2
|
||||
rect_y1 = text_y - text_size[1] - margin * 2
|
||||
rect_x2 = text_x + text_size[0] + margin * 2
|
||||
rect_y2 = text_y + margin * 2
|
||||
cv2.rectangle(im0, (rect_x1, rect_y1), (rect_x2, rect_y2), bg_color, -1)
|
||||
cv2.putText(
|
||||
self.im,
|
||||
str(count),
|
||||
(text_x_pos, text_y_pos + max_text_height),
|
||||
0,
|
||||
fontScale=self.sf,
|
||||
color=count_txt_color,
|
||||
thickness=self.tf,
|
||||
lineType=cv2.LINE_AA,
|
||||
im0, txt, (text_x, text_y), 0, int(self.sf * 1.5), txt_color, int(self.tf * 1.5), lineType=cv2.LINE_AA
|
||||
)
|
||||
text_y_offset = rect_y2
|
||||
|
||||
@staticmethod
|
||||
def estimate_pose_angle(a, b, c):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue