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 flash_lights(): t = time.time() r, g, b = [ int(x * 255) for x in colorsys.hsv_to_rgb(((t * 100) % 360) / 360.0, 1.0, 1.0) ] r, g, b = (255, 255, 255) for i in range(2, 6): pantilthat.set_pixel(i, r, g, b) pantilthat.show()
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');
#!/usr/bin/env python import colorsys import math import time import pantilthat pantilthat.light_mode(pantilthat.WS2812) pantilthat.light_type(pantilthat.GRBW) r, g, b, w = 0, 0, 0, 50 while True: for x in range(18): pantilthat.set_pixel(x, r, g, b, w) pantilthat.show() p = int(math.sin(time.time()) * 90) t = int(math.sin(time.time()) * 90) pantilthat.pan(p) pantilthat.tilt(t)
def set_pixel(x, r, g, b, brightness=None): global _brightness if brightness is not None: _brightness = brightness pantilthat.set_pixel(x, int(r * _brightness), int(g * _brightness), int(b * _brightness))
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)
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)
#!/usr/bin/env python import colorsys import math import time import pantilthat pantilthat.light_mode(pantilthat.WS2812) pantilthat.light_type(pantilthat.GRBW) r, g, b, w = 0, 0, 0, 50 while True: pantilthat.brightness(128) for x in range(8): pantilthat.set_pixel(x, 0, 0, 255) pantilthat.show() time.sleep(0.1) # pantilthat.set_pixel(x, r, g, b, w) #pantilthat.set_pixel(0, 255, 0, 255) #p = int(math.sin(time.time()) * 90) #t = int(math.sin(time.time()) * 90) #print("pan: ", p) #print("tilt: ", t) # pantilthat.pan(p) # pantilthat.tilt(t)