generated from roboflow/template-python
-
Notifications
You must be signed in to change notification settings - Fork 3k
Open
Labels
questionFurther information is requestedFurther information is requested
Description
Search before asking
- I have searched the Supervision issues and found no similar feature requests.
Question
The first two frames both correctly identify the object and successfully draw the track.
However, starting from the second frame, detections remains at 0, and I'm unsure why.
I then tried using the tracker.reset() function, which worked, but the track lines were very messy.
Here's my code:
model = YOLO('BTrain09301516.pt')
tracker = sv.ByteTrack(frame_rate=25)
box_annotator = sv.BoxAnnotator(color_lookup=sv.ColorLookup.TRACK)
label_annotator = sv.LabelAnnotator(color_lookup=sv.ColorLookup.TRACK)
trace_annotator = sv.TraceAnnotator(trace_length=30, color_lookup=sv.ColorLookup.TRACK)
image_dir = Path("images")
img_suffixes = ('*.jpg', '*.jpeg')
img_paths = []
for suf in img_suffixes:
img_paths.extend(image_dir.glob(suf))
img_paths = sorted(img_paths)
for idx, img_path in enumerate(img_paths, 1):
frame = cv2.imread(str(img_path))
results = model(frame, verbose=False, conf=0.25)[0]
detections = sv.Detections.from_ultralytics(results) # 转成 supervision 格式
detections = tracker.update_with_detections(detections)
print(f"[{idx}/{len(img_paths)}] ball>> results: {len(results)}, detections: {len(detections)}, conf: {results.boxes.conf.cpu().numpy()}")
annotated_frame = frame.copy()
annotated_frame = box_annotator.annotate(annotated_frame, detections)
annotated_frame = label_annotator.annotate(annotated_frame, detections)
annotated_frame = trace_annotator.annotate(annotated_frame, detections)
cv2.imshow('frame', annotated_frame)
tracker.reset() # test
if cv2.waitKey(0) & 0xFF == ord('q'):
cv2.destroyAllWindows()
The directory contains 300 images, which I extracted from video frames. I tried using the video, but the problem persisted starting with the second frame. I also tried modifying the ByteTrack parameters, but to no avail.
Please help me. I've been working on this for two days. I can display the example video from the official website: https://media.roboflow.com/supervision/video-examples/people-walking.mp4
Yolo can correctly infer objects.
Additional
No response
Metadata
Metadata
Assignees
Labels
questionFurther information is requestedFurther information is requested