Last active
February 7, 2020 05:17
-
-
Save jihyeonRyu/8d7c3c8b909ab464d757dc4e2dc1c394 to your computer and use it in GitHub Desktop.
opencv automated fontsize
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
import cv2 | |
def get_font_point_and_scale(text, x, y, h, w, thickness, font): | |
(text_width, text_height) = cv2.getTextSize(text, font, 1.0, thickness)[0] | |
scalex = w/text_width | |
scaley = h/text_height | |
scale = min(scalex, scaley) | |
marginx = 0 if scale == scalex else int(w *(scalex-scale)/scalex*0.5) | |
marginy = 0 if scale == scaley else int(h *(scaley-scale)/scaley*0.5) | |
return (x+marginx, y+h-marginy), scale |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment