import cv2 as cv
import numpy as np
import matplotlib.pyplot as plt
img = cv.imread("../SampleImages/pomeranian.png")
print(img.shape)
plt.imshow(img[:,:,::-1])
#画直线
#cv.line(img,start,end,color,thickness)
#参考资料:https://blog.csdn.net/weixin_42618420/article/details/106097270
cv.line(img, (0,0), (512,512), (0, 0, 255), 1)
plt.imshow(img[:,:,::-1])
#画圆
#cv.circle(img,centerpoint,r,color,thickness)
#参考资料:https://blog.csdn.net/viven_hui/article/details/102807995
cv.circle(img,(335,360),16,(0,255,0),2)
plt.imshow(img[:,:,::-1])
#画矩形
#cv.rectangle(img,uppperLeftPoint,downRightPoint,color,thickness)
#参考资料:https://blog.csdn.net/Kefenggewu_/article/details/109909087
cv.rectangle(img, (50,50), (100,100), (255,0,0), 2)
plt.imshow(img[:,:,::-1])
#绘制文字
#cv.putText(img, text, org, fontFace, fontScale, color, thickness=None, lineType=None, bottomLeftOrigin=None)
# org: 文字在图像中的左下角位置
#参考资料:https://blog.csdn.net/weixin_41010198/article/details/89155899
cv.putText(img, 'Cute Pomeranian~', (50, 300), cv.FONT_HERSHEY_SIMPLEX, 1, (100,200,50), 2, cv.LINE_AA)
plt.imshow(img[:,:,::-1])
文章来源:https://www.toymoban.com/news/detail-642922.html
文章来源地址https://www.toymoban.com/news/detail-642922.html
到了这里,关于Python Opencv实践 - 在图像上绘制图形的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!