Facial Recognition Algorithm Explained for Makers

OpenCV YXZhu ⋅ 于 2016-12-06 14:57:53 ⋅ 1735 阅读

​Machine Learning is a buzz word these days, it involves heavy math, and tons of computer programming skills. It is so difficult that only graduate school teaches these topics. But please don't be panic. Today we will show you makers how to make a working Machine Learning system within just half an hour. We will make a facial recognition system from scratch. It runs on Raspberry Pi, so it is portable, can be set up anywhere for monitoring, examining your room, garage, sidewalk etc.
We will take three or four audiences, record their facial data, and train the data with the code we wrote on side, the system we built will recognize each one of them and show everyone how accurate the recognition system could be. Also we will show you how to tune the system to make it more accurate as we do more training. In term of the background of Facial Recognition with PCA(Principle Component Analysis), it can be traced back long way to early 90s that MIT students published one ground breaking paper, it purposed the PCA approach in facial recognition.
Programming Language and Package for fast Facial Recognition Application
The tool we are using is Python, and it's packages. Thanks to language like python, package such as scikit-learn, the abstraction is high, programmers have greater power to move around huge building blocks of module , to accelerate the developing speed. Facial recognition could be easy if you armed with the right tool, scikit-learn based on python is great for manipulating matrices and vectors. Facial recognition in a nutshell is translating facial images to vectors, and then try to find out the part which can be used for most significantly differentiating these faces.

file

The Machine Learning Algorithm - Principle Component Analysis (PCA)

The most significant parts for recognizing face are eyes, nose, and mouth,yet machine has no idea what so ever to find the part of eyes, nose and mouth, hence we should teach machine to find the right part to compare with each other. This is the PCA 's job. Facial images can be translated to bunch of vectors. Now, the PCA kicks in. Finding the most import vectors that contain most information is boiled down to finding the eigenvalue and eigenvector of the covariance matrix of AA'(A is made up of all the face vectors).The problem here is that compute the eigenvalue and eigenvector for such huge matrix is time consuming. Now here is the kicker, MIT folks purposed a great approach to do computing which can reduce the computation complexity, read the paper if you are interested. PCA has another important goal of simplifying the calculation of huge number of vectors. PCA can reduce the dimension of matrix, i.e. reducing the pool of vectors to certain number of projected vectors, which can represent face images, this can make the calculation possible in term of speed .

file

file

Machine Learning Algorithm – K-Nearest Neighbors(KNN)

KNN(K-Nearest Neighbors) is another machine learning algorithm that can make the classification more accurate. After PCA, KNN is just like there are multiple persons execute the recognition multiple times, if one person can make mistakes, now there are multiple persons examining one case at the same time, and the result is based on the collective voting from these persons, the result could be more accurate , i.e. each person will return a result.,KNN will ask those persons to vote for the best candidate. We accept the answer with the most votes. This process will reduce the error of recognition. Simple philosophy, easy implementation, boost the accuracy tremendously.

Implement PCA and KNN with Python package scikit-learn

Now it is the fun part, let's do the coding. Scikit-learn offers PCA module, first you need to translate the face images to vectors. Pixel in image could be perceived as number, colored pixel is constructed with three channels, which could be difficult to compare and compute, for the sake of simplicity, we convert the three channels colored pixel to grays scale pixel which has only one channel.

  • PCA Snippets with scikit-learn, train and predict:
    pca = PCA(n_components=k)
    newfacedataset=pca.fit_transform(faceData)
    projectedface=pca.transform(resized_image.flatten("C").copy())
  • KNN Snippets with scikit-learn , train and predict:
    knn=KNeighborsClassifier(n_neighbors=3)
    knn.fit(newfacedataset, y)
    y_pred=knnpresistencemodle.predict(projectedface)

file

Finally, we need to load the training facial data to system,just few seconds, the system is good to go.
It will name the students out load when students show up in front of the camera, enjoy it!

Reference:
https://en.wikipedia.org/wiki/Eigenface
http://www.face-rec.org/algorithms/PCA/jcn.pdf
http://www.vision.jhu.edu/teaching/vision08/Handouts/case_study_pca1.pdf

-EOF-

本帖已被设为精华帖!
本帖由 YXZhu 于 3年前 加精
回复数量: 0
    暂无评论~~
    • 请注意单词拼写,以及中英文排版,参考此页
    • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`, 更多语法请见这里 Markdown 语法
    • 支持表情,使用方法请见 Emoji 自动补全来咯,可用的 Emoji 请见 :metal: :point_right: Emoji 列表 :star: :sparkles:
    • 上传图片, 支持拖拽和剪切板黏贴上传, 格式限制 - jpg, png, gif
    • 发布框支持本地存储功能,会在内容变更时保存,「提交」按钮点击时清空
    Ctrl+Enter