Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to increase the size of history_observations. #1466

Closed
1 task done
AyushSarangi opened this issue Jun 8, 2024 · 2 comments
Closed
1 task done

How to increase the size of history_observations. #1466

AyushSarangi opened this issue Jun 8, 2024 · 2 comments
Labels
question Further information is requested

Comments

@AyushSarangi
Copy link

Search before asking

  • I have searched the Yolo Tracking issues and found no similar bug report.

Question

How to increase the size of history_observations. i have tried updating STrack.history_observations = deque([],maxlen = 100) changes are not reflecting in output. what to do?

from boxmot import BoTSORT
from boxmot.trackers.botsort.bot_sort import STrack
from collections import deque

Initialize the tracker

STrack.history_observations = deque([],maxlen=100)

tracker = BoTSORT(
model_weights = Path('osnet_x0_25_msmt17.pt'), # which ReID model to use
device = 'cuda:0',
fp16 = False,
)

Initialize YOLO model

yolo_model = YOLOv10('/content/weights/yolov10b.pt')

Open the input video

input_video_path = '/content/5330828-hd_1920_1080_30fps.mp4'
vid = cv2.VideoCapture(input_video_path)

if not vid.isOpened():
print("Error: Could not open input video.")
exit()

Define the output video path

output_video_path = '/content/BoTSORT_output_tracking_video.mp4'

Create the video writer

out = create_video_writer(vid, output_video_path)
frame_count = 500

trail_path = {}

while frame_count:
frame_count -= 1
ret, im = vid.read()
if not ret:
break

try:
    # Run the YOLO model on the frame
    results = yolo_model(im)

    # Convert the detections to the required format: N X (x, y, x, y, conf, cls)
    dets = []
    for result in results:
        for detection in result.boxes.data.cpu().numpy():
            x1, y1, x2, y2, conf, cls = detection
            if int(cls)==0:
              dets.append([x1, y1, x2, y2, conf, int(cls)])
    dets = np.array(dets)

    # Update tracker with detections
    tracker.update(dets, im)
    tracker.plot_results(im, show_trajectories = True)

    # trail_hist
    for a in tracker.active_tracks:
      if a.cls == 0:
        if len(a.history_observations)>2:
          trail_path[a.id] = a.history_observations

    # Write the frame to the output video
    out.write(im)

except Exception as e:
    print(f"An error occurred: {e}")
    break

vid.release()
out.release()
cv2.destroyAllWindows()

print(f"Tracking video saved to {output_video_path}")

@AyushSarangi AyushSarangi added the question Further information is requested label Jun 8, 2024
@YoungjaeDev
Copy link
Contributor

Isn't that MAX_AGE?

@mikel-brostrom
Copy link
Owner

mikel-brostrom commented Jun 13, 2024

You can now use MAX_AGE. I implemented dynamic deques based on this value 🚀 . Available in the new release!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants