Python Opencv实践 - 在图像上绘制图形

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])

Python Opencv实践 - 在图像上绘制图形_第1张图片

Python Opencv实践 - 在图像上绘制图形_第2张图片 

Python Opencv实践 - 在图像上绘制图形_第3张图片

 Python Opencv实践 - 在图像上绘制图形_第4张图片

 Python Opencv实践 - 在图像上绘制图形_第5张图片

 

你可能感兴趣的:(OpenCV实践-python,python,opencv,开发语言,图像处理,计算机视觉)