OpenCV putText函数

来源:互联网 发布:斗牛开挂软件 编辑:程序博客网 时间:2024/05/16 09:04

       在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 imageimport cv2cap = 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
原创粉丝点击