Closed uma-oo closed 1 year ago
@uma-oo were you able to run it with YoloV8?
@uma-oo I fixed your code. Had to change:
coordinates = list((int(x1), int(x2), int(w), int(h)))
to:
coordinates = list((int(x1), int(y1), int(w), int(h)))
Also, I removed some lines. Below is the full example:
import cv2
from ultralytics import YOLO
from deep_sort_realtime.deepsort_tracker import DeepSort
object_tracker = DeepSort()
cap = cv2.VideoCapture(
"/Users/3i-a1-2021-15/Developer/projects/pivo-tracking/videos/2.mp4"
)
model = YOLO("yolov8n.pt")
classes = model.names
while cap.isOpened():
ret, image = cap.read()
if ret:
results = model(image)
for result in results:
detections = []
boxes = result.boxes
for r in result.boxes.data.tolist():
x1, y1, x2, y2 = r[:4]
w, h = x2 - x1, y2 - y1
coordinates = list((int(x1), int(y1), int(w), int(h)))
conf = r[4]
clsId = int(r[5])
cls = classes[clsId]
if cls == "person":
detections.append((coordinates, conf, cls))
print("detections: ", detections)
tracks = object_tracker.update_tracks(detections, frame=image)
for track in tracks:
if not track.is_confirmed():
continue
track_id = track.track_id
bbox = track.to_ltrb()
cv2.rectangle(
image,
(int(bbox[0]), int(bbox[1])),
(int(bbox[2]), int(bbox[3])),
color=(0, 0, 255),
thickness=4,
)
cv2.putText(
image,
"ID: " + str(track_id),
(int(bbox[0]), int(bbox[1]) - 10),
cv2.FONT_HERSHEY_SIMPLEX,
2,
(0, 255, 0),
2,
)
cv2.imshow("Image", image)
if cv2.waitKey(1) & 0xFF == ord("q"):
break
cap.release()
cv2.destroyAllWindows()
Hi there, I'm trying to impement tracking for a specific use case, but before i was just trying to make the tracking work with yolov8 for a video , here's the whole code :
I'm too much confused because i'm sure of the input format i give to the tracker , which is like this : detections: [([495, 794, 299, 167], 0.9417956, 'bowl'), ([111, 921, 810, 597], 0.9322504, 'cat'), ([75, 1126, 1050, 92], 0.33967713, 'dining table')] I think this is the right format of input we should give, i tried also to initialize the tracker with only the max_age hyperparameter only but i still encounter the same error :
please any help !!!!