ultralytics 8.0.239 Ultralytics Actions and hub-sdk adoption (#7431)

Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>
Co-authored-by: UltralyticsAssistant <web@ultralytics.com>
Co-authored-by: Burhan <62214284+Burhan-Q@users.noreply.github.com>
Co-authored-by: Kayzwer <68285002+Kayzwer@users.noreply.github.com>
This commit is contained in:
Glenn Jocher 2024-01-10 03:16:08 +01:00 committed by GitHub
parent e795277391
commit fe27db2f6e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
139 changed files with 6870 additions and 5125 deletions

View file

@ -7,7 +7,7 @@ import cv2
from ultralytics.utils.checks import check_imshow, check_requirements
from ultralytics.utils.plotting import Annotator, colors
check_requirements('shapely>=2.0.0')
check_requirements("shapely>=2.0.0")
from shapely.geometry import LineString, Point, Polygon
@ -56,22 +56,24 @@ class ObjectCounter:
# Check if environment support imshow
self.env_check = check_imshow(warn=True)
def set_args(self,
classes_names,
reg_pts,
count_reg_color=(255, 0, 255),
line_thickness=2,
track_thickness=2,
view_img=False,
view_in_counts=True,
view_out_counts=True,
draw_tracks=False,
count_txt_thickness=2,
count_txt_color=(0, 0, 0),
count_color=(255, 255, 255),
track_color=(0, 255, 0),
region_thickness=5,
line_dist_thresh=15):
def set_args(
self,
classes_names,
reg_pts,
count_reg_color=(255, 0, 255),
line_thickness=2,
track_thickness=2,
view_img=False,
view_in_counts=True,
view_out_counts=True,
draw_tracks=False,
count_txt_thickness=2,
count_txt_color=(0, 0, 0),
count_color=(255, 255, 255),
track_color=(0, 255, 0),
region_thickness=5,
line_dist_thresh=15,
):
"""
Configures the Counter's image, bounding box line thickness, and counting region points.
@ -101,16 +103,16 @@ class ObjectCounter:
# Region and line selection
if len(reg_pts) == 2:
print('Line Counter Initiated.')
print("Line Counter Initiated.")
self.reg_pts = reg_pts
self.counting_region = LineString(self.reg_pts)
elif len(reg_pts) == 4:
print('Region Counter Initiated.')
print("Region Counter Initiated.")
self.reg_pts = reg_pts
self.counting_region = Polygon(self.reg_pts)
else:
print('Invalid Region points provided, region_points can be 2 or 4')
print('Using Line Counter Now')
print("Invalid Region points provided, region_points can be 2 or 4")
print("Using Line Counter Now")
self.counting_region = LineString(self.reg_pts)
self.names = classes_names
@ -164,8 +166,9 @@ class ObjectCounter:
# Extract tracks
for box, track_id, cls in zip(boxes, track_ids, clss):
self.annotator.box_label(box, label=str(track_id) + ':' + self.names[cls],
color=colors(int(cls), True)) # Draw bounding box
self.annotator.box_label(
box, label=str(track_id) + ":" + self.names[cls], color=colors(int(cls), True)
) # Draw bounding box
# Draw Tracks
track_line = self.track_history[track_id]
@ -175,9 +178,9 @@ class ObjectCounter:
# Draw track trails
if self.draw_tracks:
self.annotator.draw_centroid_and_tracks(track_line,
color=self.track_color,
track_thickness=self.track_thickness)
self.annotator.draw_centroid_and_tracks(
track_line, color=self.track_color, track_thickness=self.track_thickness
)
# Count objects
if len(self.reg_pts) == 4:
@ -199,8 +202,8 @@ class ObjectCounter:
else:
self.in_counts += 1
incount_label = 'In Count : ' + f'{self.in_counts}'
outcount_label = 'OutCount : ' + f'{self.out_counts}'
incount_label = "In Count : " + f"{self.in_counts}"
outcount_label = "OutCount : " + f"{self.out_counts}"
# Display counts based on user choice
counts_label = None
@ -211,24 +214,27 @@ class ObjectCounter:
elif not self.view_out_counts:
counts_label = incount_label
else:
counts_label = incount_label + ' ' + outcount_label
counts_label = incount_label + " " + outcount_label
if counts_label is not None:
self.annotator.count_labels(counts=counts_label,
count_txt_size=self.count_txt_thickness,
txt_color=self.count_txt_color,
color=self.count_color)
self.annotator.count_labels(
counts=counts_label,
count_txt_size=self.count_txt_thickness,
txt_color=self.count_txt_color,
color=self.count_color,
)
def display_frames(self):
"""Display frame."""
if self.env_check:
cv2.namedWindow('Ultralytics YOLOv8 Object Counter')
cv2.namedWindow("Ultralytics YOLOv8 Object Counter")
if len(self.reg_pts) == 4: # only add mouse event If user drawn region
cv2.setMouseCallback('Ultralytics YOLOv8 Object Counter', self.mouse_event_for_region,
{'region_points': self.reg_pts})
cv2.imshow('Ultralytics YOLOv8 Object Counter', self.im0)
cv2.setMouseCallback(
"Ultralytics YOLOv8 Object Counter", self.mouse_event_for_region, {"region_points": self.reg_pts}
)
cv2.imshow("Ultralytics YOLOv8 Object Counter", self.im0)
# Break Window
if cv2.waitKey(1) & 0xFF == ord('q'):
if cv2.waitKey(1) & 0xFF == ord("q"):
return
def start_counting(self, im0, tracks):
@ -254,5 +260,5 @@ class ObjectCounter:
return self.im0
if __name__ == '__main__':
if __name__ == "__main__":
ObjectCounter()