1def get_optimal_font_scale(text, width):
2 for scale in reversed(range(0, 60, 1)):
3 textSize = cv.getTextSize(text, fontFace=cv.FONT_HERSHEY_DUPLEX, fontScale=scale/10, thickness=1)
4 new_width = textSize[0][0]
5 #print(new_width)
6 if (new_width <= width):
7 return scale/10
8 return 1
9