示例#1
0
def run_rec():
    # This is where we write the images, if an output_dir is given
    # in command line:
    out_dir = None
    # Now read in the image data. This must be a valid path!
    [X, y] = read_images('images')
    # Then set up a handler for logging:
    handler = logging.StreamHandler(sys.stdout)
    formatter = logging.Formatter(
        '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    handler.setFormatter(formatter)
    # Add handler to facerec modules, so we see what's going on inside:
    logger = logging.getLogger("facerec")
    logger.addHandler(handler)
    logger.setLevel(logging.DEBUG)
    # Define the Fisherfaces as Feature Extraction method:
    feature = Fisherfaces()
    # Define a 1-NN classifier with Euclidean Distance:
    classifier = NearestNeighbor(dist_metric=EuclideanDistance(), k=1)
    # Define the model as the combination
    my_model = PredictableModel(feature=feature, classifier=classifier)
    # Compute the Fisherfaces on the given data (in X) and labels (in y):
    my_model.compute(X, y)
    # We then save the model, which uses Pythons pickle module:
    save_model('model.pkl', my_model)

    model = load_model('model.pkl')
    # Then turn the first (at most) 16 eigenvectors into grayscale
    # images (note: eigenvectors are stored by column!)
    #E = []
    #for i in xrange(min(model.feature.eigenvectors.shape[1], 16)):
    #    e = model.feature.eigenvectors[:,i].reshape(X[0].shape)
    #    E.append(minmax_normalize(e,0,255, dtype=np.uint8))
    # Plot them and store the plot to "python_fisherfaces_fisherfaces.pdf"
    #subplot(title="Fisherfaces", images=E, rows=4, cols=4, sptitle="Fisherface", colormap=cm.jet, filename="fisherfaces.png")
    # Perform a 10-fold cross validation
    cv = KFoldCrossValidation(model, k=10)
    cv.validate(X, y)
    # And print the result:
    cv.print_results()

    im = Image.open('search.png')
    im = im.convert("L")
    predicted_label = model.predict(im)[0]

    print(predicted_label)
    return predicted_label
示例#2
0
def run_rec():
    # This is where we write the images, if an output_dir is given
    # in command line:
    out_dir = None
    # Now read in the image data. This must be a valid path!
    [X,y] = read_images('images')
    # Then set up a handler for logging:
    handler = logging.StreamHandler(sys.stdout)
    formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    handler.setFormatter(formatter)
    # Add handler to facerec modules, so we see what's going on inside:
    logger = logging.getLogger("facerec")
    logger.addHandler(handler)
    logger.setLevel(logging.DEBUG)
    # Define the Fisherfaces as Feature Extraction method:
    feature = Fisherfaces()
    # Define a 1-NN classifier with Euclidean Distance:
    classifier = NearestNeighbor(dist_metric=EuclideanDistance(), k=1)
    # Define the model as the combination
    my_model = PredictableModel(feature=feature, classifier=classifier)
    # Compute the Fisherfaces on the given data (in X) and labels (in y):
    my_model.compute(X, y)
    # We then save the model, which uses Pythons pickle module:
    save_model('model.pkl', my_model)

    model = load_model('model.pkl')
    # Then turn the first (at most) 16 eigenvectors into grayscale
    # images (note: eigenvectors are stored by column!)
    #E = []
    #for i in xrange(min(model.feature.eigenvectors.shape[1], 16)):
    #    e = model.feature.eigenvectors[:,i].reshape(X[0].shape)
    #    E.append(minmax_normalize(e,0,255, dtype=np.uint8))
    # Plot them and store the plot to "python_fisherfaces_fisherfaces.pdf"
    #subplot(title="Fisherfaces", images=E, rows=4, cols=4, sptitle="Fisherface", colormap=cm.jet, filename="fisherfaces.png")
    # Perform a 10-fold cross validation
    cv = KFoldCrossValidation(model, k=10)
    cv.validate(X, y)
    # And print the result:
    cv.print_results()

    im = Image.open('search.png')
    im = im.convert("L")
    predicted_label = model.predict(im)[0]

    print(predicted_label)
    return predicted_label
def get_model(numeric_dataset, model_filename=None):
    feature = ChainOperator(Resize((128,128)), SpatialHistogram())	
    #feature = ChainOperator(Resize((128,128)), Fisherfaces())
    classifier = NearestNeighbor(dist_metric=NormalizedCorrelation(), k=1)
    print "kjasnanscal"
    #classifier = NearestNeighbor(dist_metric=EuclideanDistance(), k=1)
    inner_model = PredictableModel(feature=feature, classifier=classifier)
    model = PredictableModelWrapper(inner_model)
    model.set_data(numeric_dataset)
    model.compute()
    if not model_filename is None:
        save_model(model_filename, model)
    return model
示例#4
0
 # Then set up a handler for logging:
 handler = logging.StreamHandler(sys.stdout)
 formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
 handler.setFormatter(formatter)
 # Add handler to facerec modules, so we see what's going on inside:
 logger = logging.getLogger("facerec")
 logger.addHandler(handler)
 logger.setLevel(logging.DEBUG)
 # Define the Fisherfaces as Feature Extraction method:
 feature = SpatialHistogram()
 #feature = Fisherfaces()
 # Define a 1-NN classifier with Euclidean Distance:
 classifier = NearestNeighbor(dist_metric=NormalizedCorrelation(), k=1)
 #classifier = SVM()
 # Define the model as the combination
 my_model = PredictableModel(feature=feature, classifier=classifier)
 # Compute the Fisherfaces on the given data (in X) and labels (in y):
 my_model.compute(X, y)
 # We then save the model, which uses Pythons pickle module:
 save_model('modelTry.pkl', my_model)
 model = load_model('modelTry.pkl')
 # Then turn the first (at most) 16 eigenvectors into grayscale
 # images (note: eigenvectors are stored by column!)
 E = []
 #for i in range(min(model.feature.eigenvectors.shape[1], 16)):
 #    e = model.feature.eigenvectors[:,i].reshape(X[0].shape)
 #    E.append(minmax_normalize(e,0,255, dtype=np.uint8))
 # Plot them and store the plot to "python_fisherfaces_fisherfaces.pdf"
 subplot(title="Fisherfaces", images=E, rows=4, cols=4, sptitle="Fisherface", colormap=cm.jet, filename="fisherfaces.png")
 # Perform a 10-fold cross validation
 cv = KFoldCrossValidation(model, k=10)
示例#5
0
from PIL import Image
import scipy
from util import asRowMatrix
import numpy as np
import logging
import matplotlib.cm as cm
import pyttsx
engine = pyttsx.init()

engine.say('Hello SID,Welcome to the future,I am part of Romeos network')
engine.runAndWait()
engine.say(
    'use this code no issues,there are a few bugs in me hope You will correct me'
)
engine.runAndWait()
model = PredictableModel(Fisherfaces(), NearestNeighbor())
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_alt.xml')
recognizer = cv2.createLBPHFaceRecognizer()
video_capture = cv2.VideoCapture(0)


def read_images(path, sz=(256, 256)):

    X, y = [], []
    folder_names = []
    default = 'Unknown'
    for dirname, dirnames, filenames in os.walk(path):
        for subdirname in dirnames:
            default = 'Unknown'
            folder_names.append(subdirname)
            subject_path = os.path.join(dirname, subdirname)
    [X, y] = read_images(FACE_DETECT_FOLDER)

    # Then set up a handler for logging:
    handler = logging.StreamHandler(sys.stdout)
    formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
    handler.setFormatter(formatter)
    # Add handler to facerec modules, so we see what's going on inside:
    logger = logging.getLogger("facerec")
    logger.addHandler(handler)
    logger.setLevel(logging.DEBUG)
    # Define the Fisherfaces as Feature Extraction method:
    feature = Fisherfaces()
    # Define a 1-NN classifier with Euclidean Distance:
    classifier = NearestNeighbor(dist_metric=EuclideanDistance(), k=1)
    # Define the model as the combination
    my_model = PredictableModel(feature=feature, classifier=classifier)
    # Compute the Fisherfaces on the given data (in X) and labels (in y):
    my_model.compute(X, y)
    # We then save the model, which uses Pythons pickle module:
    save_model("model.pkl", my_model)
    model = load_model("model.pkl")
    # Then turn the first (at most) 16 eigenvectors into grayscale
    # images (note: eigenvectors are stored by column!)
    E = []
    for i in xrange(min(model.feature.eigenvectors.shape[1], 16)):
        e = model.feature.eigenvectors[:, i].reshape(X[0].shape)
        E.append(minmax_normalize(e, 0, 255, dtype=np.uint8))
    # Plot them and store the plot to "python_fisherfaces_fisherfaces.pdf"
    subplot(
        title="Fisherfaces", images=E, rows=4, cols=4, sptitle="Fisherface", colormap=cm.jet, filename="fisherfaces.png"
    )
示例#7
0
from feature import Fisherfaces
from classifier import NearestNeighbor
from model import PredictableModel
from fisc import *

model = PredictableModel(Fisherfaces(), NearestNeighbor())
[X, y] = read_images("./resources/att_faces/")
model.compute(X, y)
model.predict(X)