-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdraw.py
31 lines (24 loc) · 907 Bytes
/
draw.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import cv2 as cv
import numpy as np
#uint8 -> datatype of images basically
#width, height, nº of color channels
blank = np.zeros((500, 500, 3), dtype='uint8')
cv.imshow('Blank', blank)
# 1. Paint the image a certain color - RGB => BGR
# blank[200:300, 300:400] = 0,255,0
# cv.imshow('Green', blank)
# 2. Draw a Rectangle
cv.rectangle(blank, (0,0), (blank.shape[1]//2,blank.shape[0]//2), (0,255,0), thickness=cv.FILLED)
#same as:
# cv.rectangle(blank, (0,0), (250,500), (0,255,0), thickness=-1)
cv.imshow('Rectangle', blank)
# 3. Draw a Circle
cv.circle(blank, (blank.shape[1]//2,blank.shape[0]//2), 40, (0,0,255), thickness=-1)
cv.imshow('Circle', blank)
# 4. Draw a Line
cv.line(blank, (100,250), (300,400), (255,255,255), thickness=3)
cv.imshow('Line', blank)
# 5. Write text
cv.putText(blank, 'Hello', (225,225), cv.FONT_HERSHEY_TRIPLEX, 1.0, (0,255,0), 2)
cv.imshow('Text', blank)
cv.waitKey(0)