In the opencv python, we use fontscale or thickness to show the font size, but if I want my font exactly to be 20px, how can I do that? How can I change the scale/thickness in a way to compute my desired point size?
cv2.putText(img_inpainted,boxes['text'][i],(x,y),cv2.FONT_HERSHEY_PLAIN,1,(120,145,152),1,2)
I want the size of text exactly to be L px. How could I go doing that?
I searched and thought a lot, couldn't find any way
CodePudding user response:
There's a roundabout way. First you need to know the size of text for a given arbitrary fontScale
. Then, assuming the Hershey vector fonts scale linearly, you can calculate desired pixel height into a corresponding fontScale
.
cv.rectangle(canvas, org, (org[0] fw, org[1] - fh), 128)
cv.line(canvas, (org[0], org[1] baseline), (org[0] fw, org[1] baseline), 128)