-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspy_mode.py
63 lines (46 loc) · 1.28 KB
/
spy_mode.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
from pynput import keyboard
from lcd import write_lcd, clear_lcd
from dc_motors import forward, backward, turn_left, turn_right, stop
import cv2
import threading
import os
cam = cv2.VideoCapture(0)
def camera():
while(True):
ret, frame = cam.read()
cv2.imshow('frame', frame)
cv2.waitKey(1)
camera_thread = threading.Thread(target=camera)
camera_thread.start()
def on_press(key):
try:
if key.char == 'w':
forward()
elif key.char == 's':
backward()
elif key.char == 'a':
turn_left()
elif key.char == 'd':
turn_right()
except AttributeError:
pass
def on_release(key):
try:
if key.char == 'w':
stop()
elif key.char == 's':
stop()
elif key.char == 'a':
stop()
elif key.char == 'd':
stop()
except AttributeError:
cam.release()
cv2.destroyAllWindows()
os.system('python3 ~/RPI-Project-Rover/main.py')
write_lcd(first_line=' SPY MODE', second_line=' READY')
with keyboard.Listener(
on_press=on_press,
on_release=on_release) as listener:
listener.join()
camera_thread.join()