This is a face recognition illustration using PCA via python.
This program is mainly used for face recognition. Face recognition can be broadly divided into two parts: data processing and recognition.
We choose The ORL Database of Faces as database. After a series of basic image preprocessing, we map each image column quantitatively. After that, we piled the vectors horizontally into a matrix, and use Principal Components Analysis to reduce the dimension of matrix. Finally, the column vector of each image is projected in a point in the high dimensional space.
We use Euclidean Distance to measure the distance between two coordinate points in high dimensional space (each coordinate point represents a face image). The smaller the metric, the closer the two coordinate points are in the high-dimensional space (not near the strict sense, but near the Euclidean space), the more the face image represented by the two coordinate points similar. Here you can set the distance threshold to determine the distance at which the two coordinate points represented the same face.
The program uses Mac OS 10.10 as a test platform, Ubuntu 16.04 can work as well. Other operating systems have yet to be tested. Program uses Python3 as the programming language, so you also need to install Python3 environment, and will also need to use pip3
to install some necessary packages.
Operating Systems: Mac OS 10.10
IDE: PyCharm CE
I only list the steps for installing Python3 on Mac, and the installation steps for the rest of the operating systems are available for download and documentation from Python3.
First we need to install Xcode command line tool. It is kind of necessary environment we need to install python. So open a terminal, and run the command as below.
xcode-select--install
It is easy install python through Homebrew. The function of Homebrew is much liable to that of command apt
under Ubuntu. The means you install packages are also similar. For instance, we use brew install <packages>
to install new packages.
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Now, well preparing, we can install Python via HomeBrew:
brew install python3
It won't take a long time. If don't success, try Proxy Note. After installing python, you shall use python3
to check whether Python3 is installed. Besides, you can use python3 -V
to check your python version.
In addition, it is worth noting that the network maybe slow due to the GFW while using HomeBrew. You can, therefore, use shadowsocks in terminal to proxy your network.
export ALL_PROXY=socks5://127.0.0.1:1080
The necessary packages are already in the file requirements.txt
. So you can use pip3
to install them all in an easy way.
cd PCA_ORL_Python
pip3 install -r requirements.txt
Proxy can also be used to speed up the process of pip3 install
. Be aware, pip doesn't support socks5
, so you can only use http proxy.
export ALL_PROXY=http://server:port
To run this code, you can run both in a IDE or terminal.
python3 PCA.py --image-scale 0.4 --train-per-person 3 --print-feature-face True --principal-rate 0.3
- Offer mathematical formula documents