forked from superquadratic/beat-bricks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
initializer.py
36 lines (26 loc) · 827 Bytes
/
initializer.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
import json
import cv2
WINDOW = 'hello'
class Initializer(object):
def __init__(self):
self.rect = []
self.capture = cv2.VideoCapture(0)
def on_mouse(event, x, y, unused, user_data):
if event == cv2.EVENT_LBUTTONDOWN:
self.click(x, y)
cv2.namedWindow(WINDOW)
cv2.setMouseCallback(WINDOW, on_mouse)
def click(self, x, y):
self.rect.append([x, y])
def run(self):
while len(self.rect) < 4:
success, frame = self.capture.read()
if success:
cv2.imshow(WINDOW, frame)
if cv2.waitKey(100) != -1:
break
if __name__ == '__main__':
initializer = Initializer()
initializer.run()
with open('rect.json', 'w') as f:
json.dump(initializer.rect, f)