-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoordinate_picker.py
66 lines (52 loc) · 1.52 KB
/
coordinate_picker.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
## Written by Katya/Aral/Jasmina
# importing the module
import cv2
# function to display the coordinates of
# of the points clicked on the image
def click_event(event, x, y, flags, params):
# checking for left mouse clicks
if event == cv2.EVENT_LBUTTONDOWN:
# displaying the coordinates
# on the Shell
print(x, ' ', y)
# displaying the coordinates
# on the image window
font = cv2.FONT_HERSHEY_SIMPLEX
cv2.putText(img, str(x) + ',' +
str(y), (x,y), font,
1, (255, 0, 0), 2)
cv2.imshow('./test_resized/busan2.jpg', img)
# checking for right mouse clicks
if event==cv2.EVENT_RBUTTONDOWN:
# displaying the coordinates
# on the Shell
print(x, ' ', y)
# Save the values to an array
values = [[x, y]]
# Print the values in the desired format
for value in values:
print(value)
# displaying the coordinates
# on the image window
font = cv2.FONT_HERSHEY_SIMPLEX
b = img[y, x, 0]
g = img[y, x, 1]
r = img[y, x, 2]
cv2.putText(img, str(b) + ',' +
str(g) + ',' + str(r),
(x,y), font, 1,
(255, 255, 0), 2)
cv2.imshow('./test_resized/busan2.jpg', img)
# driver function
if __name__=="__main__":
# reading the image
img = cv2.imread('./test_resized/busan2.jpg', 1)
# displaying the image
cv2.imshow('./test_resized/busan2.jpg', img)
# setting mouse handler for the image
# and calling the click_event() function
cv2.setMouseCallback('./test_resized/busan2.jpg', click_event)
# wait for a key to be pressed to exit
cv2.waitKey(0)
# close the window
cv2.destroyAllWindows()