-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
sv changes bbox shape for object detection with YOLOv8?? #1362
Comments
Hi @abelBEDOYA 👋 Could you share a short snippet of the code, with the print statements? Also, to clarify, which of these are you measuring the difference between?
|
Here is the code. It just open webcam with cv2 and runs callback() parsing last frame, which infers and tracks: import numpy as np
import supervision as sv
from ultralytics import YOLO
import torch
model = YOLO("yolov8n.pt")
tracker = sv.ByteTrack()
box_annotator = sv.BoundingBoxAnnotator()
label_annotator = sv.LabelAnnotator()
def callback(frame: np.ndarray, _: int) -> np.ndarray:
results = model(frame)[0]
print('YOLO bbox: ', results.boxes.cpu().xyxy[0] if len(results.boxes.cpu().xyxy)>0 else [])
detections = sv.Detections.from_ultralytics(results)
detections = tracker.update_with_detections(detections)
print('bbox from tracker sv: ', torch.tensor(tracker.tracked_tracks[0].tlbr).cpu())
print('\n \n ')
labels = [
f"#{tracker_id} {results.names[class_id]}"
for class_id, tracker_id
in zip(detections.class_id, detections.tracker_id)
]
annotated_frame = box_annotator.annotate(
frame.copy(), detections=detections)
return label_annotator.annotate(
annotated_frame, detections=detections, labels=labels)
import cv2
# Abre la webcam (0 es el índice por defecto de la cámara)
cap = cv2.VideoCapture(0)
# Verifica si la cámara se abrió correctamente
if not cap.isOpened():
print("Error: No se puede abrir la cámara")
exit()
while True:
# Captura frame por frame
ret, frame = cap.read()
# Si no se recibió el frame correctamente, sal del loop
if not ret:
print("Error: No se puede recibir frame (stream end?). Saliendo ...")
break
img = callback(frame, 0)
# # Muestra el frame resultante
cv2.imshow('Webcam', img)
# Presiona 'q' para salir del loop
if cv2.waitKey(1) == ord('q'):
break
# Cuando todo esté listo, libera el capture
cap.release()
cv2.destroyAllWindows() |
Curious. Thanks for letting us know - we'll test it. |
@abelBEDOYA, |
|
Hmm, the latest release is 0.22.0, please try the latest one and see if it helps. In the meantime I will test your code. |
Hi @abelBEDOYA, I think I know what your problem is. It looks like you are printing the bounding box stored in the tracked object in this line print('bbox from tracker sv: ', torch.tensor(tracker.tracked_tracks[0].tlbr).cpu()) This prints the internal bounding box that the tracker is using and which is associated with location and size velocities within the tracker and may be different than the actual bounding box from the most recent frame. If you want the precise bounding box from detector that is associated with that track, you will want to get the bounding box from the print('bbox from tracker sv: ', detections.xyxy[0]) |
I just wanted to take some time to say thanks, @rolson24. The tracker issues have been plaguing us for a while, and we've not had much time to look at it. We really appreciate you helping out! |
Okey! Thanks @rolson24! I also take this opportunity to ask you about the detection and track association. My point is, I start with ultralytics Result object which contains detections. I parse them to How can this association be done? Thanks again! |
If you use the detections returned from Unfortunately, the tracker does not support Keypoints right now. From what you are describing, it sounds like you would want to use a yolo-pose model which returns bboxes and keypoints, and you would want to track the objects. This may be something we add, but for now I have a somewhat hacky idea of how you may be able to do this:
This will make it so that the keypoints in post_track_keypoints have the same index as their corresponding bounding box in post_track_detections. Its kinda hacky, but it should work. |
Search before asking
Question
I've been using supervision, its tracker, annotators, ... Nice work!! However I've noticed that, doing object detection with yolov8, bboxe shape from ultralytics are changed by supervision even though it refers to the same detection. The following screenshot shows a detected object provided by YOLO, ultralytics.Result (before doing
supervision_tracker.update(results[0])
and after parsing it tosupervision_tracker
.The bboxes are diferent. I expect they shouldn't...
Can this bbox shape change be removed? I would like to keep original bbox shape.
Thanks!!
Additional
No response
The text was updated successfully, but these errors were encountered: