Displaying object detection confidence scores with the custom object detector

How can I display the confidence score for the detected objects alongside the bounding box visualisation and object class ID and distance with the custom detector?

Hello @a11s,

You can mimic how we display the class ID, in the render2D call in the main loop.

It’s a call to cv2.putText, placing some text at some coordinates.
You can add the confidence display here.

Hi @JPlou, thanks for the pointer.

I have tried replacing the following lines in the render_2D function of tracking_viewer.py:

text = "class " + str(obj.raw_label)
text_color = (255, 255, 255, 255)
cv2.putText(left_display, text, text_position, cv2.FONT_HERSHEY_COMPLEX_SMALL, 0.5, text_color, 1)

With the following lines:

if isinstance(obj, sl.CustomBoxObjectData):
label = obj.label
probability = obj.probability
text = f"class {obj.raw_label} ({probability:.2f})"
else:
text = "class " + str(obj.raw_label)

text_color = (255, 255, 255, 255)
cv2.putText(left_display, text, text_position, cv2.FONT_HERSHEY_COMPLEX_SMALL, 0.5, text_color, 1)

The code runs fine, but the confidence/probability score is still not showing. Where am I going wrong?

@a11s

By the time it reaches the viewer, the obj that is displayed is ingested by the SDK, and processed into an ObjectData.

You should try displaying the confidence of ObjectData instead of the probability of CustomBoxObjectData.