码迷,mamicode.com
首页 > 其他好文 > 详细

opencv-函数--画框、写字

时间:2019-03-23 21:01:26      阅读:590      评论:0      收藏:0      [点我收藏+]

标签:ttext   for   pre   str   enter   win   show   numpy   window   

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-函数--画框、写字

标签:ttext   for   pre   str   enter   win   show   numpy   window   

原文地址:https://www.cnblogs.com/yeran/p/10585498.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!