def reconstruct (W , Y , mu = None ) :
if mu is None :
return np . dot (Y ,W.T)
return np . dot (Y , W .T) + mu



# read images
[X , y] = read_images ('D:\homework and assignments\computer vision\face and gender recognition\images')
# perform a full pca
[D , W , mu ] = pca ( asRowMatrix (X ) , y)
import sys
# append tinyfacerec to module search path
sys.path.append("..")
# import numpy and matplotlib colormaps
import numpy as np
# import tinyfacerec modules
from tinyfacerec.util import read_images
from tinyfacerec.model import FisherfacesModel

if __name__ == '__main__':

    if len(sys.argv) != 2:
        print "USAGE: example_model_fisherfaces.py </path/to/images>"
        sys.exit()
    
    # read images
    [X,y] = read_images(sys.argv[1], sz=[92, 112])
    # compute the eigenfaces model
    model = FisherfacesModel(X[1:], y[1:])
    # get a prediction for the first observation
    print "expected =", y[0], "/", "predicted =", model.predict(X[0])
sys.path.append("..")
# import numpy and matplotlib colormaps
import numpy as np
# import tinyfacerec modules
from tinyfacerec.subspace import pca
from tinyfacerec.util import normalize, asRowMatrix, read_images
from tinyfacerec.visual import subplot

if __name__ == '__main__':

    if len(sys.argv) != 2:
        print "USAGE: example_eigenfaces.py </path/to/images>"
        sys.exit()

    # read images
    [X, y] = read_images(sys.argv[1])

    # perform a full pca
    [D, W, mu] = pca(asRowMatrix(X), y)

    import matplotlib.cm as cm

    # turn the first (at most) 16 eigenvectors into grayscale
    # images (note: eigenvectors are stored by column!)
    E = []
    for i in xrange(min(len(X), 16)):
        e = W[:, i].reshape(X[0].shape)
        E.append(normalize(e, 0, 255))
    # plot them and store the plot to "python_eigenfaces.pdf"
    subplot(title="Eigenfaces AT&T Facedatabase",
            images=E,
import sys
# append tinyfacerec to module search path
sys.path.append("..")
# import numpy and matplotlib colormaps
import numpy as np
# import tinyfacerec modules
from tinyfacerec.util import read_images
from tinyfacerec.model import EigenfacesModel
# read images
[X,y] = read_images("/home/philipp/facerec/data/yalefaces_recognition")
# compute the eigenfaces model
model = EigenfacesModel(X[1:], y[1:])
# get a prediction for the first observation
print "expected =", y[0], "/", "predicted =", model.predict(X[0])
示例#5
0
			s, img = cam.read()
			if s:    # frame captured without any errors
				print "capture done!!"
				#cam.release()
			else:
				print "Not successful!!"
				

			
			#Convert to gray scale
			gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
			
		#--------------------------------------------------------

			# read images
			[X,y] = read_images(imagePath)

			# Create the haar cascade
			faceCascade = cv2.CascadeClassifier(cascPath)

		 #--------------------------------------------------------
		  
			# compute the eigenfaces model
			#model = EigenfacesModel(X, y) #makes an instance of EigenfacesModel class
			
		#--------------------------------------------------------

			# For face recognition we will the the LBPH Face Recognizer 
			recognizer = cv2.createLBPHFaceRecognizer() #Better results in different lighting conditions
			
			#recognizer = cv2.createEigenFaceRecognizer()
示例#6
0
import sys
# append tinyfacerec to module search path
sys.path.append("..")
# import numpy and matplotlib colormaps
import numpy as np
# import tinyfacerec modules
from tinyfacerec.subspace import pca
from tinyfacerec.util import normalize, asRowMatrix, read_images
from tinyfacerec.visual import subplot

# read images
[X,y] = read_images('att_faces')
# perform a full pca
[D, W, mu] = pca(asRowMatrix(X[1:]), y)

import matplotlib.cm as cm

# turn the first (at most) 16 eigenvectors into grayscale
# images (note: eigenvectors are stored by column!)
E = []
for i in range(min(len(X), 16)):
	e = W[:,i].reshape(X[0].shape)
	E.append(normalize(e,0,255))
# plot them and store the plot to "python_eigenfaces.pdf"
subplot(title="Eigenfaces AT&T Facedatabase", images=E, rows=4, cols=4, sptitle="Eigenface", colormap=cm.gray, filename="python_pca_eigenfaces.pdf")

from tinyfacerec.subspace import project, reconstruct

# reconstruction steps
steps=[i for i in range(10, min(len(X), 400), 20)]
E = []
示例#7
0
import sys

# import numpy and matplotlib colormaps
import numpy as np
# import tinyfacerec modules
from tinyfacerec.subspace import pca
from tinyfacerec.util import normalize, asRowMatrix, read_images
from tinyfacerec.visual import subplot

# set numpy array print option
np.set_printoptions(threshold=1000000)

# read images
[X, y] = read_images('../att_faces')

# perform a full pca
[D, W, mu] = pca(asRowMatrix(X), y)

print()
print(D)
print()
print(len(W))

import matplotlib.cm as cm

# turn the first (at most) 16 eigenvectors into grayscale
# images (note: eigenvectors are stored by column!)
E = []
for i in range(min(len(X), 10)):
    e = W[:, i].reshape(X[0].shape)
    E.append(normalize(e, 0, 255))
示例#8
0
sys.path.append("..")
# import numpy and matplotlib colormaps
import numpy as np
# import tinyfacerec modules
from tinyfacerec.subspace import pca
from tinyfacerec.util import normalize, asRowMatrix, read_images
from tinyfacerec.visual import subplot

if __name__ == '__main__':

    if len(sys.argv) != 2:
        print "USAGE: example_eigenfaces.py </path/to/images>"
        sys.exit()
    
    # read images
    [X,y] = read_images(sys.argv[1])

    # perform a full pca
    [D, W, mu] = pca(asRowMatrix(X), y)

    import matplotlib.cm as cm

    # turn the first (at most) 16 eigenvectors into grayscale
    # images (note: eigenvectors are stored by column!)
    E = []
    for i in xrange(min(len(X), 16)):
	    e = W[:,i].reshape(X[0].shape)
	    E.append(normalize(e,0,255))
    # plot them and store the plot to "python_eigenfaces.pdf"
    subplot(title="Eigenfaces AT&T Facedatabase", images=E, rows=4, cols=4, sptitle="Eigenface", colormap=cm.jet, filename="python_pca_eigenfaces.png")
sys.path.append("..")
# import numpy and matplotlib colormaps
import numpy as np
# import tinyfacerec modules
from tinyfacerec.subspace import fisherfaces
from tinyfacerec.util import normalize, asRowMatrix, read_images
from tinyfacerec.visual import subplot

if __name__ == '__main__':

    if len(sys.argv) != 2:
        print "USAGE: example_fisherfaces.py </path/to/images>"
        sys.exit()

    # read images
    [X,y] = read_images(sys.argv[1])
    # perform a full pca
    [D, W, mu] = fisherfaces(asRowMatrix(X), y)
    #import colormaps
    import matplotlib.cm as cm
    # turn the first (at most) 16 eigenvectors into grayscale
    # images (note: eigenvectors are stored by column!)
    E = []
    for i in xrange(min(W.shape[1], 16)):
	    e = W[:,i].reshape(X[0].shape)
	    E.append(normalize(e,0,255))
    # plot them and store the plot to "python_fisherfaces_fisherfaces.pdf"
    subplot(title="Fisherfaces AT&T Facedatabase", images=E, rows=4, cols=4, sptitle="Fisherface", colormap=cm.jet, filename="python_fisherfaces_fisherfaces.png")

    from tinyfacerec.subspace import project, reconstruct
示例#10
0
import sys
import os
import numpy as np
# append tinyfacerec to module search path
sys.path.append("..")

from tinyfacerec.subspace import pca
from tinyfacerec.util import normalize, asRowMatrix, read_images
from tinyfacerec.visual import subplot

[X,y] = read_images("/home/priyanka/Desktop/CV/scripts/att_faces")


[D, W, mu] = pca(asRowMatrix(X), y)

import matplotlib.cm as cm

# turn the first (at most) 16 eigenvectors into grayscale
# images (note: eigenvectors are stored by column!)
E = []
for i in range(min(len(X), 16)):
	e = W[:,i].reshape(X[0].shape)
	E.append(normalize(e,0,255))
# plot them and store the plot to "python_eigenfaces.pdf"
subplot(title="Eigenfaces AT&T Facedatabase", images=E, rows=4, cols=4, sptitle="Eigenface", colormap=cm.jet, filename="python_pca_eigenfaces.pdf")

from tinyfacerec.subspace import project, reconstruct

# reconstruction steps
steps=[i for i in range(10, min(len(X), 320), 20)]
E = []
示例#11
0
import sys
# append tinyfacerec to module search path
sys.path.append("..")
# import numpy and matplotlib colormaps
import numpy as np
# import tinyfacerec modules
from tinyfacerec.subspace import pca
from tinyfacerec.util import normalize, asRowMatrix, read_images
from tinyfacerec.visual import subplot

# read images
[X,y] = read_images("/home/philipp/facerec/data/at")
# perform a full pca
[D, W, mu] = pca(asRowMatrix(X), y)

import matplotlib.cm as cm

# turn the first (at most) 16 eigenvectors into grayscale
# images (note: eigenvectors are stored by column!)
E = []
for i in xrange(min(len(X), 16)):
	e = W[:,i].reshape(X[0].shape)
	E.append(normalize(e,0,255))
# plot them and store the plot to "python_eigenfaces.pdf"
subplot(title="Eigenfaces AT&T Facedatabase", images=E, rows=4, cols=4, sptitle="Eigenface", colormap=cm.jet, filename="python_pca_eigenfaces.pdf")

from tinyfacerec.subspace import project, reconstruct

# reconstruction steps
steps=[i for i in xrange(10, min(len(X), 320), 20)]
E = []
from pylab import *
from PIL import Image
from io import StringIO
# append tinyfacerec to module search path
sys . path . append ("..")


# import tinyfacerec modules
from tinyfacerec . util import read_images

from tinyfacerec . model import EigenfacesModel
from scripts . data_spilt import data_spilts
# read images

data_spilts(train=5)
[X,y] = read_images ("/home/priyanka/Desktop/scripts/Test")

[A,a] = read_images ("/home/priyanka/Desktop/scripts/Train")

model = EigenfacesModel (X[0:] , y [0:])

correct=0
incorrect=0
for i in range(size(a)):
	if a[i] ==model . predict (A[i]):
		correct+=1
	else:
		incorrect+=1
print("Correct = ",correct)
print("Incorrect = ",incorrect)
Accuracy=(size(a)-incorrect)*100/size(a)
示例#13
0
import sys
# append tinyfacerec to module search path
sys.path.append("..")
# import numpy and matplotlib colormaps
import numpy as np
# import tinyfacerec modules
from tinyfacerec.util import read_images
from tinyfacerec.model import EigenfacesModel

# read images
[X,y] = read_images('training')
[A,b] = read_images('test')

# compute the eigenfaces model
model = EigenfacesModel(X[:], y[:])
# get a prediction for the first observation
c=[]
num_correct=0
for i in range(120):
    if i%3==0:
        a=int(i/3)
        print ("expected =", y[(a)*7])
    print("/", "predicted =", model.predict(A[i]))
    c.append(model.predict(A[i]))
    
    if c[i]==b[i]:
        num_correct+=1


num_test = float(len(b[:]))
accuracy = float(num_correct)/ num_test
示例#14
0
sys.path.append("..")
# import numpy and matplotlib colormaps
import numpy as np
# import tinyfacerec modules
from tinyfacerec.subspace import pca
from tinyfacerec.util import normalize, asRowMatrix, read_images
from tinyfacerec.visual import subplot

if __name__ == '__main__':

    if len(sys.argv) != 2:
        print "USAGE: example_eigenfaces.py </path/to/images>"
        sys.exit()

    # read images
    [X, y] = read_images(sys.argv[1])

    # perform a full pca
    [D, W, mu] = pca(asRowMatrix(X), y)

    import matplotlib.cm as cm

    # turn the first (at most) 16 eigenvectors into grayscale
    # images (note: eigenvectors are stored by column!)
    E = []
    for i in xrange(min(len(X), 16)):
        e = W[:, i].reshape(X[0].shape)
        E.append(normalize(e, 0, 255))
    # plot them and store the plot to "python_eigenfaces.pdf"
    subplot(title="Eigenfaces AT&T Facedatabase",
            images=E,
示例#15
0
			
			#Cgray = CropFace(img, eye_left=(252,364), eye_right=(420,366), offset_pct=(0.3,0.3), dest_sz=(200,200))
			#gray = cv2.normalize(gray,gray,0,255)
		  
			#gray = Image.fromarray(gray)
		#--------------------------------------------------------

			# Create the haar cascade
			faceCascade = cv2.CascadeClassifier(cascPath)

			#if len(sys.argv) != 3:
			   # print "USAGE: example_model_eigenfaces.py </path/to/images>"
			   # sys.exit()
			
			# read images
			[X,y] = read_images(imagePath) #argv[1]:path to the images
		  
		 #--------------------------------------------------------
		  
			# compute the eigenfaces model
			#model = EigenfacesModel(X, y) #makes an instance of EigenfacesModel class
			
		#--------------------------------------------------------

			# For face recognition we will the the LBPH Face Recognizer 
			recognizer = cv2.createLBPHFaceRecognizer() #Better results in different lighting conditions
			
			#recognizer = cv2.createEigenFaceRecognizer()
			
			# Perform the tranining
			recognizer.train(X, np.array(y))