-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathline_drawer.py
37 lines (26 loc) · 922 Bytes
/
line_drawer.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
# importing the libraries
import cv2
# storing the coordinates
points = []
# event function
def click_event(event, x, y, flag, params):
global points
if event == cv2.EVENT_LBUTTONDOWN:
cv2.circle(img, (x,y), 2, (0,0,0), -1)
points.append((x,y))
if len(points) == 2:
cv2.line(img, points[0], points[1], (0,0,0), 2)
points = []
cv2.imshow('Scientists', img)
elif event == cv2.EVENT_RBUTTONDOWN:
coordinates = 'Coordinates: ('+str(x)+','+str(y)+')'
cv2.putText(img, coordinates, (10,30), cv2.FONT_HERSHEY_SIMPLEX, 0.75, (0,0,0))
cv2.imshow('Scientists', img)
# reading the image
img = cv2.imread('scientists.jpg', -1)
# displaying the image
cv2.imshow('Scientists', img)
# event listener method
cv2.setMouseCallback('Scientists', click_event)
cv2.waitKey(0)
cv2.destroyAllWindows()