-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.py
executable file
·33 lines (27 loc) · 879 Bytes
/
cli.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
import cv2
class Cli:
def __init__(self, image, wsize = 30, hsize =30):
self.image = image.copy()
self.wsize = wsize
self.hsize = hsize
self.points = []
def handle_click(self, event, y, x, flags,param):
if event == cv2.EVENT_LBUTTONDOWN:
# half = self.wsize // 2
uHalf = self.wsize // 2
lHalf = self.hsize // 2
upper = y - uHalf, x - lHalf
lower = y + uHalf, x + lHalf
self.points.append((x, y))
cv2.rectangle(self.image, upper, lower, 255, 1)
def ask_points(self):
cv2.namedWindow('image')
cv2.setMouseCallback('image', self.handle_click)
while cv2.waitKey(1) != 27:
cv2.imshow('image', self.image)
cv2.destroyAllWindows()
return self.points
if __name__ == '__main__':
image = cv2.imread('./images/patient4/1_0.png', 0)
cli = Cli(image)
print(cli.ask_points())