-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMouseEvent.py
More file actions
37 lines (29 loc) · 1004 Bytes
/
MouseEvent.py
File metadata and controls
37 lines (29 loc) · 1004 Bytes
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
#impoting the libraries
import numpy as np
import cv2
#setting up the window
winName = "win"
cv2.namedWindow(winName)
img = np.zeros((512, 512, 3), np.uint8)
#mouse call back function i.e when mouse is used this function will be activated
def drawCircle(event, x, y, flags, param):
#if left mouse button is pressed twice
if event == cv2.EVENT_LBUTTONDBLCLK:
#draws a green circle
cv2.circle(img, (x, y), 40, (0, 0, 255), -1)
#if right mouse button is pressed twice
if event == cv2.EVENT_RBUTTONDBLCLK:
#makes the screen blank(black)
img[:] = [0, 0, 0]
#method to call the callback function when mouse is used
cv2.setMouseCallback(winName, drawCircle)
#main function
def main():
#continues until 'esc' key is pressed
while(True):
cv2.imshow(winName, img)
if cv2.waitKey(1) == 27:
break;
cv2.destroyAllWindows()
if __name__ == "__main__":
main()