Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
This commit is contained in:
Ultralytics Assistant 2024-09-26 00:41:38 +02:00 committed by GitHub
parent 4bcc80c646
commit 38e95f33a5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 30 additions and 31 deletions

View file

@ -176,22 +176,24 @@ class ObjectCounter:
# Count objects using line
elif len(self.reg_pts) == 2:
if prev_position is not None and track_id not in self.count_ids:
# Check if the object's movement segment intersects the counting line
if LineString([(prev_position[0], prev_position[1]), (box[0], box[1])]).intersects(
if (
prev_position is not None
and track_id not in self.count_ids
and LineString([(prev_position[0], prev_position[1]), (box[0], box[1])]).intersects(
self.counting_line_segment
):
self.count_ids.append(track_id)
)
):
self.count_ids.append(track_id)
# Determine the direction of movement (IN or OUT)
dx = (box[0] - prev_position[0]) * (self.counting_region.centroid.x - prev_position[0])
dy = (box[1] - prev_position[1]) * (self.counting_region.centroid.y - prev_position[1])
if dx > 0 and dy > 0:
self.in_counts += 1
self.class_wise_count[self.names[cls]]["IN"] += 1
else:
self.out_counts += 1
self.class_wise_count[self.names[cls]]["OUT"] += 1
# Determine the direction of movement (IN or OUT)
dx = (box[0] - prev_position[0]) * (self.counting_region.centroid.x - prev_position[0])
dy = (box[1] - prev_position[1]) * (self.counting_region.centroid.y - prev_position[1])
if dx > 0 and dy > 0:
self.in_counts += 1
self.class_wise_count[self.names[cls]]["IN"] += 1
else:
self.out_counts += 1
self.class_wise_count[self.names[cls]]["OUT"] += 1
labels_dict = {}

View file

@ -128,14 +128,13 @@ class ParkingPtsSelection:
rg_data = [] # regions data
for box in self.rg_data:
rs_box = [] # rescaled box list
for x, y in box:
rs_box.append(
(
int(x * self.imgw / self.canvas.winfo_width()), # width scaling
int(y * self.imgh / self.canvas.winfo_height()),
)
) # height scaling
rs_box = [
(
int(x * self.imgw / self.canvas.winfo_width()), # width scaling
int(y * self.imgh / self.canvas.winfo_height()), # height scaling
)
for x, y in box
]
rg_data.append({"points": rs_box})
with open("bounding_boxes.json", "w") as f:
json.dump(rg_data, f, indent=4)