roboflow / supervision

We write your reusable computer vision tools. 💜
https://supervision.roboflow.com
MIT License
23.54k stars 1.76k forks source link

draw wrong OrientedBoxAnnotator with InferenceSlicer #1339

Closed DawnMagnet closed 2 months ago

DawnMagnet commented 3 months ago

Search before asking

Bug

I'm using official yolov8m_obb.pt and if I write code like below

def callback(image_slice: np.ndarray) -> sv.Detections:
    result = model(image_slice)[0]
    return sv.Detections.from_ultralytics(result)
slicer = sv.InferenceSlicer(callback=callback, thread_workers=1)
detections = slicer(image)
bounding_box_annotator = sv.OrientedBoxAnnotator()
annotated_image = bounding_box_annotator.annotate(scene=image, detections=detections)

The OrientedBoxAnnotator in annotated_image was in the wrong place, and if i check variables inside detections it shows like below

Detections(xyxy=array([[     759.02,      8.0095,      770.99,      12.812]]), mask=None, confidence=array([    0.31441], dtype=float32), class_id=array([1]), tracker_id=None, data={'xyxyxyxy': array([[[     247.02,      8.3203],
        [     247.13,      12.812],
        [     258.99,      12.501],
        [     258.87,      8.0095]]], dtype=float32), 'class_name': array(['Van'], dtype='<U13')})

which xyxy can't match xyxyxyxy and boxes inside picture are wrong too image

but if i don't use the InferenceSlicer, then the answer is correct

Environment

python = 3.9
dependencies = [
    "ultralytics~=8.2.45",
    "opencv-contrib-python~=4.10.0.84",
    "onnx~=1.16.1",
    "supervision~=0.21.0",
]

Minimal Reproducible Example

No response

Additional

No response

Are you willing to submit a PR?

LinasKo commented 3 months ago

Hi @DawnMagnet 👋

InferenceSlicer does not support OBB boxes at the moment. But it definitely should!


@Bhavay-2001, would you have some time to work on this?

Inside _run_callback of InferenceSlicer, there's a call to move_detections. Inside you'll find calls to move_boxes and move_masks. Notice that we don't mention data at all.

We need to create a function move_obb_boxes and place it inside move_detections, calling it if ORIENTED_BOX_COORDINATES key is in data.

Bhavay-2001 commented 3 months ago

Sure @LinasKo, give me some time and I will have a look at this. Thanks

SkalskiP commented 2 months ago

Hi @DawnMagnet 👋🏻

@eric220 just submitted a PR aiming to fix this issue. It would greatly help us if you could test it on your example. All you need to do is:

  1. uninstall supervision
pip uninstall -y supervision
  1. install updated version
pip install git+https://github.com/eric220/supervision@develop
  1. run your code

Like I said it would help us a lot to run this new version on your example. Thanks in advance 🙏🏻

DawnMagnet commented 2 months ago

thank you very much! I'll test this today

SkalskiP commented 2 months ago

@DawnMagnet awesome! Let me know how it went!

DawnMagnet commented 2 months ago

with my test, it's working prefectly, and the value of points now make sense, thank you again! image

SkalskiP commented 2 months ago

Awesome! It's merged and accessible on develop. I'm closing the issue. Feel free to reopen it if you encounter more problems.