Opencv cv2.putText 函数详解

1. 函数讲解

具体函数如下:

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

函数源码如下:

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

对应的参数如下:

参数具体表述
image绘制的图像
text绘制的文本
org文本在图像中显示的坐标,用元组表示格式为(X坐标,Y坐标)
font文本字体类型,值可以为FONT_HERSHEY_SIMPLEXFONT_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. 代码讲解

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()

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

  • 5
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

码农研究僧

你的鼓励将是我创作的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值