def __init__(self): self.settings_marshaller = settings.SettingsMarshaller() self.settings = self.settings_marshaller.settings self.face_recognizer = face_recognizer.FaceRecognizer(self.settings) self.gtk_window = gtk.Window(gtk.WINDOW_TOPLEVEL) self.gtk_window.connect("destroy", gtk.main_quit) self.gtk_window.connect("key_press_event", self.on_key_press_event) self.gtk_window.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(0, 0, 0)) self.gtk_fixed = gtk.Fixed() self.gtk_window.add(self.gtk_fixed) if self.settings.default_height is not None and self.settings.default_width is not None: self.gtk_window.set_default_size(self.settings.default_width, self.settings.default_height) self.gtk_window.fullscreen() self.gtk_fixed.show() self.gtk_window.show() self.screen_width, self.screen_height = self.gtk_window.get_size() self.gtk_drawing_area = gtk.DrawingArea() self.gtk_drawing_area.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(0, 0, 0)) self.gtk_drawing_area.connect("expose_event", self.expose_event) self.gtk_drawing_area.connect("configure_event", self.configure_event) self.gtk_drawing_area.set_size_request(self.screen_width, self.screen_height) self.gtk_pixmap = None self.gtk_fixed.add(self.gtk_drawing_area) self.gtk_drawing_area.show() #self.pixbuf_animation_blue_bird_iter = gtk.gdk.PixbufAnimation('images/bluebird.gif').get_iter() self.scene = scene.Scene() self.settings_marshaller.default_if_none('background_image_width', self.screen_width) self.settings_marshaller.default_if_none('background_image_height', self.screen_height) self.settings_marshaller.default_if_none('left_pad', 0) self.settings_marshaller.default_if_none('top_pad', 0) self.settings_marshaller.default_if_none('showing_background_image', False) self.settings_marshaller.default_if_none('showing_face_rectangles', False) self.settings_marshaller.default_if_none('recognition_threshold', 80) self.settings_marshaller.save() self.camera = self.get_camera() self.background_thread = threading.Thread(target=self.background_work) self.background_thread.daemon = True self.kill_background = False self.recognizing_face = False self.pending_delete_training = False self.temporary_notice_timer = None self.temporary_notice = None
import unittest import face_recognizer from skimage import io import dlib facer = face_recognizer.FaceRecognizer() img_name = 'test/img/test_urgant.jpg' img_name1 = 'test/img/urgant2.jpg' img_name2 = 'test/img/mart1.jpg' class RecognizerTest(unittest.TestCase): def test_points_file(self): try: predictor = dlib.shape_predictor(facer.points_file_name) except RuntimeError: predictor = [] self.assertNotEqual(predictor, []) def test_model_file(self): try: model = dlib.face_recognition_model_v1(facer.model_file_name) except RuntimeError: model = [] self.assertNotEqual(model, []) def test_load_model(self): failed = False try: facer.load_model(facer.model_file_name, facer.points_file_name) except Exception:
- Display a found face, ask who's face this is, discard "" 3. Incorporate RPi's camera module to constantly scan for faces 4. If recognized face, load personalized document (browser?) ''' import cv2, os #import numpy as np from PIL import Image import face_recognizer # Test if we already have a recognizer set load_previous = "./last_recognizer.xml" create_new = "./training_set" #create_new = "./yalefaces" recog = face_recognizer.FaceRecognizer(load_previous, create_new) #recog.save_recognizer("./last_recognizer.xml") path = "./testing_set" # Append the images with the extension .sad into image_paths #image_paths = [os.path.join(path, f) for f in os.listdir(path) if f.endswith('.sad')] image_paths = [os.path.join(path, f) for f in os.listdir(path)] for image_path in image_paths: predict_image_pil = Image.open(image_path).convert('L') predict_image = np.array(predict_image_pil, 'uint8') cascade_path = "haarcascade_frontalface_default.xml" face_cascade = cv2.CascadeClassifier(cascade_path) faces = face_cascade.detectMultiScale(predict_image) for (x, y, w, h) in faces: #nbr_predicted, conf = recognizer.predict(predict_image[y: y + h, x: x + w])