-
Notifications
You must be signed in to change notification settings - Fork 0
/
draw_circle.py
48 lines (41 loc) · 1.19 KB
/
draw_circle.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
42
43
44
45
46
47
48
import cv2
def my_draw(event,x,y,flags,param):
if event==cv2.EVENT_LBUTTONDOWN:
print ('x',x)
#print ('y',y)
print ('event',event)
print ('flags',flags)
print ('param',param)
cv2.circle(img,(x,y),100,(255,0,0),5)
img = cv2.imread("apple.jpeg")
window_name='my_window'
cv2.namedWindow(winname=window_name)
cv2.setMouseCallback(window_name,my_draw)
while True:
cv2.imshow(window_name,img)
## waitkey(0) does not draw circle
## waitkey(1) also works
#key = cv2.waitKey(30)
#print('key',key)
## draws immediately after lbutton down
## breaks when escape key is pressed
#if key & 0xFF == 27:
#break
##below works in a different way
##first captures the x,y location
##does not draw immediately
##and draws after any other key is pressed
## breaks when esc is pressed
#key2 = cv2.waitKey(0)
#print('key2',key2)
#if key2 & 0xFF == 27:
#break
##first captures the x,y location
##does not draw immediately
##and draws after any other key is pressed
## breaks when q is pressed
key1 = cv2.waitKey(0)
print ('key1',key1)
if key1 & 0xFF == ord('q'):
break
cv2.destroyAllWindows()