1. 函數(shù)講解
具體函數(shù)如下:
cv2.putText(image, text, org, font, fontScale, color[, thickness[, lineType[, bottomLeftOrigin]]])
函數(shù)源碼如下:
def putText(img, text, org, fontFace, fontScale, color, thickness=None, lineType=None, bottomLeftOrigin=None): # real signature unknown; restored from __doc__
"""
putText(img, text, org, fontFace, fontScale, color[, thickness[, lineType[, bottomLeftOrigin]]]) -> img
. @brief Draws a text string.
.
. The function cv::putText renders the specified text string in the image. Symbols that cannot be rendered
. using the specified font are replaced by question marks. See #getTextSize for a text rendering code
. example.
.
. @param img Image.
. @param text Text string to be drawn.
. @param org Bottom-left corner of the text string in the image.
. @param fontFace Font type, see #HersheyFonts.
. @param fontScale Font scale factor that is multiplied by the font-specific base size.
. @param color Text color.
. @param thickness Thickness of the lines used to draw a text.
. @param lineType Line type. See #LineTypes
. @param bottomLeftOrigin When true, the image data origin is at the bottom-left corner. Otherwise,
. it is at the top-left corner.
"""
pass
對(duì)應(yīng)的參數(shù)如下:
參數(shù) | 具體表述 |
---|---|
image | 繪制的圖像 |
text | 繪制的文本 |
org | 文本在圖像中顯示的坐標(biāo),用元組表示格式為(X坐標(biāo),Y坐標(biāo)) |
font | 文本字體類(lèi)型,值可以為FONT_HERSHEY_SIMPLEX 、FONT_HERSHEY_PLAIN
|
fontScale | 字體比例因子乘以font-specific基本大小 |
color | 文本顏色,設(shè)置三通道的元組,比如(255,0,0) |
thickness | 線的粗細(xì) |
lineType | 可選參數(shù),行的類(lèi)型 |
bottomLeftOrigin | 可選參數(shù),true表示數(shù)據(jù)位于原點(diǎn)左下角,flase位于左上角。 |
對(duì)應(yīng)的字體類(lèi)型如下:文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-707718.html
- cv.FONT_ITALIC:斜體字的標(biāo)志
- cv.FONT_HERSHEY_PLAIN:小尺寸無(wú)襯線字體
- cv.FONT_HERSHEY_SIMPLEX:正常大小的無(wú)襯線字體
- cv.FONT_HERSHEY_DUPLEX:正常大小的無(wú)襯線字體(比FONT_HERSHEY_SIMPLEX更復(fù)雜)
- cv.FONT_HERSHEY_COMPLEX:正常大小的襯線字體
- cv.FONT_HERSHEY_TRIPLEX:正常大小的襯線字體(比FONT_HERSHEY_COMPLEX更復(fù)雜)
- cv.FONT_HERSHEY_SCRIPT_SIMPLEX:手寫(xiě)體字體
- cv.FONT_HERSHEY_SCRIPT_COMPLEX(比FONT_HERSHEY_SCRIPT_SIMPLEX的更復(fù)雜)
2. 代碼講解
import cv2
import matplotlib.pyplot as plt
image = cv2.imread("Gym.jpg")
font = cv2.FONT_HERSHEY_SIMPLEX
org = (100, 100)
fontScale = 1
color = (255, 0, 0)
thickness = 3
image = cv2.putText(image, 'manong yanjiuseng', org, font,fontScale, color, thickness, cv2.LINE_AA)
plt.imshow(image)
plt.show()
截圖如下:文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-707718.html
到了這里,關(guān)于Opencv cv2.putText 函數(shù)詳解的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!