OpenCV putText函数

       在Python中,putText函数常用于在图像上绘图。其原型为:

cv2.putText(img, text, org, fontFace, fontScale, color)

#img – 想要打印上文字的图像
#text – 想要打印的文字
#org – 文字的左下角坐标
#fontFace – 字体,可选的有:FONT_HERSHEY_SIMPLEX, 
#       FONT_HERSHEY_PLAIN, FONT_HERSHEY_DUPLEX, 
#       FONT_HERSHEY_COMPLEX, FONT_HERSHEY_TRIPLEX, 
#       以及 FONT_HERSHEY_SCRIPT_COMPLEX, 其中任意一种字体
#       都可加上 FONT_ITALIC 使其变为斜体
#fontScale – 字号
#color – 颜色

       下面是代码应用,具体代码将在文章最后展示。
       用摄像头获取图像,并在图像上打印出 “Hello World!”。

puText
图一:在图片上打印 “Hello World!”

Python代码:

# Author Junkun Di
# Create at: 29/6/2017
# Description: Get an image by using the webcamera and put text "Hello World" in the image

import cv2

cap = cv2.VideoCapture(0)
while(cap.isOpened()):
    # read image
    ret, img = cap.read()
    # Display the text
    cv2.putText(img, "Hello World!", (50, 150), cv2.FONT_HERSHEY_SIMPLEX, 3, 1)
    # show appropriate images in windows
    cv2.imshow('putText', img)

    k = cv2.waitKey(10)
    if k == 27:
        break
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值