sujanshresstha / YOLOv10_DeepSORT

This repository contains code for object detection and tracking in videos using the YOLOv10 object detection model and the DeepSORT algorithm.
MIT License
74 stars 8 forks source link

can I save txt file like yolov8 track #5

Open panyuxin1993 opened 1 month ago

panyuxin1993 commented 1 month ago

In YOLOv8, a function track can both show results on videos and save results as txt files for each frames. Can this tool achieve similar function? Or in future plan to add this valuable function?

sujanshresstha commented 1 month ago

Since the YOLOv10 model's code base is built with Ultralytics, you can save a text file similar to YOLOv8 track using the following code: results = model(frame, verbose=False, save_txt=True)[0]

However, in the output file, you can't differentiate detections with frames. To include more details in the output file, you can use the following function instead of the method above:

def save_tracking_results(tracks, frame_count):
    with open("./output/tracking_results.txt", "a") as file:
        for track in tracks:
            if not track.is_confirmed():
                continue
            track_id = track.track_id
            ltrb = track.to_ltrb()
            class_id = track.get_det_class()
            file.write(f"Frame: {frame_count}, Track ID: {track_id}, Class ID: {class_id}, BBox: {ltrb}\n")

# Add after analyzing tracks inside the main function
save_tracking_results(tracks, frame_count)  # Save results to the same text file