opencv-函数--画框写字
Posted yeran
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了opencv-函数--画框写字相关的知识,希望对你有一定的参考价值。
import cv2
import numpy as np
img = np.zeros([512, 512, 3], dtype=np.uint8)
for i in range(512):
for j in range(512):
img[i, j, :] = [i % 256, j % 256, (i + j) % 256]
cv2.rectangle(img, (200, 200), (400, 400), (0, 0, 255), 3)
cv2.circle(img, (300, 300), 100, (0, 255, 255), 3)
info = 'Hello World'
font_face = cv2.FONT_HERSHEY_COMPLEX
font_scale = 2
thickness = 2
text_size = cv2.getTextSize(info, font_face, font_scale, thickness)
print(text_size)
p_center = (int(512 / 2 - text_size[0][0] / 2), int(512 / 2 - text_size[0][1] / 2))
cv2.putText(img, info, p_center, font_face, font_scale, (0, 0, 0), thickness)
cv2.imshow('demo', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
以上是关于opencv-函数--画框写字的主要内容,如果未能解决你的问题,请参考以下文章
python opencv鼠标事件实现画框圈定目标获取坐标信息