-
-
Save evilmtv/af2a023e472e6303fd2d3cc02aa1a83a to your computer and use it in GitHub Desktop.
Center text on an image with Python and OpenCV.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# setup text | |
font = cv2.FONT_HERSHEY_SIMPLEX | |
text = "Female" | |
# get boundary of this text | |
textsize = cv2.getTextSize(text, font, 1, 2)[0] | |
# get coords based on boundary | |
textX = int(boundingboxcenter[0] - (textsize[0] / 2)) | |
textY = int(boundingboxcenter[1] + (textsize[1] / 2)) | |
# add text centered on image | |
cv2.putText(img, text, (textX, textY ), font, 1, (255, 255, 255), 2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment