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
并没有根据图像的宽度和高度缩放文本,因为对于不同大小的图像,文本的大小几乎相同。那么如何根据图像大小调整文本大小,以便所有文本都适合图像中呢?
fontScale
?请解释其他变量是什么。 - parthagarfontScale
。谢谢。 - XINDI LIfontScale
=1?请指定图像尺寸(高x宽),我会尽快分享代码。 - parthagarfontScale
的值感到困惑。但是从我的实验来看,对于1000*1000像素或更大的图像,我可以将fontScale
设置为1。 - XINDI LI