def main(): print('Initializing HAT') hat.servo_enable(1, False) hat.servo_enable(2, False) hat.light_mode(hat.WS2812) hat.light_type(hat.GRBW) print('Initializing camera') with picamera.PiCamera() as camera: camera.resolution = (WIDTH, HEIGHT) camera.framerate = FRAMERATE camera.vflip = VFLIP # flips image rightside up, as needed camera.hflip = HFLIP # flips image left-right, as needed sleep(1) # camera warm-up time print('Initializing websockets server on port %d' % WS_PORT) WebSocketWSGIHandler.http_version = '1.1' websocket_server = make_server( '', WS_PORT, server_class=WSGIServer, handler_class=WebSocketWSGIRequestHandler, app=WebSocketWSGIApplication(handler_cls=StreamingWebSocket)) websocket_server.initialize_websockets_manager() websocket_thread = Thread(target=websocket_server.serve_forever) print('Initializing HTTP server on port %d' % HTTP_PORT) http_server = StreamingHttpServer() http_thread = Thread(target=http_server.serve_forever) print('Initializing broadcast thread') output = BroadcastOutput(camera) broadcast_thread = BroadcastThread(output.converter, websocket_server) print('Starting recording') camera.start_recording(output, 'yuv') try: print('Starting websockets thread') websocket_thread.start() print('Starting HTTP server thread') http_thread.start() print('Starting broadcast thread') broadcast_thread.start() while True: camera.wait_recording(1) except KeyboardInterrupt: pass finally: print('Stopping recording') camera.stop_recording() print('Waiting for broadcast thread to finish') broadcast_thread.join() print('Shutting down HTTP server') http_server.shutdown() print('Shutting down websockets server') websocket_server.shutdown() print('Waiting for HTTP server thread to finish') http_thread.join() print('Disabling servos') hat.servo_enable(1, False) hat.servo_enable(2, False) hat.clear() hat.show() print('Waiting for websockets thread to finish') websocket_thread.join()
def test_lights(): pantilthat.light_mode(pantilthat.WS2812) pantilthat.light_type(pantilthat.GRBW) r, g, b, w = 0, 0, 0, 0 try: while True: pantilthat.set_all(0, 0, 0, 0) pantilthat.show() time.sleep(0.5) pantilthat.set_all(100, 0, 0, 0) pantilthat.show() time.sleep(0.5) pantilthat.set_all(0, 100, 0, 0) pantilthat.show() time.sleep(0.5) pantilthat.set_all(0, 0, 100, 0) pantilthat.show() time.sleep(0.5) pantilthat.set_all(100, 100, 0, 0) pantilthat.show() time.sleep(0.5) pantilthat.set_all(0, 100, 100, 0) pantilthat.show() time.sleep(0.5) pantilthat.set_all(100, 0, 100, 0) pantilthat.show() time.sleep(0.5) pantilthat.set_all(100, 100, 100, 0) time.sleep(0.5) pantilthat.show() except KeyboardInterrupt: pantilthat.clear() pantilthat.show()
# if the tilt angle is within the range, tilt if in_range(tiltAngle, servoRange[0]+20, servoRange[1] ): pth.tilt(tiltAngle-20) time.sleep(0.1) # check to see if this is the main body of execution if __name__ == "__main__": # construct the argument parser and parse the arguments ap = argparse.ArgumentParser() ap.add_argument("-m", "--model", type=str, required=True, help="path to openvino model for face detection") args = vars(ap.parse_args()) #set up lights: pth.light_mode(pth.WS2812) pth.light_type(pth.RGB) pth.set_all(0,0,255) pth.show() # start a manager for managing process-safe variables with Manager() as manager: # enable the servos pth.servo_enable(1, True) pth.servo_enable(2, True) # set integer values for the object center (x, y)-coordinates centerX = manager.Value("i", 0) centerY = manager.Value("i", 0) # set integer values for the object's (x, y)-coordinates objX = manager.Value("i", 0) objY = manager.Value("i", 0)
import picamera import time import pantilthat import datetime from time import sleep # Initialise PanTilt Hat a = 0 # intitial pan position (center) b = -20 # intitial tilt position (center) r = 0 # neopixel red off g = 0 # neopixel green off b = 0 # neopixel blue off w = 0 # neopixel white off pantilthat.light_mode(pantilthat.WS2812) pantilthat.light_type(pantilthat.GRBW) pantilthat.pan(a) pantilthat.tilt(b) pantilthat.set_all(r, g, b, w) pantilthat.show() # Initialise Camera camera = picamera.PiCamera() win_size = (500, 40, 640, 480) x = 0 # set zoom to zero y = 0 # set zoom to zero video = (1920, 1088) photo = (2592, 1944) framerate = 30 rotate = 180 effect_value = "none"
else: try: if (command == 'pan' and len(list)>=2): pantilthat.pan(float(list[1])); elif (command == 'tilt' and len(list)>=2): pantilthat.tilt(float(list[1])); elif (command == 'goto' and len(list)>=3): pantilthat.pan(float(list[1])); pantilthat.tilt(float(list[2])); elif (command == 'get_pan'): print(pantilthat.get_pan()); elif (command == 'get_tilt'): print(pantilthat.get_tilt()); elif( command == 'light_type' and len(list)>=2): if( list[1] == 'RGB' ): pantilthat.light_type(pantilthat.RGB); elif( list[1] == 'GRB' ): pantilthat.light_type(pantilthat.GRB); elif( list[1] == 'RGBW' ): pantilthat.light_type(pantilthat.RGBW); elif( list[1] == 'GRBW' ): pantilthat.light_type(pantilthat.GRBW); else: print('error: light_type requires parameter RBB, GRB, RGBW or GRBW'); elif( command == 'light_mode' and len(list)>=2): if( list[1] == 'PWM' ): pantilthat.light_mode(pantilthat.PWM); elif( list[1] == 'WS2812' ): pantilthat.light_mode(pantilthat.WS2812); else: print('error: light_mode requires parameter PWM or WS2812');
import os, sys sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from utils import HaarFaceDetector, PID from src.face_recognition import PiFaceRecognition MODELS_DIRECTORY = os.path.join( os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'models') DATA_DIRECTORY = os.path.join( os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'data') import json import matplotlib.pyplot as plt import pandas as pd pth.light_mode(pth.WS2812) pth.light_type(pth.GRBW) class PiFaceDetector: """ Aim a Raspberry Pi camera at one or more faces. If single face: -> aim at center of face If multiple faces: -> aim at average of center of faces -> move from one face to the next, staying on each face for n seconds """ def __init__(self, rpi=True): self.rpi = rpi