manansh
Posts: 9
Joined: Sun Feb 01, 2015 10:22 am

face detection

Sun Feb 08, 2015 5:10 pm

hey guys ,completely new to raspberry pi and python :?: i got the following open source code used for face recognition.

Code: Select all

from sklearn.decomposition import RandomizedPCA
import numpy as np
import glob
import cv2
import math
import os.path
import string

#function to get ID from filename
def ID_from_filename(filename):
    part = string.split(filename, '/')
    return part[1].replace("s", "")
 
#function to convert image to right format
def prepare_image(filename):
    img_color = cv2.imread(filename)
    img_gray = cv2.cvtColor(img_color, cv2.cv.CV_RGB2GRAY)
    img_gray = cv2.equalizeHist(img_gray)
    return img_gray.flat

IMG_RES = 92 * 112 # img resolution
NUM_EIGENFACES = 10 # images per train person
NUM_TRAINIMAGES = 110 # total images in training set

#loading training set from folder train_faces
folders = glob.glob('train_faces/*')
 
# Create an array with flattened images X
# and an array with ID of the people on each image y
X = np.zeros([NUM_TRAINIMAGES, IMG_RES], dtype='int8')
y = []

# Populate training array with flattened imags from subfolders of train_faces and names
c = 0
for x, folder in enumerate(folders):
    train_faces = glob.glob(folder + '/*')
    for i, face in enumerate(train_faces):
        X[c,:] = prepare_image(face)
        y.append(ID_from_filename(face))
        c = c + 1

# perform principal component analysis on the images
pca = RandomizedPCA(n_components=NUM_EIGENFACES, whiten=True).fit(X)
X_pca = pca.transform(X)
once the code recognizes the image i want it to send the signal to an arduino due board and i also need to flash an led connected to a gpio pin.what changes should i make :?: thanks in advance :D

-rst-
Posts: 1316
Joined: Thu Nov 01, 2012 12:12 pm
Location: Dublin, Ireland

Re: face detection

Fri Feb 13, 2015 4:52 pm

Change of strategy maybe? ;)

Learn some Python (for example http://learnpythonthehardway.org/book/).

Learn about RPi GPIO (for example http://www.themagpi.com/)

Revisit the site you got that face recognition code from and try to find out how to use the library.

When all parts work on their own, start combining them.

Best of luck - is should be fun.
http://raspberrycompote.blogspot.com/ - Low-level graphics and 'Coding Gold Dust'

Return to “Python”