-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBasicDrawing1.py
37 lines (32 loc) · 1.52 KB
/
BasicDrawing1.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
32
33
34
35
36
37
import cv2
import numpy as np
import matplotlib.pyplot as plt
def ShowWithMatplotlib(img, title):
imgRGB = img[:, :, ::-1]
plt.imshow(imgRGB)
plt.title(title)
plt.show()
colors = {'blue': (255, 0, 0), 'green': (0, 255, 0), 'red': (0, 0, 255), 'yellow': (0, 255, 255),
'magenta': (255, 0, 255), 'cyan': (255, 255, 0), 'white': (255, 255, 255), 'black': (0, 0, 0),
'gray': (125, 125, 125), 'rand': np.random.randint(0, high=256, size=(3,)).tolist(),
'dark_gray': (50, 50, 50), 'light_gray': (220, 220, 220)}
image = np.zeros((400, 400, 3), dtype="uint8")
image[:] = colors['light_gray']
ShowWithMatplotlib(image, '')
cv2.line(image, (0, 0), (400, 400), colors['green'], 3)
cv2.line(image, (0, 400), (400, 0), colors['blue'], 3)
cv2.line(image, (200, 0), (200, 400), colors['red'], 10)
cv2.line(image, (0, 200), (400, 200), colors['yellow'], 10)
ShowWithMatplotlib(image, 'cv2.line()')
image[:] = colors['light_gray']
cv2.rectangle(image, (10, 50), (60, 300), colors['green'], 3)
cv2.rectangle(image, (80, 50), (130, 300), colors['blue'], -1)
cv2.rectangle(image, (150, 50), (350, 100), colors['red'], -1)
cv2.rectangle(image, (150, 150), (350, 300), colors['cyan'], 10)
ShowWithMatplotlib(image, 'cv2.rectangle()')
image[:] = colors['light_gray']
cv2.circle(image, (50, 50), 20, colors['green'], 3)
cv2.circle(image, (100, 100), 30, colors['blue'], -1)
cv2.circle(image, (200, 200), 40, colors['magenta'], 10)
cv2.circle(image, (300, 300), 40, colors['cyan'], -1)
ShowWithMatplotlib(image, 'cv2.circle()')