Skip to content

Instantly share code, notes, and snippets.

@evilmtv
evilmtv / center_cv2_text.py
Last active December 27, 2021 11:51 — forked from xcsrz/center_text_on_image.py
Center text on an image with Python and OpenCV.
# 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))