roboflow / supervision

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

LabelAnnotator mixes up RGB and BGR #1371

Closed yeldarby closed 2 months ago

yeldarby commented 2 months ago

Search before asking

Bug

LabelAnnotator is using to_rgb instead of to_bgr for the text color so the channels get mixed up. Using text_color = sv.Color.RED produces blue labels.

image

Environment

Minimal Reproducible Example

Colab: https://colab.research.google.com/drive/1DVjQ4ETQK2o4CUqMGD8rBaLSxOu7KE4o#scrollTo=_Czi4iAkPt01

box_annotator = sv.BoxAnnotator()
label_annotator = sv.LabelAnnotator(
    text_color = sv.Color.RED
)

annotated_image = box_annotator.annotate(image.copy(), detections=detections)
annotated_image = label_annotator.annotate(annotated_image, detections=detections)

sv.plot_image(image=annotated_image, size=(8, 8))

Additional

Pretty sure this is the culprit: https://github.com/roboflow/supervision/blob/e76dec7e1518cd286ea7391caf3a5766bbda1890/supervision/annotators/core.py#L1155

Looking at the file it also seems like it might affect RichLabelAnnotator (though that uses to_rgb both for the background and the text).

Are you willing to submit a PR?

Bhavay-2001 commented 2 months ago

Hi @yeldarby, if you are okay with it, can I work on this issue?

SkalskiP commented 2 months ago

Hi @yeldarby 👋🏻 Thanks for pointing this out. It's funny how this bug flew under the radar for so long. As for RichLabelAnnotator, it uses Pillow for text rendering, and in that case, as_rgb is the expected behavior (I just tested this).

@Bhavay-2001, feel free to open PR to fix this issue. I assign this issue to you. Let me know if you need any help.

SkalskiP commented 2 months ago

@yeldarby fix is merged into develop. I'm closing the issue. Feel free to re-open it if you'll face more problems.

yeldarby commented 2 months ago

Awesome work @Bhavay-2001!