|
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 67 68 69 70 71 |
from fusion_hat.servo import Servo from fusion_hat.stt import STT import threading import cv2 from picamera2 import Picamera2 piCam = Picamera2() panPin = 2 tiltPin = 3 panServo = Servo(panPin) tiltServo = Servo(tiltPin) x = 0 y =-20 xDelta = 10 yDelta = 5 panServo.angle(x) tiltServo.angle(y) W=1280 H=720 RES = (W,H) piCam.preview_configuration.main.size = RES piCam.preview_configuration.main.format = "RGB888" piCam.preview_configuration.controls.FrameRate=60 piCam.preview_configuration.align() piCam.configure("preview") piCam.start() running = True def listenThread(): global running, x, y stt = STT(language = "en-us") while running: print("Listening . . .") result = stt.listen(stream = False) command = result.strip() print("Command was: ", command) if command == "right": x = x + xDelta panServo.angle(x) if command == "left": x= x - xDelta panServo.angle(x) if command == "up": y = y - yDelta tiltServo.angle(y) if command == "down": y = y + yDelta tiltServo.angle(y) if command == "quit": running = False break print("Thread Terminated") myThread = threading.Thread(target = listenThread, daemon = True) myThread.start() while running: frame= piCam.capture_array() frame=cv2.flip(frame,-1) cv2.imshow("Camera", frame) cv2.moveWindow("Camera",0,60) if cv2.waitKey(1)==ord('q'): running = False break cv2.destroyAllWindows() piCam.stop() print('Program Terminated') |
