OpenCV画线、矩形、圆形

代码位置:9-DrawingLineRectangleCircle.py

import numpy as np
import cv2
import matplotlib.pyplot as plt

def show(image):
    plt.imshow(image)
    plt.axis('off')
    plt.show()

image = np.zeros((400, 400,3), dtype='uint8')

red = (255, 0, 0)
cv2.line(image, (0,0), (400, 400), red)

green = (0, 255, 0)
cv2.line(image, (400, 0), (0,400), green, 5)

blue = (0, 0, 255)
cv2.rectangle(image, (200, 200), (250, 250), blue, 2)

white = (255, 255, 255)
cv2.rectangle(image, (20, 300), (40, 350), white, -1)

(cX, cY) = image.shape[1]//2, image.shape[0]//2

cv2.circle(image, (cX, cY - 100), 40, white, 2)

show(image)
  • 这里通过np.zeros生成了一个黑色的底图。通过line、rectangle、circle进行绘制。
  • 特别说明的是绘制函数的最后一个参数,是线的粗细,如果是‘-1’代表进行颜色填充
    在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/kingroc/article/details/84618772