class WebsocketChat(basic.LineReceiver): p = pipan.PiPan() def connectionMade(self): print "Got new client!" self.transport.write('connected ....\n') self.factory.clients.append(self) def connectionLost(self, reason): print "Lost a client!" self.factory.clients.remove(self) def dataReceived(self, data): if data.split(" ")[0] == "COO": coo = data.split(" ")[1].split("=") if coo[0] == "x": self.p.do_pan(int(coo[1])) print "Update X=%s" % coo[1] if coo[0] == "y": self.p.do_tilt(int(coo[1])) print "Update Y=%s" % coo[1] self.factory.messages[float(time.time())] = data self.updateClients(data) def updateClients(self, data): for c in self.factory.clients: c.message(data) def message(self, message): self.transport.write(message + '\n')
def neutral(): p = pipan.PiPan() p.neutral_pan() p.neutral_panc() p.neutral_panu() p.neutral_tiltc() sleep(1)
def main(): #Center the camera's position servo = pipan.PiPan() servo.neutral_pan() servo.neutral_tilt() raw_input("press enter to start searching") print 'Search Begin!' # Start position of pan and tilt servo tilt_pos = 120 pan_pos = 150 # Infinite Loop while True: # Subtle serach when no face is found if (find_face is False): tilt_pos += random.randint(-10, 10) pan_pos += random.randint(-15, 15) # Obvious serach when a face is found else: tilt_pos = random.randint(TILT_MIN_POS, TILT_MAX_POS) pan_pos = random.randint(PAN_MIN_POS, PAN_MAX_POS) # make sure the servos also in the range if tilt_pos > TILT_MIN_POS or tilt_pos < TILT_MAX_POS: servo.do_pan(pan_pos) else: servo.do_pan(150) if pan_pos > PAN_MIN_POS or pan_pos < PAN_MAX_POS: servo.do_tilt(tilt_pos) else: servo.do_tilt(120) face_recognition()
import io import picamera import cv2 import numpy import pipan # center the camera p = pipan.PiPan() p.neutral_pan() p.neutral_tilt() # Pan -> (80, 220), middle position -> 150 # Tilt -> (50, 250) , middle position -> 150 #p.do_pan(100) #p.do_tilt(100) #Create a memory stream so photos doesn't need to be saved in a file stream = io.BytesIO() #Get the picture (low resolution, so it should be quite fast) #Here you can also specify other parameters (e.g.:rotate the image) with picamera.PiCamera() as camera: camera.resolution = (1280, 720) camera.hflip = True camera.vflip = True camera.capture(stream, format='jpeg') #Convert the picture into a numpy array buff = numpy.fromstring(stream.getvalue(), dtype=numpy.uint8) #Now creates an OpenCV image
#!/usr/bin/env python3 import time import os, sys import pipan p_servo = pipan.PiPan() while True: fifoLocation = os.environ['PIPAN_FIFO_LOCATION'] pipein = open(fifoLocation, 'r') line = pipein.readline() print(line) line_array = line.split(' ') if line_array[0] == "servo": p_servo.do_pan(int(line_array[1])) p_servo.do_tilt(int(line_array[2])) pipein.close()
try: wgetfile = urllib2.urlopen(config_url) except: print("ERROR - Download of config.py Failed") print(" Try Rerunning the face-track-install.sh Again.") print(" or") print(" Perform GitHub curl install per Readme.md") print(" and Try Again") print("Exiting %s" % PROG_NAME) quit() f = open('config.py', 'wb') f.write(wgetfile.read()) f.close() from config import * p = pipan.PiPan( ) # Initialize pipan driver My Servo Controller is a Dagu mega # Create Calculated Variables cam_cx = int(CAMERA_WIDTH / 2) cam_cy = int(CAMERA_HEIGHT / 2) big_w = int(CAMERA_WIDTH * WINDOW_BIGGER) big_h = int(CAMERA_HEIGHT * WINDOW_BIGGER) # Setup haar_cascade variables face_cascade = cv2.CascadeClassifier(fface1_haar_path) frontalface = cv2.CascadeClassifier(fface2_haar_path) profileface = cv2.CascadeClassifier(pface1_haar_path) # Color data for OpenCV Markings blue = (255, 0, 0) green = (0, 255, 0) red = (0, 0, 255)
print("Exiting %s" % (progName)) quit() f = open('config.py', 'wb') f.write(wgetfile.read()) f.close() from config import * # import the necessary python libraries import io import time import cv2 from picamera.array import PiRGBArray from picamera import PiCamera from threading import Thread import pipan p = pipan.PiPan() # Initialize pipan driver # Create Calculated Variables cam_cx = CAMERA_WIDTH / 2 cam_cy = CAMERA_HEIGHT / 2 big_w = int(CAMERA_WIDTH * WINDOW_BIGGER) big_h = int(CAMERA_HEIGHT * WINDOW_BIGGER) # Setup haar_cascade variables face_cascade = cv2.CascadeClassifier(fface1_haar_path) frontalface = cv2.CascadeClassifier(fface2_haar_path) profileface = cv2.CascadeClassifier(pface1_haar_path) # Color data for OpenCV Markings blue = (255, 0, 0) green = (0, 255, 0)