Face Detection and Face Recognition in P
Face Detection and Face Recognition in P
uses Python in its production of special effects Its a library intended (as the name sug-
for large-budget feature films, Yahoo! uses gests) to be a simplified version of
it (among other things) to manage its discus- OpenCV. It doesnt offer all the possibil-
sion groups and Google has used it to imple- ities of OpenCV, but it is easier to learn
ment many components of its web crawler and and use.
search engine [3]. As Python is also a language
that is easy to learn and both powerful and con- • OpenCV
venient from the start [2], we might soon be It is by far the most capable and most
asking, who is not using it. As already men- commonly used computer vision library.
tioned Python has an extensive set of libraries It is written in C/C++, but Python bind-
which can be imported into a project in order ings are added during the installation. It
to perform specific tasks. The ones that re- also gives emphasis on real time image
ally should be mentioned in any scientific pa- processing. Among the ones, which will
per dealing with mathematics are NumPy and not be presented it might be worth men-
SciPy. NumPy is a library which provides sup- tioning Ilastik. It is a simple, user-friendly
port for large, multi-dimensional arrays. As tool for interactive image classification,
images are in fact large two (greyscale) or three segmentation and analysis.
(color) dimensional matrices, this library is es-
2.1 Python Imaging Library (PIL)
sential in all image processing tasks. It should
also be emphasized that many other libraries Python Imaging Library (PIL) is a library orig-
(not limited to image processing) use NumPy inally written by Fredrik Lundh. As PIL’s last
release dates back to 2009 it is a little outdated
array representation. SciPy is a library built on [5]. It’s successor that also supports Python
the NumPy array object and contains modules 3 is called Pillow [6]. Consequently not both
for signal and image processing, linear alge- of them can be installed at the same time. At
bra, fast Fourier transform, etc. The last library the time of writing the paper, the last version
mentioned in this introductory section is Mat- of Pillow is 5.1.0. The most trivial program
(showing an image) can be written as follows:
plotlib. As the name suggests this library is a
plotting library. Although it is used a lot in all from PIL import Image
im=Image.open(’/path/to/the/image/’)
areas of science, Image processing relies heav-
im.show()
ily on it. In this paper the libraries and their ca-
pabilities in the area of image processing, im- Pillow is able to extract a lot of information
age analysis and computer vision in general are from an image and makes it possible to execute
discussed. The execution of some of the most several standard procedures for image manipu-
common algorithms in the field is also demon- lation, including:
strated together with the resulting images.
• per-pixel manipulations,
2 PYTHON’S IMAGE PROCESSING LI- • masking and transparency handling,
BRARIES
• image filtering, such as blurring, contour-
There are several Python libraries related to
ing, smoothing, or edge finding,
Image processing and Computer vision. The
ones that will be presented in this paper are: • image enhancing, such as sharpening, ad-
justing brightness, contrast or color
• PIL/Pillow
This library is mainly appropriate for sim- Some of them will be demonstrated. Image can
ple image manipulations (rotation, resiz- for example be easily rotated for specific angle
ing, etc.) and very basic image analysis (in our case 45◦ ) and then saved by the follow-
ing code:
(histogram for example)
rotated_image=im.rotate(45)
• SimpleCV rotated_image.save(’rotated.jpg’)
Figure 2. An example of face detection Figure 3. Sample images of Bob Kelso and John Dorian
feature could for example be based upon the face recognition is based on ResNet-34 neural
fact that the eyes are usually darker than the network [10]. The Python’s face recognition li-
bridge of the nose. With the increasing num- brary however has fewer layers and the number
ber of such features, we can increase the reli- of filters is reduced by half. The network was
ability of the algorithm. Misclassifications are trained on a dataset of approximately 3 million
of course always a possibility. It should also images (mainly the VGG dataset [11] and the
be noted, that the reliability decreases with the scrubs dataset [12]).
decreasing amount of pixels in the face area. The algorithm is composed of four steps:
3. Encoding Faces
The Deep Convolutional Neural Network
is trained to generate 128 measurements
for each face. The training process uses
three images at a time (the image of a
known person, another image of the same
person and an image of some other per-
son) [15]. This step requires a large
dataset and a lot of computer power. But
it has to be executed only once. Some pre-
Figure 4. A sample of an original image and its his- trained neural networks are also available
togram of gradients on internet.
4. Finding the persons name from the encod-
of 16x16 size are formed. Then the pre- ing
dominant direction for each submatrix is The last step is actually a very basic one.
found. The face being analyzed is compared to
the faces that we have in our database.
2. Posing and Projecting Faces Python’s library uses Support vector ma-
This step deals with the problem that faces chine (SVM) to do that. In principle
in an image might be looking to some any other classification algorithm could
other direction and not straight into the be used.
camera. There are several solutions to this
problem. Python’s library uses the ap- The performance of the algorithm is presented
proach with 68 landmarks that are present on the image shown in Fig. 6. It can be seen
on any face [14]. An example of such an
image is shown in Fig. 5. Then a ma-
REFERENCES
[1] C. Fuhrer, J. E. Solem, and O. Verdier, Scientific
Computing with Python 3, Packt Publishing Ltd,
2016. (references)
The paper is divided into two parts. In the [7] https://en.wikipedia.org/wiki/Python Imaging Library
first one a short overview of the most common
Python’s libraries related to image processing [8] A. Kaehler, and G. Bradski, Learning OpenCV:
and computer vision is given. The second part computer vision in C++ with the OpenCV library,
uses the OpenCV library. In this part the li- 2nd Ed.,” O’Reilly, 2016.
braries for face detection and face recognition
[9] P. Viola, and M. Jones, “Rapid object detection us-
are described and analyzed. Face detection and
ing a boosted cascade of simple features,” Proceed-
face recognition are namely two areas of inten- ings of the 2001 IEEE Computer Society Confer-
sive research, because they enable a better in- ence on Computer Vision and Pattern Recognition,
teraction between computer system or robots vol. 1, pp. I-511-I-518, 2001.
on one side and humans on the other.
[10] K. He, X. Zhang, S. Ren, and J. Sun, Deep residual
Python’s face recognition library turns out to
learning for image recognition,” In Proceedings of
be fast and very reliable tool for face detec- the IEEE conference on computer vision and pattern
tion and face recognition. As Python is a recognition, pp. 770-778, 2016.
high level programming language the library
is well suited to be used just as a face detec- [11] O. M. Parkhi, A. Vedaldi, and A. Zisserman,
tion(recognition) procedure in a wider project “Deep face recognition,” In British Machine Vision
Conference, vol. 1, no. 3, p. 6, September, 2015.
without the need for a detailed knowledge of
the theoretical background of the employed al- [12] H. W. Ng, and S. Winkler, “A data-driven approach
gorithms. So, in our opinion it has a bright fu- to cleaning large face datasets,” IEEE International
ture. Conference on Image Processing (ICIP), pp. 343-
In future it would be very interesting to investi- 347, 2014.
gate the possibilities of Python and its libraries
[13] N. Dalal, and B. Trigs, “Histograms of oriented
for emotion detection. This field is a very hot gradients for human detection,” IEEE Computer So-
topic in human machine interface research. Us- ciety Conference on Computer Vision and Pattern
ing the results of this research it is possible to Recognition (CVPR), vol. 1, pp. 886-893, 2005.