Example #1
0
def switch_lights(light_on):
    if light_on == True:
        pantilthat.set_all(255, 255, 255, 255)
    else:
	     pantilthat.set_all(0, 0, 0, 0)
    # light_on = not light_on
    pantilthat.show()
Example #2
0
    def update(self, next_frame, frameCenter):
        initial_h, initial_w, depth = next_frame.shape
        in_frame = cv2.resize(next_frame, (self.w, self.h))
        in_frame = in_frame.transpose(
            (2, 0, 1))  # Change data layout from HWC to CHW
        in_frame = in_frame.reshape((self.n, self.c, self.h, self.w))
        self.exec_net.start_async(request_id=self.next_request_id,
                                  inputs={self.input_blob: in_frame})

        rects = []
        if self.exec_net.requests[self.cur_request_id].wait(-1) == 0:
            # Parse detection results of the current request
            res = self.exec_net.requests[self.cur_request_id].outputs[
                self.out_blob]
            for obj in res[0][0]:
                # Draw only objects when probability more than specified threshold
                if obj[2] > 0.5:
                    xmin = int(obj[3] * initial_w)
                    ymin = int(obj[4] * initial_h)
                    xmax = int(obj[5] * initial_w)
                    ymax = int(obj[6] * initial_h)
                    rects.append([xmin, ymin, xmax - xmin, ymax - ymin])

        self.cur_request_id, self.next_request_id = self.next_request_id, self.cur_request_id
        # check to see if a face was found
        if len(rects) > 0:
            # extract the bounding box coordinates of the face and
            # use the coordinates to determine the center of the
            # face
            (x, y, w, h) = rects[0]
            faceX = int(x + (w / 2))
            faceY = int(y + (h / 2))

            # color the error
            pth.set_all(255, 0, 0)
            if (faceX - frameCenter[0]) > 10:
                pth.set_pixel(0, 255, 255, 255)
            if (faceX - frameCenter[0]) > 30:
                pth.set_pixel(1, 255, 255, 255)
            if (faceX - frameCenter[0]) > 50:
                pth.set_pixel(2, 255, 255, 255)
            if (faceX - frameCenter[0]) < -10:
                pth.set_pixel(7, 255, 255, 255)
            if (faceX - frameCenter[0]) < -30:
                pth.set_pixel(6, 255, 255, 255)
            if (faceX - frameCenter[0]) < -50:
                pth.set_pixel(5, 255, 255, 255)

            pth.show()

            # print("face detected centroid", faceX, faceY)
            # return the center (x, y)-coordinates of the face
            return ((faceX, faceY), rects[0])

        # otherwise no faces were found, so return the center of the
        # frame
        pth.clear()
        pth.show()
        return (frameCenter, None)
Example #3
0
def set_light_color(color, indices=None):
    (r, g, b) = color_to_rgb(color)
    # print("rgb requested: ", (r,g,b))
    if indices is None:
        pantilthat.set_all(r, g, b)
    else:
        for idx in indices:
            pantilthat.set_pixel(idx, r, g, b)
    pantilthat.show()
def set_light():
    getvar_dict = request.query.decode()
    set = request.query.set
    if (set == "on"):
        pantilthat.set_all(0, 0, 0, 255)
        pantilthat.show()
        return ("Light On")
    else:
        pantilthat.clear()
        pantilthat.show()
        return ("Light Off")
Example #5
0
def color_set():
    global r
    global g
    global b
    global w
    
    r = red_select.value
    g = green_select.value
    b = blue_select.value
    w = white_select.value
    
    pantilthat.set_all(r, g, b, w)
    pantilthat.show()
Example #6
0
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"
camera.exposure_mode = "auto"
camera.awb_mode = "auto"
camera.rotation = rotate
Example #7
0
#!/usr/bin/env python

import pantilthat

pantilthat.light_mode(pantilthat.WS2812)
pantilthat.light_type(pantilthat.GRBW)
pantilthat.set_all(255, 255, 255, 255)
pantilthat.show()
Example #8
0
                    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'); 
            elif (command == 'brightness' and len(list)>=2):
                pantilthat.brightness(float(list[1]));
            elif( command == 'set_all' and len(list)==4):
                    pantilthat.set_all(int(list[1]), int(list[2]), int(list[3]));
            elif( command == 'set_all' and len(list)==5):
                    print("setting three colours and white");
                    pantilthat.set_all(int(list[1]), int(list[2]), int(list[3]), int(list[4]));
            elif( command == 'set_pixel' and len(list)==5):
                    pantilthat.set_pixel(int(list[1]), int(list[2]), int(list[3]), int(list[4]));
            elif( command == 'set_pixel' and len(list)==6):
                    pantilthat.set_pixel(int(list[1]), int(list[2]), int(list[3]), int(list[4]), int(list[5]));
            elif( command == 'show'):
                    pantilthat.show();
            else:
                print('error processing command'); 

        except:
            print('error processing command'); 
Example #9
0
def set_all(r, g, b, brightness=None):
    global _brightness
    if brightness is not None:
        _brightness = brightness
    pantilthat.set_all(int(r * _brightness), int(g * _brightness),
                       int(b * _brightness))
Example #10
0
 def do_LIGHT( self, value = 0 ) :
     if value < 0 : value = 0
     if value > 255 : value = 255
     pantilthat.clear()
     pantilthat.set_all( value, value, value )
     pantilthat.show()
Example #11
0
def exit_program():
    pantilthat.set_all(0, 0, 0, 0)
    pantilthat.show()
    pantilthat.pan(0)    
    pantilthat.tilt(-20)
    exit()
Example #12
0
#!/usr/bin/env python

import pantilthat


pantilthat.light_mode(pantilthat.WS2812)
pantilthat.light_type(pantilthat.GRBW)
pantilthat.set_all(0, 0, 0, 255)
pantilthat.show()
Example #13
0
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()
    def start_camera(self, face_position_X, face_position_Y):
        """
		1. Begin video stream
		2. Extract faces from frames
		3. Display frames with bounding boxes
		4. Update global variables with:
			-> pixel coordinates of the center of the frame
			-> pixel coordinates of the center of the faces
		"""
        # signal trap to handle keyboard interrupt
        signal.signal(signal.SIGINT, signal_handler)

        # start the video stream and wait for the camera to warm up
        # vs = VideoStream(usePiCamera=self.rpi, resolution=self.resolution).start()
        print('Starting Camera')
        if self.rpi:
            vs = VideoStream(usePiCamera=self.rpi,
                             resolution=self.resolution).start()
        else:
            vs = VideoStream(src=1, resolution=self.resolution).start()
        time.sleep(2.0)

        # initialize the object center finder
        face_detector = HaarFaceDetector(
            os.path.join(MODELS_DIRECTORY,
                         'haarcascade_frontalface_default.xml'))

        # initialise the recogniser
        # fr = PiFaceRecognition()

        # start recording
        filename = os.path.join(DATA_DIRECTORY, 'recordings',
                                '{}.avi'.format(time.time()))
        cv2.VideoWriter_fourcc(*'MJPG')
        print(filename)
        fourcc = cv2.VideoWriter_fourcc(*'MJPG')
        out = cv2.VideoWriter(filename, fourcc, 20.0, self.resolution)

        while True:
            # grab the frame from the threaded video stream and flip it
            # vertically (since our camera was upside down)
            frame = vs.read()
            frame = cv2.flip(frame, 0)

            # (H, W) = frame.shape[:2]
            # print('H', H)

            # find the object's location
            object_locations = face_detector.extract_faces(frame)
            people = []  # for setting colour

            # get first face for now
            if object_locations:
                # print('{} faces found.'.format(len(object_locations)))
                (face_position_X.value,
                 face_position_Y.value) = object_locations[0][0]
                # print(object_locations[0][0])
                # extract the bounding box and draw it
                for pos, rect, neighbour, weight in object_locations:
                    (x, y, w, h) = rect
                    cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0),
                                  2)

                    # recogniser part
                    gray_frame = cv2.cvtColor(
                        frame, cv2.COLOR_BGR2GRAY)  # convert to gray

                    person, confidence = PiFaceRecognition.infer_lbph_face_recogniser(
                        gray_frame[y:y + h, x:x + w])
                    people.append(person)
                    cv2.putText(frame, person, (x + 5, y - 5),
                                cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255),
                                2)
                    cv2.putText(frame, str(confidence), (x + 5, y + h - 5),
                                cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 0), 1)

            else:
                print('No faces found.')
                face_position_X.value, face_position_Y.value = (
                    self.frame_center_X, self.frame_center_Y)

            if len(people) > 1:
                # set to orange
                pth.set_all(255, 127, 80, 50)
                pth.show()
            elif 'jai' in people:
                # set to green
                pth.set_all(173, 255, 47, 50)
                pth.show()
            elif 'alleeya' in people:
                # set to purple
                pth.set_all(221, 160, 221, 50)
                pth.show()
            else:
                pth.clear()
                pth.show()

            # display the frame to the screen
            cv2.imshow("Pan-Tilt Face Tracking", frame)
            out.write(frame)
            cv2.waitKey(1)

        out.release()
Example #15
0
    def update(self, frame, frameCenter):
        # convert the frame to grayscale
        gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
        # self.flip += 1
        # if self.flip < 100:
        #   return ((320,240), None)
        # elif self.flip < 200:
        #   return (((160,120), None))
        # elif self.flip < 300:
        #   self.flip = 0
        #   return (((160,120), None))
        # if self.flip:
        #   self.testcoord[0] -= 1
        # else:
        #   self.testcoord[0] += 1
        # if self.testcoord[0] > 170:
        #   self.flip = True
        # if self.testcoord[0] < 150:
        #   self.flip = False
        # print(self.testcoord)
        # return (self.testcoord, (self.testcoord[0], self.testcoord[1], 10, 10))

        # detect all faces in the input frame
        rects = self.detector.detectMultiScale(gray,
                                               scaleFactor=1.05,
                                               minNeighbors=9,
                                               minSize=(30, 30),
                                               flags=cv2.CASCADE_SCALE_IMAGE)

        # check to see if a face was found
        if len(rects) > 0:
            # extract the bounding box coordinates of the face and
            # use the coordinates to determine the center of the
            # face
            (x, y, w, h) = rects[0]
            faceX = int(x + (w / 2))
            faceY = int(y + (h / 2))

            # color the error
            pth.set_all(255, 0, 0)
            if (faceX - frameCenter[0]) > 10:
                pth.set_pixel(0, 255, 255, 255)
            if (faceX - frameCenter[0]) > 30:
                pth.set_pixel(1, 255, 255, 255)
            if (faceX - frameCenter[0]) > 50:
                pth.set_pixel(2, 255, 255, 255)
            if (faceX - frameCenter[0]) < -10:
                pth.set_pixel(7, 255, 255, 255)
            if (faceX - frameCenter[0]) < -30:
                pth.set_pixel(6, 255, 255, 255)
            if (faceX - frameCenter[0]) < -50:
                pth.set_pixel(5, 255, 255, 255)

            pth.show()

            # print("face detected centroid", faceX, faceY)
            # return the center (x, y)-coordinates of the face
            return ((faceX, faceY), rects[0])

        # otherwise no faces were found, so return the center of the
        # frame
        pth.clear()
        pth.show()
        return (frameCenter, None)
Example #16
0
#!/usr/bin/env python

import pantilthat

pantilthat.light_mode(pantilthat.WS2812)
pantilthat.light_type(pantilthat.GRBW)
pantilthat.set_all(0, 0, 0, 127)
pantilthat.show()
Example #17
0
#!/usr/bin/env python

import colorsys
import math
import time

import pantilthat

pantilthat.light_mode(pantilthat.WS2812)
pantilthat.light_type(pantilthat.GRBW)

while True:
    t = time.time()
    b = (math.sin(t * 2) + 1) / 2
    b = int(b * 255.0)
    t = round(time.time() * 1000) / 1000
    a = round(math.sin(t) * 90)
    pantilthat.pan(int(a))
    pantilthat.tilt(int(a))
    r, g, b = [
        int(x * 255)
        for x in colorsys.hsv_to_rgb(((t * 100) % 360) / 360.0, 1.0, 1.0)
    ]
    pantilthat.set_all(r, g, b)
    pantilthat.show()
    print(a)
    time.sleep(0.04)
Example #18
0
        # 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)
 
Example #19
0
#!/usr/bin/env python

import sys
from sys import argv
import pantilthat

if len(argv)<2 or len(argv)>5:
    sys.stderr.write( "Syntax: {0} [<red> <green> <blue>] [<white>]\n".format(argv[0]) )
    exit(1)

red   = int(argv[1]) if len(argv)>3 else 0
green = int(argv[2]) if len(argv)>3 else 0
blue  = int(argv[3]) if len(argv)>3 else 0
white = int(argv[4]) if len(argv)>4 else 0
white = int(argv[1]) if len(argv)==2 else white

pantilthat.light_mode(pantilthat.WS2812)
pantilthat.light_type(pantilthat.GRBW)
pantilthat.set_all(red, green, blue, white)
pantilthat.show()