def main(): # Load training data into model print 'Loading training data...' model = cv2.createEigenFaceRecognizer() model.load(config.TRAINING_FILE) print 'Training data loaded!' # Initialize camer and box. camera = config.get_camera() door = hardware.Door() # Move box to locked position. door.lock() print 'Running Lock...' print 'Press button to lock (if unlocked), or unlock if the correct face is detected.' print 'Press Ctrl-C to quit.' while True: try: # Check if capture should be made. # TODO: Check if button is pressed. if door.is_button_up() or is_letter_input('l'): if not door.is_locked: # Lock the door if it is unlocked door.lock() print 'Door is now locked.' else: print 'Button pressed, looking for face...' # Check for the positive face and unlock if found. image = camera.read() # Convert image to grayscale. image = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY) # Get coordinates of single face in captured image. result = face.detect_single(image) if result is None: print 'Could not detect single face! Check the image in capture.pgm' \ ' to see what was captured and try again with only one face visible.' soundChannelC.play(soundC) sleep(.01) continue x, y, w, h = result # Crop and resize image to face. crop = face.resize(face.crop(image, x, y, w, h)) # Test face against model. label, confidence = model.predict(crop) print 'Predicted {0} face with confidence {1} (lower is more confident).'.format( 'POSITIVE' if label == config.POSITIVE_LABEL else 'NEGATIVE', confidence) if label == config.POSITIVE_LABEL and confidence < config.POSITIVE_THRESHOLD: print 'Recognized face! Unlocking Door Now...' door.unlock() soundChannelA.play(soundA) sleep(.01) else: print 'Did not recognize face!' soundChannelB.play(soundB) sleep(.01) except KeyboardInterrupt: door.clean() sys.exit()
def ReadCardID(self): global ID global camera global door global led User = UserData.UserData() ID = User.UserID() camera = config.get_camera() door = hardware.Door() led = hardware.Led()
if select.select([sys.stdin,],[],[],0.0)[0]: input_char = sys.stdin.read(1) return input_char.lower() == letter.lower() return False if __name__ == '__main__': # Load training data into model print 'Loading training data...' model = cv2.face.createEigenFaceRecognizer() model.load(config.TRAINING_FILE) print 'Training data loaded!' # Initialize camera and door. camera = config.get_camera() door = hardware.Door() # Move box to locked position. door.lock() print 'Running Face Detection Software' print 'Press button to lock (if unlocked), or unlock if the correct face is detected.' print 'Press and Enter c for Manual Button Press.' print 'Press Ctrl-C to quit.' while True: # Check if capture should be made. # TODO: Check if button is pressed. if door.is_button_up() or is_letter_input('c') : if not door.is_locked: # Lock the door if it is unlocked door.lock() print 'Door is now locked.' else: