OpenCV draw lines, rectangles and garden

First, we need an import library:

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

Custom image is shown as a function:

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

Create a black canvas and show it:

= np.zeros Image (( 300 , 300 , 3 ), dtype = ' uint8 ' ) 
Show (Image) # show is really black picture

# Draw a line (straight line)
green=(0,255,0)
cv2.line(image,(0,0),(300,300),green)
show(image)

blue=(0,0,255)
cv2.line(image,(300,0),(150,150),blue,5)
show(image)#不知道为什么左下角还有一条线呢?

red=(255,0,0)
cv2.line(image,(0,300),(150,150),red,5)
show(image)#不知道为什么左下角还有一条线呢?

#现在开始画矩形
cv2.rectangle(image,(90,90),(220,220),green,-1)#-1表示的是填充矩形的意思
show(image)

#现在开始画圆
image2=np.zeros((300,300,3),dtype='uint8')

在画圆的时候重新绘制一个画布

green=(0,255,0)
cv2.circle(image2,(150,150),50,green,3)
show(image2

 

Guess you like

Origin www.cnblogs.com/geeksongs/p/11074327.html