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:
Muhammad Rizwan Munawar 2024-04-29 13:58:12 +05:00 committed by GitHub
parent 156b6be8d3
commit bc9fd45cdf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 451 additions and 81 deletions

View file

@ -190,9 +190,7 @@ class Heatmap:
for box, cls, track_id in zip(self.boxes, self.clss, self.track_ids):
# Store class info
if self.names[cls] not in self.class_wise_count:
if len(self.names[cls]) > 5:
self.names[cls] = self.names[cls][:5]
self.class_wise_count[self.names[cls]] = {"in": 0, "out": 0}
self.class_wise_count[self.names[cls]] = {"IN": 0, "OUT": 0}
if self.shape == "circle":
center = (int((box[0] + box[2]) // 2), int((box[1] + box[3]) // 2))
@ -225,10 +223,10 @@ class Heatmap:
if (box[0] - prev_position[0]) * (self.counting_region.centroid.x - prev_position[0]) > 0:
self.in_counts += 1
self.class_wise_count[self.names[cls]]["in"] += 1
self.class_wise_count[self.names[cls]]["IN"] += 1
else:
self.out_counts += 1
self.class_wise_count[self.names[cls]]["out"] += 1
self.class_wise_count[self.names[cls]]["OUT"] += 1
# Count objects using line
elif len(self.count_reg_pts) == 2:
@ -239,10 +237,10 @@ class Heatmap:
if (box[0] - prev_position[0]) * (self.counting_region.centroid.x - prev_position[0]) > 0:
self.in_counts += 1
self.class_wise_count[self.names[cls]]["in"] += 1
self.class_wise_count[self.names[cls]]["IN"] += 1
else:
self.out_counts += 1
self.class_wise_count[self.names[cls]]["out"] += 1
self.class_wise_count[self.names[cls]]["OUT"] += 1
else:
for box, cls in zip(self.boxes, self.clss):
@ -264,28 +262,21 @@ class Heatmap:
heatmap_normalized = cv2.normalize(self.heatmap, None, 0, 255, cv2.NORM_MINMAX)
heatmap_colored = cv2.applyColorMap(heatmap_normalized.astype(np.uint8), self.colormap)
label = "Ultralytics Analytics \t"
labels_dict = {}
for key, value in self.class_wise_count.items():
if value["in"] != 0 or value["out"] != 0:
if value["IN"] != 0 or value["OUT"] != 0:
if not self.view_in_counts and not self.view_out_counts:
label = None
continue
elif not self.view_in_counts:
label += f"{str.capitalize(key)}: IN {value['in']} \t"
labels_dict[str.capitalize(key)] = f"OUT {value['OUT']}"
elif not self.view_out_counts:
label += f"{str.capitalize(key)}: OUT {value['out']} \t"
labels_dict[str.capitalize(key)] = f"IN {value['IN']}"
else:
label += f"{str.capitalize(key)}: IN {value['in']} OUT {value['out']} \t"
labels_dict[str.capitalize(key)] = f"IN {value['IN']} OUT {value['OUT']}"
label = label.rstrip()
label = label.split("\t")
if self.count_reg_pts is not None and label is not None:
self.annotator.display_counts(
counts=label,
count_txt_color=self.count_txt_color,
count_bg_color=self.count_bg_color,
)
if labels_dict is not None:
self.annotator.display_analytics(self.im0, labels_dict, self.count_txt_color, self.count_bg_color, 10)
self.im0 = cv2.addWeighted(self.im0, 1 - self.heatmap_alpha, heatmap_colored, self.heatmap_alpha, 0)