1
1
Face Recognition
2
2
================
3
3
4
- The world’s simplest face recognition and face manipulation library.
4
+ Recognize and manipulate faces from Python or from the command line with
5
+ the world's simplest face recognition library.
5
6
6
- Built using `dlib `_\ ’s state-of-the-art deep learning face recognition.
7
+ Built using `dlib <http://dlib.net/ >`__'s state-of-the-art face
8
+ recognition built with deep learning. The model has an accuracy of
9
+ 99.38% on the `Labeled Faces in the
10
+ Wild <http://vis-www.cs.umass.edu/lfw/> `__ benchmark.
7
11
8
- | |image0|
9
- | |image1|
12
+ This also provides a simple ``face_recognition `` command line tool that
13
+ lets you do face recognition on a folder of images from the command
14
+ line!
10
15
11
- Recognize and manipulate faces from Python or from the command line
12
-
13
- Free software, MIT license.
16
+ |image0 | |image1 |
14
17
15
18
Features
16
19
--------
17
20
18
21
Find faces in pictures
19
22
^^^^^^^^^^^^^^^^^^^^^^
20
23
21
- Find all the faces that appear in a picture.
24
+ Find all the faces that appear in a picture:
25
+
26
+ .. figure :: https://cloud.githubusercontent.com/assets/896692/23625227/42c65360-025d-11e7-94ea-b12f28cb34b4.png
27
+ :alt:
22
28
23
- |image2 |
29
+ .. code :: python
30
+
31
+ import face_recognition
32
+ image = face_recognition.load_image_file(" your_file.jpg" )
33
+ face_locations = face_recognition.face_locations(image)
24
34
25
35
Find and manipulate facial features in pictures
26
36
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
27
37
28
- Get the locations and outlines of each person’ s eyes, nose, mouth and
38
+ Get the locations and outlines of each person' s eyes, nose, mouth and
29
39
chin.
30
40
31
- |image3 |
41
+ .. figure :: https://cloud.githubusercontent.com/assets/896692/23625282/7f2d79dc-025d-11e7-8728-d8924596f8fa.png
42
+ :alt:
43
+
44
+ .. code :: python
32
45
33
- | Finding facial features is super useful for lots of important stuff.
34
- But you can also use for really stupid stuff
35
- | like applying `digital make-up`_ (think ‘Meitu’):
46
+ import face_recognition
47
+ image = face_recognition.load_image_file( " your_file.jpg " )
48
+ face_landmarks_list = face_recognition.face_landmarks(image)
36
49
37
- |f3 |
50
+ Finding facial features is super useful for lots of important stuff. But
51
+ you can also use for really stupid stuff like applying `digital
52
+ make-up <https://github.com/ageitgey/face_recognition/blob/master/examples/digital_makeup.py> `__
53
+ (think 'Meitu'):
54
+
55
+ .. figure :: https://cloud.githubusercontent.com/assets/896692/23625283/80638760-025d-11e7-80a2-1d2779f7ccab.png
56
+ :alt:
38
57
39
58
Identify faces in pictures
40
59
^^^^^^^^^^^^^^^^^^^^^^^^^^
41
60
42
61
Recognize who appears in each photo.
43
62
44
- |f4 |
63
+ .. figure :: https://cloud.githubusercontent.com/assets/896692/23625229/45e049b6-025d-11e7-89cc-8a71cf89e713.png
64
+ :alt:
65
+
66
+ .. code :: python
67
+
68
+ import face_recognition
69
+ known_image = face_recognition.load_image_file(" biden.jpg" )
70
+ unknown_image = face_recognition.load_image_file(" unknown.jpg" )
71
+
72
+ biden_encoding = face_recognition.face_encodings(known_image)[0 ]
73
+ unknown_encoding = face_recognition.face_encodings(unknown_image)
74
+
75
+ results = face_recognition.compare_faces([biden_encoding], unknown_encoding)
76
+
77
+ Installation
78
+ ------------
79
+
80
+ Python 3 is fully supported. Python 2 should also work. Only macOS and
81
+ Linux are tested. I have no idea if this will work on Windows.
82
+
83
+ You can install this module from pypi using ``pip3 `` (or ``pip2 `` for
84
+ Python 2):
85
+
86
+ .. code :: bash
87
+
88
+ $ pip3 install face_recognition
89
+
90
+ It's very likely that you will run into problems when pip tries to
91
+ compile the ``dlib `` dependency. If that happens, check out this guide
92
+ to installing dlib from source instead to fix the error:
93
+
94
+ `How to install dlib from
95
+ source <https://gist.github.com/ageitgey/629d75c1baac34dfa5ca2a1928a7aeaf> `__
96
+
97
+ After manually installing ``dlib ``, try running
98
+ ``pip3 install face_recognition `` again.
45
99
46
100
Usage
47
101
-----
48
102
49
103
Command-Line Interface
50
104
^^^^^^^^^^^^^^^^^^^^^^
51
105
52
- | When you install ``face_recognition``, you get a simple command-line
53
- program
54
- | called ``face_recognition`` that you can use to recognize faces in a
55
- | photograph or folder full for photographs.
106
+ When you install ``face_recognition ``, you get a simple command-line
107
+ program called ``face_recognition `` that you can use to recognize faces
108
+ in a photograph or folder full for photographs.
109
+
110
+ First, you need to provide a folder with one picture of each person you
111
+ already know. There should be one image file for each person with the
112
+ files named according to who is in the picture:
56
113
57
- | First, you need to provide a folder with one picture of each person
58
- you
59
- | already know. There should be one image file for each person with the
60
- | files named according to who is in the picture:
114
+ .. figure :: https://cloud.githubusercontent.com/assets/896692/23582466/8324810e-00df-11e7-82cf-41515eba704d.png
115
+ :alt: known
61
116
62
- | known |
117
+ known
63
118
64
119
Next, you need a second folder with the files you want to identify:
65
120
66
- |unknown |
121
+ .. figure :: https://cloud.githubusercontent.com/assets/896692/23582465/81f422f8-00df-11e7-8b0d-75364f641f58.png
122
+ :alt: unknown
67
123
68
- | Then in you simply run the commnad ``face_recognition``, passing in
69
- | the folder of known people and the folder (or single image) with
70
- unknown
71
- | people and it tells you who is in each image:
124
+ unknown
125
+
126
+ Then in you simply run the commnad ``face_recognition ``, passing in the
127
+ folder of known people and the folder (or single image) with unknown
128
+ people and it tells you who is in each image:
72
129
73
130
.. code :: bash
74
131
@@ -77,17 +134,14 @@ Next, you need a second folder with the files you want to identify:
77
134
/unknown_pictures/unknown.jpg,Barack Obama
78
135
/face_recognition_test/unknown_pictures/unknown.jpg,unknown_person
79
136
80
- | There’s one line in the output for each face. The data is
81
- comma-separated
82
- | with the filename and the name of the person found.
137
+ There's one line in the output for each face. The data is
138
+ comma-separated with the filename and the name of the person found.
83
139
84
- | An ``unknown_person`` is a face in the image that didn’t match anyone
85
- in
86
- | your folder of known people.
140
+ An ``unknown_person `` is a face in the image that didn't match anyone in
141
+ your folder of known people.
87
142
88
- | If you simply want to know the names of the people in each photograph
89
- but don’t
90
- | care about file names, you could do this:
143
+ If you simply want to know the names of the people in each photograph
144
+ but don't care about file names, you could do this:
91
145
92
146
.. code :: bash
93
147
@@ -96,19 +150,115 @@ Next, you need a second folder with the files you want to identify:
96
150
Barack Obama
97
151
unknown_person
98
152
99
- Python API
100
- ^^^^^^^^^^
153
+ Python Module
154
+ ^^^^^^^^^^^^^
155
+
156
+ You can import the ``face_recognition `` module and then easily
157
+ manipulate faces with just a couple of lines of code. It's super easy!
158
+
159
+ API Docs: https://face-recognition.readthedocs.io.
160
+
161
+ Automatically find all the faces in an image
162
+ ''''''''''''''''''''''''''''''''''''''''''''
163
+
164
+ .. code :: python
165
+
166
+ import face_recognition
101
167
102
- API Docs: [https://face-recognition.readthedocs.io](\ https://fac
168
+ image = face_recognition.load_image_file(" my_picture.jpg" )
169
+ face_locations = face_recognition.face_locations(image)
103
170
104
- .. _dlib : http://dlib.net/
105
- .. _digital make-up : https://github.com/ageitgey/face_recognition/blob/master/examples/digital_makeup.py
171
+ # face_locations is now an array listing the co-ordinates of each face!
172
+
173
+ See `this
174
+ example <https://github.com/ageitgey/face_recognition/blob/master/examples/find_faces_in_picture.py> `__
175
+ to try it out.
176
+
177
+ Automatically locate the facial features of a person in an image
178
+ ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
179
+
180
+ .. code :: python
181
+
182
+ import face_recognition
183
+
184
+ image = face_recognition.load_image_file(" my_picture.jpg" )
185
+ face_landmarks_list = face_recognition.face_landmarks(image)
186
+
187
+ # face_landmarks_list is now an array with the locations of each facial feature in each face.
188
+ # face_landmarks_list[0]['left_eye'] would be the location and outline of the first person's left eye.
189
+
190
+ See `this
191
+ example <https://github.com/ageitgey/face_recognition/blob/master/examples/find_facial_features_in_picture.py> `__
192
+ to try it out.
193
+
194
+ Recognize faces in images and identify who they are
195
+ '''''''''''''''''''''''''''''''''''''''''''''''''''
196
+
197
+ .. code :: python
198
+
199
+ import face_recognition
200
+
201
+ picture_of_me = face_recognition.load_image_file(" me.jpg" )
202
+ my_face_encoding = face_recognition.face_encodings(picture_of_me)[0 ]
203
+
204
+ # my_face_encoding now contains a universal 'encoding' of my facial features that can be compared to any other picture of a face!
205
+
206
+ unknown_picture = face_recognition.load_image_file(" unknown.jpg" )
207
+ unknown_face_encoding = face_recognition.face_encodings(unknown_picture)[0 ]
208
+
209
+ # Now we can see the two face encodings are of the same person with `compare_faces`!
210
+
211
+ results = face_recognition.compare_faces([my_face_encoding], unknown_face_encoding)
212
+
213
+ if results[0 ] == True :
214
+ print (" It's a picture of me!" )
215
+ else :
216
+ print (" It's not a picture of me!" )
217
+
218
+ See `this
219
+ example <https://github.com/ageitgey/face_recognition/blob/master/examples/recognize_faces_in_pictures.py> `__
220
+ to try it out.
221
+
222
+ Python Code Examples
223
+ --------------------
224
+
225
+ All the examples are available
226
+ `here <https://github.com/ageitgey/face_recognition/tree/master/examples >`__.
227
+
228
+ - `Find faces in an
229
+ photograph <https://github.com/ageitgey/face_recognition/blob/master/examples/find_faces_in_picture.py> `__
230
+ - `Identify specific facial features in a
231
+ photograph <https://github.com/ageitgey/face_recognition/blob/master/examples/find_facial_features_in_picture.py> `__
232
+ - `Apply (horribly ugly) digital
233
+ make-up <https://github.com/ageitgey/face_recognition/blob/master/examples/digital_makeup.py> `__
234
+ - `Find and recognize unknown faces in a photograph based on
235
+ photographs of known
236
+ people <https://github.com/ageitgey/face_recognition/blob/master/examples/recognize_faces_in_pictures.py> `__
237
+
238
+ Caveats
239
+ -------
240
+
241
+ - The face recognition model is trained on adults does not work very
242
+ well on children. It tends to mix up children quite easy using the
243
+ default comparison threshold of 0.6.
244
+
245
+ Thanks
246
+ ------
247
+
248
+ - Many, many thanks to `Davis King <https://github.com/davisking >`__
249
+ ([@nulhom](https://twitter.com/nulhom)) for creating dlib and for
250
+ providing the trained facial feature detection and face encoding
251
+ models used in this library. For more information on the ResNet the
252
+ powers the face encodings, check out his `blog
253
+ post <http://blog.dlib.net/2017/02/high-quality-face-recognition-with-deep.html> `__.
254
+ - Everyone who works on all the awesome Python data science libraries
255
+ like numpy, scipy, scikit-image, pillow, etc, etc that makes this
256
+ kind of stuff so easy and fun in Python.
257
+ - `Cookiecutter <https://github.com/audreyr/cookiecutter >`__ and the
258
+ `audreyr/cookiecutter-pypackage <https://github.com/audreyr/cookiecutter-pypackage >`__
259
+ project template for making Python project packaging way more
260
+ tolerable.
106
261
107
262
.. |image0 | image :: https://img.shields.io/pypi/v/face_recognition.svg
108
263
.. |image1 | image :: https://travis-ci.org/ageitgey/face_recognition
109
- .. |image2 | image :: https://cloud.githubusercontent.com/assets/896692/23582662/3891b65c-00e4-11e7-848e-0007bca850df.png
110
- .. |image3 | image :: https://cloud.githubusercontent.com/assets/896692/23582665/3bbf323c-00e4-11e7-83f9-d42ede9ead2d.png
111
- .. |f3 | image :: https://cloud.githubusercontent.com/assets/896692/23582667/3cf969c4-00e4-11e7-82e6-add45ae3992f.png
112
- .. |f4 | image :: https://cloud.githubusercontent.com/assets/896692/23582670/405a5268-00e4-11e7-879f-b4de9f727096.png
113
- .. |known | image :: https://cloud.githubusercontent.com/assets/896692/23582466/8324810e-00df-11e7-82cf-41515eba704d.png
114
- .. |unknown | image :: https://cloud.githubusercontent.com/assets/896692/23582465/81f422f8-00df-11e7-8b0d-75364f641f58.png
264
+
0 commit comments