cv2.putText简单参数介绍

下面是官方文档:

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

简单的使用:
主要参数:图片数据,写入字符,基准坐标,字体,字体比例,颜色,粗细等

cv2.putText(img_arr, 'Fmg_b', (base_x,base_y), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 0, 0), 2)

cv2.getTextSize得到文本尺寸参数

官方文档:
参考:https://blog.csdn.net/Dontla/article/details/103139195

def getTextSize(text, fontFace, fontScale, thickness): # real signature unknown; restored from __doc__"""getTextSize(text, fontFace, fontScale, thickness) -> retval, baseLine.   @brief Calculates the width and height of a text string.计算文本字符串的宽度和高度。.   .   The function cv::getTextSize calculates and returns the size of a box that contains the specified text..   That is, the following code renders some text, the tight box surrounding it, and the baseline: :计算并返回包含指定文本的框的大小。。 也就是说,以下代码呈现了一些文本,其周围的紧框和基线:.   @code.   String text = "Funny text inside the box";.   int fontFace = FONT_HERSHEY_SCRIPT_SIMPLEX;.   double fontScale = 2;.   int thickness = 3;.   .   Mat img(600, 800, CV_8UC3, Scalar::all(0));.   .   int baseline=0;.   Size textSize = getTextSize(text, fontFace,.   fontScale, thickness, &baseline);.   baseline += thickness;.   .   // center the text 文字居中.   Point textOrg((img.cols - textSize.width)/2,.   (img.rows + textSize.height)/2);.   .   // draw the box 画盒子.   rectangle(img, textOrg + Point(0, baseline),.   textOrg + Point(textSize.width, -textSize.height),.   Scalar(0,0,255));.   // ... and the baseline first 首先是基线.   line(img, textOrg + Point(0, thickness),.   textOrg + Point(textSize.width, thickness),.   Scalar(0, 0, 255));.   .   // then put the text itself 然后把文字本身.   putText(img, text, textOrg, fontFace, fontScale,.   Scalar::all(255), thickness, 8);.   @endcode.   .   @param text Input text string. 输入文字字符串。.   @param fontFace Font to use, see #HersheyFonts. 要使用的字体,请参见#HersheyFonts。.   @param fontScale Font scale factor that is multiplied by the font-specific base size.字体比例因子,用来被特定字体的基本大小相乘。.   @param thickness Thickness of lines used to render the text. See #putText for details.用于渲染文本的线的粗细。 有关详细信息,请参见#putText。.   @param[out] baseLine y-coordinate of the baseline relative to the bottom-most text.   point. 基线相对于最底下的文本点的y坐标。.   @return The size of a box that contains the specified text. 包含指定文本的框的大小。.   .   @see putText"""pass

简单使用:
主要使用参数:字符,字体,字符比例,粗细

cv2.getTextSize('Fmg_b',cv2.FONT_HERSHEY_SIMPLEX, 1, 2)

对cv2.getTextSize的返回值的详细介绍

返回的格式如下,(是以putText的坐标做为基准点)

(width,height),bottom

对图片写入“英文”文本,并计算文本尺寸的实例

代码中参数的含义:
base_x,base_y:写入文本的左下角基准点坐标
其他参数如图片中标注

import cv2
img_name = r'test.jpg'img_arr = cv2.imread(img_name,-1)base_x = 40;base_y=50
cv2.putText(img_arr, 'Fmg_b', (base_x,base_y), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 0, 0), 2)
(base_width,base_h),bottom = cv2.getTextSize('Fmg_b',cv2.FONT_HERSHEY_SIMPLEX, 1, 2)
print((base_width,base_h),bottom) #(190, 43) 19
cv2.circle(img_arr,(base_x ,base_y),3,(0,0,255),2,)  ## 字符显示基准红色原点,字符左下方
cv2.line(img_arr,(base_x ,base_y),(base_x+base_width ,base_y),(0,0,255),2)  # 红色字符下线范围
cv2.line(img_arr,(base_x ,base_y),(base_x ,base_y-base_h),(0,255,0),2)  # 绿色高度范围
# 图片中文字的最下方
cv2.line(img_arr,(base_x ,base_y+bottom),(base_x+base_width ,base_y+bottom),(0,255,255),2)  # 绿色高度范围## 保存标注后的图片
cv2.imwrite('./line_picture.jpg',img_arr)
cv2.imshow('text',img_arr)
cv2.waitKey(0)

python中cv2.putText和cv2.getTextSize相关推荐

  1. 为什么OpenCV3在Python中导入名称是cv2

    我们来看一下: import cv3 print(cv3.__version__) 输出报错: Traceback (most recent call last):ImportError: No mo ...

  2. 在Python中使用OpenCV(CV2)对图像进行边缘检测

    Modules used: 使用的模块: For this, we will use the opencv-python module which provides us various functi ...

  3. cv2.imread()、cv2.putText、cv2.imwrite()、cv2.waitKey()

    cv2 cv2.imread() cv2.putText() cv2.imwrite() cv2.waitKey() cv2.imread() 用于读取图像数据 案例演示: import cv2# o ...

  4. OpenCV绘图函数:cv2.line、cv2.circle、cv2.rectangle、cv2.ellipse、 cv2.putText()、cv2.setMouseCallback

    ​OpenCV是一个用于图像处理.分析.机器视觉方面的开源函数库. 不管你是做科学研究,还是商业应用,opencv都能够作为你理想的工具,它可以运行在Linux.Windows.Android和Mac ...

  5. python灰度图cv2到plt变颜色_python中plt.imshow与cv2.imshow显示颜色问题

    python中plt.imshow与cv2.imshow显示颜色问题 在用plt.imshow和cv2.imshow显示同一幅图时可能会出现颜色差别很大的现象. 这是因为:opencv的接口使用BGR ...

  6. opencv python 中cv2.putText()函数的用法

    opencv python 中cv2.putText()函数的用法 文章目录: 一.快速使用 二.官方文档 三.使用举例 虽然用啦很多次,还是决定记录一下 一.快速使用 cv2.putText(ima ...

  7. python中的字体英文名_对python opencv 添加文字 cv2.putText 的各参数介绍

    如下所示: cv2.putText(img, str(i), (123,456)), font, 2, (0,255,0), 3) 各参数依次是:图片,添加的文字,左上角坐标,字体,字体大小,颜色,字 ...

  8. python中cv2.putText参数详解

    cv2.putText(img, str(i), (123,456)), font, 2, (0,255,0), 3) 各参数依次是:图片,添加的文字,左上角坐标,字体,字体大小,颜色,字体粗细 其中 ...

  9. python opencv 如何给图片添加文字?cv2.putText() PIL

    参考文章1:python如何在图片上添加文字(中文和英文)Python在图片上添加文字的两种方法:OpenCV和PIL 参考文章2:python之------如何在图片上面添加文字(多种类型的文字)[ ...

最新文章

  1. linux wireshark使用教程,技术|Ubuntu 上 Wireshark 的安装与使用
  2. Smart Card知识
  3. GlusterFS的安装及使用
  4. 使用gradle构建android项目,Android中使用Gradle来构建App项目的入门指南
  5. python第三方库有哪些常用的、请列举15个-python基础面试常见题
  6. 算法测试及对比度进一步增强
  7. mysql 插入毫秒数据_【转载】怎样在mybatis里向mysql中插入毫秒数的时间?
  8. Qt4访问sqlite数据库
  9. 学以致用六---Centos7.2+python3.6.2+django2.1.1 --搭建一个网站
  10. 《零基础入门学习Python》学习过程笔记【32,33,34异常处理】(没看)
  11. vb6.0中的Private Declare Function的含义
  12. unity案例星际迷航_《星际迷航》:自1964年以来启发人们和他们的技术
  13. Godaddy SSL证书解析到阿里云后配置nginx服务器https
  14. 实用的CAD技巧,你也可以成为大神!
  15. SQL SERVER 修改数据库名称(包括 db.mdf 名称的修改)
  16. 2022年MinGW-w64的安装及配置教程(傻瓜式)
  17. Unity 大气特效插件分析 - Aura #01
  18. 在linux安装java过程_挑战Java在Linux上安装过程分享
  19. matlab极点怎么输入法,[转载]MatLab中的极点配置方法
  20. 锁机制:读者写者问题 Linux C

热门文章

  1. Flutter在苹果手机上运行崩溃事件,iOS 14 崩溃
  2. 塞尔达荒野之息vs艾尔登法环
  3. JavaWeb(三层构架)
  4. PyQt之QComboBox(下拉列表框)动态添加
  5. 有关个人租房的一些细节
  6. bootstrap table export插件导出pdf格式文件中文乱码问题解决办法
  7. Markdown中插入图片
  8. One PUNCH Man——决策树和随机森林
  9. 面经|快手|策略运营实习生(数据分析)-【电商】|30min
  10. WAF绕过神器 (过安全狗、智创SQL注入)