0


Opencv cv2.putText 函数详解

目录

1. 函数讲解

具体函数如下:

  1. cv2.putText(image, text, org, font, fontScale, color[, thickness[, lineType[, bottomLeftOrigin]]])

函数源码如下:

  1. defputText(img, text, org, fontFace, fontScale, color, thickness=None, lineType=None, bottomLeftOrigin=None):# real signature unknown; restored from __doc__"""
  2. putText(img, text, org, fontFace, fontScale, color[, thickness[, lineType[, bottomLeftOrigin]]]) -> img
  3. . @brief Draws a text string.
  4. .
  5. . The function cv::putText renders the specified text string in the image. Symbols that cannot be rendered
  6. . using the specified font are replaced by question marks. See #getTextSize for a text rendering code
  7. . example.
  8. .
  9. . @param img Image.
  10. . @param text Text string to be drawn.
  11. . @param org Bottom-left corner of the text string in the image.
  12. . @param fontFace Font type, see #HersheyFonts.
  13. . @param fontScale Font scale factor that is multiplied by the font-specific base size.
  14. . @param color Text color.
  15. . @param thickness Thickness of the lines used to draw a text.
  16. . @param lineType Line type. See #LineTypes
  17. . @param bottomLeftOrigin When true, the image data origin is at the bottom-left corner. Otherwise,
  18. . it is at the top-left corner.
  19. """pass

对应的参数如下:
参数具体表述image绘制的图像text绘制的文本org文本在图像中显示的坐标,用元组表示格式为(X坐标,Y坐标)font文本字体类型,值可以为

  1. FONT_HERSHEY_SIMPLEX

  1. FONT_HERSHEY_PLAIN

fontScale字体比例因子乘以font-specific基本大小color文本颜色,设置三通道的元组,比如(255,0,0)thickness线的粗细lineType可选参数,行的类型bottomLeftOrigin可选参数,true表示数据位于原点左下角,flase位于左上角。
对应的字体类型如下:

  • cv.FONT_ITALIC:斜体字的标志
  • cv.FONT_HERSHEY_PLAIN:小尺寸无衬线字体
  • cv.FONT_HERSHEY_SIMPLEX:正常大小的无衬线字体
  • cv.FONT_HERSHEY_DUPLEX:正常大小的无衬线字体(比FONT_HERSHEY_SIMPLEX更复杂)
  • cv.FONT_HERSHEY_COMPLEX:正常大小的衬线字体
  • cv.FONT_HERSHEY_TRIPLEX:正常大小的衬线字体(比FONT_HERSHEY_COMPLEX更复杂)
  • cv.FONT_HERSHEY_SCRIPT_SIMPLEX:手写体字体
  • cv.FONT_HERSHEY_SCRIPT_COMPLEX(比FONT_HERSHEY_SCRIPT_SIMPLEX的更复杂)

2. 代码讲解

  1. import cv2
  2. import matplotlib.pyplot as plt
  3. image = cv2.imread("Gym.jpg")
  4. font = cv2.FONT_HERSHEY_SIMPLEX
  5. org =(100,100)
  6. fontScale =1
  7. color =(255,0,0)
  8. thickness =3
  9. image = cv2.putText(image,'manong yanjiuseng', org, font,fontScale, color, thickness, cv2.LINE_AA)
  10. plt.imshow(image)
  11. plt.show()

截图如下:
在这里插入图片描述


本文转载自: https://blog.csdn.net/weixin_47872288/article/details/129060230
版权归原作者 码农研究僧 所有, 如有侵权,请联系我们删除。

“Opencv cv2.putText 函数详解”的评论:

还没有评论