fontScale = 1
fontThickness = 1
# make sure font thickness is an integer, if not, the OpenCV functions that use this may crash
fontThickness = int(fontThickness)
upperLeftTextOriginX = int(imageWidth * 0.05)
upperLeftTextOriginY = int(imageHeight * 0.05)
textSize, baseline = cv2.getTextSize(resultText, fontFace, fontScale, fontThickness)
textSizeWidth, textSizeHeight = textSize
# calculate the lower left origin of the text area based on the text area center, width, and height
lowerLeftTextOriginX = upperLeftTextOriginX
lowerLeftTextOriginY = upperLeftTextOriginY + textSizeHeight
# write the text on the image
cv2.putText(openCVImage, resultText, (lowerLeftTextOriginX, lowerLeftTextOriginY), fontFace, fontScale, Color,
fontThickness)
似乎fontScale
没有根据图像的宽度和高度缩放文本,因为对于不同大小的图像,文本的大小几乎相同。那么,我如何根据图像大小调整文本大小,以便所有文本都能适合图像?在
因为这起作用了!在
请记住,字体类型会影响25常量
如果将
fontScale = 1
用于大小约为1000 x 1000的图像,则此代码应正确缩放字体。在如果你仍然有任何问题,请发表意见。在
相关问题 更多 >
编程相关推荐