roboflow / supervision

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

Add legend text on video frames #676

Closed dimpolitik closed 10 months ago

dimpolitik commented 10 months ago

Search before asking

Question

Hi All!

I'm trying to find a way to add a legend text at each frame (with the number of frame assigned) during the object tracking. Does supervision has a way to do that? I checked the available annotators, but I didn't find something relevant. Thank you!

Additional

No response

SkalskiP commented 10 months ago

Hi @dimpolitik 👋🏻 Did you try to use draw_text? It allows you to display arbitrary text in arbitrary places.

import supervision as sv

scene = np.zeros((100, 100, 3), dtype=np.uint8)
text_anchor = Point(x=50, y=50)
scene = draw_text(scene=scene, text="Hello, world!",text_anchor=text_anchor)
SkalskiP commented 10 months ago

Hi @dimpolitik. Did my idea solve your problem?

dimpolitik commented 10 months ago

Hi @dimpolitik. Did my idea solve your problem? @SkalskiP Thank you for your help, it solved my issue :) . The scene image is black, so the text is not visible. I tried this and it works fine:

import supervision as sv
import cv2 as cv 
img = cv.imread('test_image.png') 
text_anchor = sv.Point(x=50, y=50)
img_text = sv.draw_text(scene=img, text="Hello, world!",text_anchor=text_anchor)
sv.plot_image(img_text) 
SkalskiP commented 10 months ago

Yeah my example was mostly showing how to apply it on the scene. Awesome!