Only one label show on bounding box

Hi everyone,

I recently followed this tutorial roboflow-computer-vision-utilities/images/roboflow_cv_utils_writetext_img.ipynb at main · roboflow/roboflow-computer-vision-utilities · GitHub with bounding boxes. However, I got an error and, I changed

sv_xyxy = sv.Detections(roboflow_xyxy).from_roboflow(predictions_json,class_list=list((project.classes).keys()))

line to
sv_xyxy = sv.Detections(roboflow_xyxy).from_inference(predictions_json) line. After making this change, I ran my code and it worked.

However, I’ve run into an unexpected issue where only the label for the first bounding box is displayed correctly, and all subsequent bounding boxes appear without any labels.

did anyone have a similar issue, or does anyone know what might be causing this?

Hey @will99

Supervision has gone through major changes since that Colab was made. You can now ingest detections using:

detections = sv.Detections.from_inference(predictions_json)

As for the visualization, could you share the code you used for the annotators? Using the example you linked, with the latest changes in Supervision, it should look something like this:

def draw_boxes_and_labels(image, detections):
    image_with_boxes = sv.BoundingBoxAnnotator().annotate(image, detections)

    return image_with_boxes

Hi,
I used this code

# def draw_boxes_and_labels(image, sv_xyxy, class_ids, add_labels):
#     print(class_ids)
#     #set add_labels to True to show the label for each object
#     image_with_boxes = sv.BoxAnnotator().annotate(image, sv_xyxy, labels=class_ids, skip_label=add_labels)

#     return image_with_boxes

I changed this code

# sv_xyxy = sv.Detections(roboflow_xyxy).from_inference(predictions_json)
            #predictions_json,class_list=list((project.classes).keys()))

to this

sv_xyxy = sv.Detections.from_inference(predictions_json)

when I used the def draw_boxes_and_labels that you provided it only showed the box without the label

Hi @will99

I’m sorry, yes, you are correct. It only draws the bounding boxes. You also have to utilize sv.LabelAnnotator().

sv.BoxAnnotator was deprecated:

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.