-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
52 lines (43 loc) · 1.57 KB
/
main.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
import argparse
import yaml
import numpy as np
import cv2
from src.controllers.cc_controller import PCRController
parser = argparse.ArgumentParser()
parser.add_argument('--config', type=str, default="configs/config1.yaml")
args = parser.parse_args()
config = yaml.safe_load(open(args.config, 'r'))
controller = PCRController(**config['controller_params'])
end_point = [0, 0]
mouse_pressed = False
playback = False
playback_points = []
def mouse_callback(event, x, y, flags, param):
global end_point, mouse_pressed, playback, playback_points
if event == cv2.EVENT_MOUSEMOVE:
if mouse_pressed:
playback_points += [(np.array([x, y]) - controller.offset)/controller.scale]
else:
end_point = (np.array([x, y]) - controller.offset)/controller.scale
controller.update_end_point(end_point)
elif event == cv2.EVENT_LBUTTONDOWN:
if not playback:
playback_points = []
mouse_pressed = True
playback = False
elif event == cv2.EVENT_LBUTTONUP:
mouse_pressed = False
playback = len(playback_points) > 0
cv2.namedWindow("Controller")
cv2.setMouseCallback("Controller", mouse_callback)
while True:
if playback:
controller.update_end_point(playback_points.pop(0))
if len(playback_points) == 0:
playback = False
img = controller.draw()
# img = cv2.circle(img, (int(end_point[0]*100 + img.shape[0]//2), int(end_point[1]*100) + img.shape[1]//2), 5, (0, 0, 0), -1)
cv2.imshow('Controller', img)
k = cv2.waitKey(1)
if k == ord('q'):
break