Example #1
0
    def init_algorithm(
            self,
            save_training_file='datasets/faces_training.pkl',
            load_preprocessed_data='datasets/faces_preprocessed.pkl',
            load_mlp='params/mlp.xml',
            face_casc='params/haarcascade_frontalface_default.xml',
            left_eye_casc='params/haarcascade_lefteye_2splits.xml',
            right_eye_casc='params/haarcascade_righteye_2splits.xml'):
        
        self.data_file = save_training_file
        self.faces = FaceDetector(face_casc, left_eye_casc, right_eye_casc)
        self.head = None

        # load preprocessed dataset to access labels and PCA params
        if path.isfile(load_preprocessed_data):
            (_, y_train), (_, y_test), V, m = homebrew.load_from_file(
                load_preprocessed_data)
            self.pca_V = V
            self.pca_m = m
            self.all_labels = np.unique(np.hstack((y_train, y_test)))

            # load pre-trained multi-layer perceptron
            if path.isfile(load_mlp):
                layer_sizes = np.array([self.pca_V.shape[1],
                                        len(self.all_labels)])
                self.MLP = MultiLayerPerceptron(layer_sizes, self.all_labels)
                self.MLP.load(load_mlp)
            else:
                print "Warning: Testing is disabled"
                print "Could not find pre-trained MLP file ", load_mlp
                self.testing.Disable()
        else:
            print "Warning: Testing is disabled"
            print "Could not find data file ", load_preprocessed_data
            self.testing.Disable()
Example #2
0
    def InitAlgorithm(self, faceCasc, leftEyeCasc, rightEyeCasc, loadPreprocessedData, loadMLP):
        # load pre-trained cascades
        self.faceCasc = cv3.CascadeClassifier(faceCasc)
        if self.faceCasc.empty():
            print 'Warning: Could not load face cascade:', faceCasc
            raise SystemExit
        self.leftEyeCasc = cv3.CascadeClassifier(leftEyeCasc)
        if self.leftEyeCasc.empty():
            print 'Warning: Could not load left eye cascade:', leftEyeCasc
            raise SystemExit
        self.rightEyeCasc = cv3.CascadeClassifier(rightEyeCasc)
        if self.rightEyeCasc.empty():
            print 'Warning: Could not load right eye cascade:', rightEyeCasc
            raise SystemExit

        # load preprocessed dataset to access labels and PCA params
        if path.isfile(loadPreprocessedData):
            (_,y_train),(_,y_test),self.pca_V,self.pca_m = homebrew.load_from_file(loadPreprocessedData)
            self.allLabels = np.unique(np.hstack((y_train,y_test)))

            # load pre-trained multi-layer perceptron
            if path.isfile(loadMLP):
                self.MLP = MultiLayerPerceptron(np.array([self.pca_V.shape[1], len(self.allLabels)]),
                    self.allLabels)
                self.MLP.load(loadMLP)
            else:
                print "Warning: Testing is disabled"
                print "Could not find pre-trained MLP file ", loadMLP
                self.testing.Disable()
        else:
            print "Warning: Testing is disabled"
            print "Could not find preprocessed data file ", loadPreprocessedData
            self.testing.Disable()
    def init_algorithm(
            self,
            save_training_file='datasets/faces_training.pkl',
            load_preprocessed_data='datasets/faces_preprocessed.pkl',
            load_mlp='params/mlp.xml',
            face_casc='params/haarcascade_frontalface_default.xml',
            left_eye_casc='params/haarcascade_lefteye_2splits.xml',
            right_eye_casc='params/haarcascade_righteye_2splits.xml'):
        """Initializes face detector and facial expression classifier

            This method initializes both the face detector and the facial
            expression classifier.

            :param save_training_file:     filename for storing the assembled
                                           training set
            :param load_preprocessed_data: filename for loading a previously
                                           preprocessed dataset (for
                                           classification in Testing Mode)
            :param load_mlp:               filename for loading a pre-trained
                                           MLP classifier (use the script
                                           train_test_mlp.py)
            :param face_casc:              path to a face cascade
            :param left_eye_casc:          path to a left-eye cascade
            :param right_eye_casc:         path to a right-eye cascade
        """
        self.data_file = save_training_file
        self.faces = FaceDetector(face_casc, left_eye_casc, right_eye_casc)
        self.head = None

        # load preprocessed dataset to access labels and PCA params
        if path.isfile(load_preprocessed_data):
            (_, y_train), (
                _,
                y_test), V, m = homebrew.load_from_file(load_preprocessed_data)
            self.pca_V = V
            self.pca_m = m
            self.all_labels = np.unique(np.hstack((y_train, y_test)))

            # load pre-trained multi-layer perceptron
            if path.isfile(load_mlp):
                layer_sizes = np.array(
                    [self.pca_V.shape[1],
                     len(self.all_labels)])
                self.MLP = MultiLayerPerceptron(layer_sizes, self.all_labels)
                self.MLP.load(load_mlp)
            else:
                print "Warning: Testing is disabled"
                print "Could not find pre-trained MLP file ", load_mlp
                self.testing.Disable()
        else:
            print "Warning: Testing is disabled"
            print "Could not find data file ", load_preprocessed_data
            self.testing.Disable()
    def init_algorithm(
            self,
            save_training_file='datasets/faces_training.pkl',
            load_preprocessed_data='datasets/faces_preprocessed.pkl',
            load_mlp='params/mlp.xml',
            face_casc='params/haarcascade_frontalface_default.xml',
            left_eye_casc='params/haarcascade_lefteye_2splits.xml',
            right_eye_casc='params/haarcascade_righteye_2splits.xml'):
        """Initializes face detector and facial expression classifier

            This method initializes both the face detector and the facial
            expression classifier.

            :param save_training_file:     filename for storing the assembled
                                           training set
            :param load_preprocessed_data: filename for loading a previously
                                           preprocessed dataset (for
                                           classification in Testing Mode)
            :param load_mlp:               filename for loading a pre-trained
                                           MLP classifier (use the script
                                           train_test_mlp.py)
            :param face_casc:              path to a face cascade
            :param left_eye_casc:          path to a left-eye cascade
            :param right_eye_casc:         path to a right-eye cascade
        """
        self.data_file = save_training_file
        self.faces = FaceDetector(face_casc, left_eye_casc, right_eye_casc)
        self.head = None

        # load preprocessed dataset to access labels and PCA params
        if path.isfile(load_preprocessed_data):
            (_, y_train), (_, y_test), V, m = homebrew.load_from_file(
                load_preprocessed_data)
            self.pca_V = V
            self.pca_m = m
            self.all_labels = np.unique(np.hstack((y_train, y_test)))

            # load pre-trained multi-layer perceptron
            if path.isfile(load_mlp):
                layer_sizes = np.array([self.pca_V.shape[1],
                                        len(self.all_labels)])
                self.MLP = MultiLayerPerceptron(layer_sizes, self.all_labels)
                self.MLP.load(load_mlp)
            else:
                print "Warning: Testing is disabled"
                print "Could not find pre-trained MLP file ", load_mlp
                self.testing.Disable()
        else:
            print "Warning: Testing is disabled"
            print "Could not find data file ", load_preprocessed_data
            self.testing.Disable()
Example #5
0
    def InitAlgorithm(self, faceCasc, leftEyeCasc, rightEyeCasc,
                      loadPreprocessedData, loadMLP):
        # load pre-trained cascades
        self.faceCasc = cv3.CascadeClassifier(faceCasc)
        if self.faceCasc.empty():
            print 'Warning: Could not load face cascade:', faceCasc
            raise SystemExit
        self.leftEyeCasc = cv3.CascadeClassifier(leftEyeCasc)
        if self.leftEyeCasc.empty():
            print 'Warning: Could not load left eye cascade:', leftEyeCasc
            raise SystemExit
        self.rightEyeCasc = cv3.CascadeClassifier(rightEyeCasc)
        if self.rightEyeCasc.empty():
            print 'Warning: Could not load right eye cascade:', rightEyeCasc
            raise SystemExit

        # load preprocessed dataset to access labels and PCA params
        if path.isfile(loadPreprocessedData):
            (_, y_train), (
                _, y_test), self.pca_V, self.pca_m = homebrew.load_from_file(
                    loadPreprocessedData)
            self.allLabels = np.unique(np.hstack((y_train, y_test)))

            # load pre-trained multi-layer perceptron
            if path.isfile(loadMLP):
                self.MLP = MultiLayerPerceptron(
                    np.array([self.pca_V.shape[1],
                              len(self.allLabels)]), self.allLabels)
                self.MLP.load(loadMLP)
            else:
                print "Warning: Testing is disabled"
                print "Could not find pre-trained MLP file ", loadMLP
                self.testing.Disable()
        else:
            print "Warning: Testing is disabled"
            print "Could not find preprocessed data file ", loadPreprocessedData
            self.testing.Disable()
Example #6
0
import socket
from socket import *
'''new=socket()
new.connect(('192.168.43.34',7000))'''
#new.listen(0)
#a,addr=new.accept()

load_preprocessed_data = 'datasets/faces_preprocessed.pkl'
load_mlp = 'params/mlp.xml'

light1 = 0
light2 = 0
if path.isfile(load_preprocessed_data):
    (_,
     y_train), (_,
                y_test), V, m = homebrew.load_from_file(load_preprocessed_data)
    pca_V = V
    pca_m = m
    all_labels = np.unique(np.hstack((y_train, y_test)))

    # load pre-trained multi-layer perceptron
    if path.isfile(load_mlp):
        layer_sizes = np.array([pca_V.shape[1], len(all_labels)])
        MLP = MultiLayerPerceptron(layer_sizes, all_labels)
        MLP.load(load_mlp)

#############################################################################
import cv2
import numpy as np
import copy
import math