-
Notifications
You must be signed in to change notification settings - Fork 0
/
05-Solution.py
24 lines (22 loc) · 916 Bytes
/
05-Solution.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
import cv2
import numpy as np
# Create a function based on a CV2 Event (Left button click)
def draw_circle(event,x,y,flags,param):
if event == cv2.EVENT_RBUTTONDOWN:
cv2.circle(img,(x,y),100,(0,0,255),-1)
# Open Image
img = cv2.imread("../DATA/dog_backpack.jpg")
# This names the window so we can reference it
cv2.namedWindow(winname='dog')
# Connects the mouse button to our callback function
cv2.setMouseCallback('dog',draw_circle)
while True: #Runs forever until we break with Esc key on keyboard
# Shows the image window
cv2.imshow('dog',img)
# EXPLANATION FOR THIS LINE OF CODE:
# https://stackoverflow.com/questions/35372700/whats-0xff-for-in-cv2-waitkey1/39201163
if cv2.waitKey(20) & 0xFF == 27:
break
# Once script is done, its usually good practice to call this line
# It closes all windows (just in case you have multiple windows called)
cv2.destroyAllWindows()