-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmouse_drawing_hollow.py
41 lines (32 loc) · 1010 Bytes
/
mouse_drawing_hollow.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
38
39
40
41
import cv2
import numpy as np
#################
## VARIABLES ##
#################
img = np.zeros((512,512,3))
xy_orig = (0,0)
drawobj = False
orig = np.copy(img)
# Funcs
def draw_rectangle(event, x, y, flags, params):
global xy_orig, drawobj, orig, img, last_xy
if event == cv2.EVENT_LBUTTONDOWN:
xy_orig = (x,y)
drawobj = True
orig = np.copy(img)
elif (event == cv2.EVENT_MOUSEMOVE) and (drawobj == True):
img = np.copy(orig)
cv2.rectangle(img, pt1=xy_orig, pt2=(x,y), color=(255,255,255), thickness=1)
last_xy = (x,y)
elif event == cv2.EVENT_LBUTTONUP:
img = np.copy(orig)
cv2.rectangle(img, pt1=xy_orig, pt2=(x,y), color=(255,255,255), thickness=3)
drawobj = False
cv2.namedWindow(winname='my_drawing')
cv2.setMouseCallback('my_drawing',draw_rectangle)
while True:
cv2.imshow('my_drawing',img)
# check for hitting esc key
if cv2.waitKey(1) & 0xFF == 27:
break
cv2.destroyAllWindows()