Deep sort code path
xxxxxxxxxx/home/yahboom/YBAMR-COBOT-EDU-00001/soft/yolov8
As in the previous section, we can see the file path of our Deep sort from the figure below.

The following project directory code class diagram

We start the demo program. The target tracking startup file is the yolov8_track.py program. We enter the command in the terminal:
xxxxxxxxxxcd /home/yahboom/YBAMR-COBOT-EDU-00001/soft/yolov8python yolov8_track.pyThen the interface pops up as shown below.

The demo program started above uses yolov8 as the target detection model, and then uses deep sort for target tracking. We can see that each target label will have an ID for the target. If the target is always within the detection range, the ID will remain unchanged.
Code running flow chart:
Code:
xxxxxxxxxximport cv2from ultralytics import YOLO# Load the YOLOv8 modelmodel = YOLO('./weights/yolov8n.pt')# Open the video filevideo_path = "demo.mp4"cap = cv2.VideoCapture(video_path)# Loop through the video frameswhile cap.isOpened(): # Read a frame from the video success, frame = cap.read() if success: # Run YOLOv8 tracking on the frame, persisting tracks between frames results = model.track(frame, persist=True) # Visualize the results on the frame annotated_frame = results[0].plot() # Display the annotated frame cv2.imshow("YOLOv8 Tracking", annotated_frame) # Break the loop if 'q' is pressed if cv2.waitKey(1) & 0xFF == ord("q"): break else: # Break the loop if the end of the video is reached break# Release the video capture object and close the display windowcap.release()cv2.destroyAllWindows()