-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmouse.py
36 lines (32 loc) · 1.59 KB
/
mouse.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
`import cv2
import numpy as np
def detect_quadrant(event, x, y, flags, param):
if event == cv2.EVENT_LBUTTONDOWN:
if x > width/2:
if y > height/2:
point_bottom_left = (int(width/2), int(height/2))
point_top_right = (width-1, height-1)
else:
point_top_right = (width-1, int(height/2))
point_bottom_left = (int(width/2), 0)
else:
if y > height/2:
point_top_right = (int(width/2), int(height/2))
point_bottom_left = (0, height/2)
else:
point_bottom_left = (0,0)
point_top_right = (int(width/2), int(height/2))
cv2.rectangle(img, (0,0), (width-1,height-1), (255,255,255), -1)
cv2.rectangle(img, point_bottom_left, point_top_right, (0,255,0), -1)
if __name__=='__main__':
width, height = 640, 480
img = 255 * np.ones((height, width, 3), dtype = np.uint8)
cv2.namedWindow('input_window')
cv2.setMouseCallback('input_window', detect_quadrant) # A callback function is one that should be called when a certain condition is met.
# Instead of being called immediately, the callback function is called at a certain point in the future.
while True:
cv2.imshow('input_window', img)
c = cv2.waitKey(1) # this will say to callback that stop for 10 sec
if c == 27:
break
cv2.destroyAllWindows()