Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python text overlay on top of everything else

Tags:

python

overlay

I'm trying to display the result of a neural net reading picture input from the screen to show what it guesses in the corner. So like I'll have a slide show of cat and dog pictures running in the background and my python code takes a screenshot every couple seconds and feeds to the neural net and gets an answer whether it's a cat or dog. I wanna show "cat"/"dog" in the corner of the screen, on top of video and everything else going on.

I found someone already asked this couple years back

Python: text overlay on top of all windows including fullscreen in Linux

but the module the answer suggested(pyosd) doesn't exist anymore apparently. Tring to:

pip install pyosd

returns

"no matching distribution found for pyosd"
like image 455
Bardia Avatar asked Dec 08 '25 10:12

Bardia


1 Answers

Bit old, but hopefully this might help someone out.

If you're using OpenCV2 for image processing. You might consider using OpenCV2's putText function to overlay text on the image.

import cv2 as cv

# Read image from file path or from a video or screenshot feed
img = cv.imread(targetImgPathOrScreenshotFeed, cv.IMREAD_UNCHANGED)

# Your detection method here to return either cat or dog result

# Overlay text on this image 
# cv.putText(img, text, distanceFromOrgin(Top left), fontFace, fontScale, colour, thickness)
cv.putText(img, 'Dog', (30, 70), cv.FONT_HERSHEY_SIMPLEX, .5, (255, 255, 255), 1)

# Display result if necessary
cv.imshow('Detection Result', img)
like image 139
ORILIRO Avatar answered Dec 10 '25 01:12

ORILIRO