Skip to content

Commit 4502c77

Browse files
committed
Updated RST docs
1 parent 1265c40 commit 4502c77

File tree

1 file changed

+200
-50
lines changed

1 file changed

+200
-50
lines changed

README.rst

Lines changed: 200 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,131 @@
11
Face Recognition
22
================
33

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.
56

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.
711

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!
1015

11-
Recognize and manipulate faces from Python or from the command line
12-
13-
Free software, MIT license.
16+
|image0| |image1|
1417

1518
Features
1619
--------
1720

1821
Find faces in pictures
1922
^^^^^^^^^^^^^^^^^^^^^^
2023

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:
2228

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)
2434
2535
Find and manipulate facial features in pictures
2636
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2737

28-
Get the locations and outlines of each persons eyes, nose, mouth and
38+
Get the locations and outlines of each person's eyes, nose, mouth and
2939
chin.
3040

31-
|image3|
41+
.. figure:: https://cloud.githubusercontent.com/assets/896692/23625282/7f2d79dc-025d-11e7-8728-d8924596f8fa.png
42+
:alt:
43+
44+
.. code:: python
3245
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)
3649
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:
3857

3958
Identify faces in pictures
4059
^^^^^^^^^^^^^^^^^^^^^^^^^^
4160

4261
Recognize who appears in each photo.
4362

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.
4599

46100
Usage
47101
-----
48102

49103
Command-Line Interface
50104
^^^^^^^^^^^^^^^^^^^^^^
51105

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:
56113

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
61116

62-
|known|
117+
known
63118

64119
Next, you need a second folder with the files you want to identify:
65120

66-
|unknown|
121+
.. figure:: https://cloud.githubusercontent.com/assets/896692/23582465/81f422f8-00df-11e7-8b0d-75364f641f58.png
122+
:alt: unknown
67123

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:
72129

73130
.. code:: bash
74131
@@ -77,17 +134,14 @@ Next, you need a second folder with the files you want to identify:
77134
/unknown_pictures/unknown.jpg,Barack Obama
78135
/face_recognition_test/unknown_pictures/unknown.jpg,unknown_person
79136
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.
83139

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.
87142

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:
91145

92146
.. code:: bash
93147
@@ -96,19 +150,115 @@ Next, you need a second folder with the files you want to identify:
96150
Barack Obama
97151
unknown_person
98152
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
101167
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)
103170
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.
106261

107262
.. |image0| image:: https://img.shields.io/pypi/v/face_recognition.svg
108263
.. |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

Comments
 (0)