Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

README.rst 11 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
  1. Face Recognition
  2. ================
  3. | Recognize and manipulate faces from Python or from the command line
  4. with
  5. | the world's simplest face recognition library.
  6. | Built using `dlib <http://dlib.net/>`__'s state-of-the-art face
  7. recognition
  8. | built with deep learning. The model has an accuracy of 99.38% on the
  9. | `Labeled Faces in the Wild <http://vis-www.cs.umass.edu/lfw/>`__
  10. benchmark.
  11. | This also provides a simple ``face_recognition`` command line tool
  12. that lets
  13. | you do face recognition on a folder of images from the command line!
  14. | |PyPI|
  15. | |Build Status|
  16. | |Documentation Status|
  17. Features
  18. --------
  19. Find faces in pictures
  20. ^^^^^^^^^^^^^^^^^^^^^^
  21. Find all the faces that appear in a picture:
  22. |image3|
  23. .. code:: python
  24. import face_recognition
  25. image = face_recognition.load_image_file("your_file.jpg")
  26. face_locations = face_recognition.face_locations(image)
  27. Find and manipulate facial features in pictures
  28. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  29. Get the locations and outlines of each person's eyes, nose, mouth and
  30. chin.
  31. |image4|
  32. .. code:: python
  33. import face_recognition
  34. image = face_recognition.load_image_file("your_file.jpg")
  35. face_landmarks_list = face_recognition.face_landmarks(image)
  36. | Finding facial features is super useful for lots of important stuff.
  37. But you can also use for really stupid stuff
  38. | like applying `digital
  39. make-up <https://github.com/ageitgey/face_recognition/blob/master/examples/digital_makeup.py>`__
  40. (think 'Meitu'):
  41. |image5|
  42. Identify faces in pictures
  43. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  44. Recognize who appears in each photo.
  45. |image6|
  46. .. code:: python
  47. import face_recognition
  48. known_image = face_recognition.load_image_file("biden.jpg")
  49. unknown_image = face_recognition.load_image_file("unknown.jpg")
  50. biden_encoding = face_recognition.face_encodings(known_image)[0]
  51. unknown_encoding = face_recognition.face_encodings(unknown_image)[0]
  52. results = face_recognition.compare_faces([biden_encoding], unknown_encoding)
  53. Installation
  54. ------------
  55. | Python 3 / Python 2 are fully supported. Only macOS and
  56. | Linux are tested. I have no idea if this will work on Windows.
  57. Install this module from pypi using ``pip3`` (or ``pip2`` for Python 2):
  58. .. code:: bash
  59. pip3 install face_recognition
  60. | IMPORTANT NOTE: It's very likely that you will run into problems when
  61. pip tries to compile
  62. | the ``dlib`` dependency. If that happens, check out this guide to
  63. installing
  64. | dlib from source (instead of from pip) to fix the error:
  65. `How to install dlib from
  66. source <https://gist.github.com/ageitgey/629d75c1baac34dfa5ca2a1928a7aeaf>`__
  67. | After manually installing ``dlib``, try running
  68. ``pip3 install face_recognition``
  69. | again to complete your installation.
  70. Usage
  71. -----
  72. Command-Line Interface
  73. ^^^^^^^^^^^^^^^^^^^^^^
  74. | When you install ``face_recognition``, you get a simple command-line
  75. program
  76. | called ``face_recognition`` that you can use to recognize faces in a
  77. | photograph or folder full for photographs.
  78. | First, you need to provide a folder with one picture of each person
  79. you
  80. | already know. There should be one image file for each person with the
  81. | files named according to who is in the picture:
  82. |known|
  83. Next, you need a second folder with the files you want to identify:
  84. |unknown|
  85. | Then in you simply run the command ``face_recognition``, passing in
  86. | the folder of known people and the folder (or single image) with
  87. unknown
  88. | people and it tells you who is in each image:
  89. .. code:: bash
  90. $ face_recognition ./pictures_of_people_i_know/ ./unknown_pictures/
  91. /unknown_pictures/unknown.jpg,Barack Obama
  92. /face_recognition_test/unknown_pictures/unknown.jpg,unknown_person
  93. | There's one line in the output for each face. The data is
  94. comma-separated
  95. | with the filename and the name of the person found.
  96. | An ``unknown_person`` is a face in the image that didn't match anyone
  97. in
  98. | your folder of known people.
  99. | If you simply want to know the names of the people in each photograph
  100. but don't
  101. | care about file names, you could do this:
  102. .. code:: bash
  103. $ face_recognition ./pictures_of_people_i_know/ ./unknown_pictures/ | cut -d ',' -f2
  104. Barack Obama
  105. unknown_person
  106. Python Module
  107. ^^^^^^^^^^^^^
  108. | You can import the ``face_recognition`` module and then easily
  109. manipulate
  110. | faces with just a couple of lines of code. It's super easy!
  111. API Docs:
  112. `https://face-recognition.readthedocs.io <https://face-recognition.readthedocs.io/en/latest/face_recognition.html>`__.
  113. Automatically find all the faces in an image
  114. ''''''''''''''''''''''''''''''''''''''''''''
  115. .. code:: python
  116. import face_recognition
  117. image = face_recognition.load_image_file("my_picture.jpg")
  118. face_locations = face_recognition.face_locations(image)
  119. # face_locations is now an array listing the co-ordinates of each face!
  120. | See `this
  121. example <https://github.com/ageitgey/face_recognition/blob/master/examples/find_faces_in_picture.py>`__
  122. | to try it out.
  123. Automatically locate the facial features of a person in an image
  124. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  125. .. code:: python
  126. import face_recognition
  127. image = face_recognition.load_image_file("my_picture.jpg")
  128. face_landmarks_list = face_recognition.face_landmarks(image)
  129. # face_landmarks_list is now an array with the locations of each facial feature in each face.
  130. # face_landmarks_list[0]['left_eye'] would be the location and outline of the first person's left eye.
  131. | See `this
  132. example <https://github.com/ageitgey/face_recognition/blob/master/examples/find_facial_features_in_picture.py>`__
  133. | to try it out.
  134. Recognize faces in images and identify who they are
  135. '''''''''''''''''''''''''''''''''''''''''''''''''''
  136. .. code:: python
  137. import face_recognition
  138. picture_of_me = face_recognition.load_image_file("me.jpg")
  139. my_face_encoding = face_recognition.face_encodings(picture_of_me)[0]
  140. # my_face_encoding now contains a universal 'encoding' of my facial features that can be compared to any other picture of a face!
  141. unknown_picture = face_recognition.load_image_file("unknown.jpg")
  142. unknown_face_encoding = face_recognition.face_encodings(unknown_picture)[0]
  143. # Now we can see the two face encodings are of the same person with `compare_faces`!
  144. results = face_recognition.compare_faces([my_face_encoding], unknown_face_encoding)
  145. if results[0] == True:
  146. print("It's a picture of me!")
  147. else:
  148. print("It's not a picture of me!")
  149. | See `this
  150. example <https://github.com/ageitgey/face_recognition/blob/master/examples/recognize_faces_in_pictures.py>`__
  151. | to try it out.
  152. Python Code Examples
  153. --------------------
  154. All the examples are available
  155. `here <https://github.com/ageitgey/face_recognition/tree/master/examples>`__.
  156. - `Find faces in a
  157. photograph <https://github.com/ageitgey/face_recognition/blob/master/examples/find_faces_in_picture.py>`__
  158. - `Identify specific facial features in a
  159. photograph <https://github.com/ageitgey/face_recognition/blob/master/examples/find_facial_features_in_picture.py>`__
  160. - `Apply (horribly ugly) digital
  161. make-up <https://github.com/ageitgey/face_recognition/blob/master/examples/digital_makeup.py>`__
  162. - `Find and recognize unknown faces in a photograph based on
  163. photographs of known
  164. people <https://github.com/ageitgey/face_recognition/blob/master/examples/recognize_faces_in_pictures.py>`__
  165. - `Recognize faces in live video using your webcam (Requires OpenCV to
  166. be
  167. installed) <https://github.com/ageitgey/face_recognition/blob/master/examples/facerec_from_webcam.py>`__
  168. How Face Recognition Works
  169. --------------------------
  170. | If you want to learn how face location and recognition work instead of
  171. | depending on a black box library, `read my
  172. article <https://medium.com/@ageitgey/machine-learning-is-fun-part-4-modern-face-recognition-with-deep-learning-c3cffc121d78>`__.
  173. Caveats
  174. -------
  175. - The face recognition model is trained on adults and does not work
  176. very well on children. It tends to mix
  177. up children quite easy using the default comparison threshold of 0.6.
  178. Common Issues
  179. -------------
  180. Issue: ``Illegal instruction (core dumped)`` when using face\_recognition or running examples.
  181. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  182. | Solution: ``dlib`` is compiled with SSE4 or AVX support, but your CPU
  183. is too old and doesn't support that.
  184. | You'll need to recompile ``dlib`` after `making the code change
  185. outlined
  186. here <https://github.com/ageitgey/face_recognition/issues/11#issuecomment-287398611>`__.
  187. Issue: ``RuntimeError: Unsupported image type, must be 8bit gray or RGB image.`` when running the webcam example.
  188. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  189. Solution: Your webcam probably isn't set up correctly with OpenCV. `Look
  190. here for
  191. more <https://github.com/ageitgey/face_recognition/issues/21#issuecomment-287779524>`__.
  192. Issue: ``MemoryError`` when running ``pip2 install face_recognition``
  193. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  194. | Solution: The face\_recognition\_models file is too big for your
  195. available pip cache memory. Instead,
  196. | try ``pip2 --no-cache-dir install face_recognition`` to avoid the
  197. issue.
  198. Thanks
  199. ------
  200. - Many, many thanks to `Davis King <https://github.com/davisking>`__
  201. (`@nulhom <https://twitter.com/nulhom>`__)
  202. for creating dlib and for providing the trained facial feature
  203. detection and face encoding models
  204. used in this library. For more information on the ResNet that powers
  205. the face encodings, check out
  206. his `blog
  207. post <http://blog.dlib.net/2017/02/high-quality-face-recognition-with-deep.html>`__.
  208. - Thanks to everyone who works on all the awesome Python data science
  209. libraries like numpy, scipy, scikit-image,
  210. pillow, etc, etc that makes this kind of stuff so easy and fun in
  211. Python.
  212. - Thanks to `Cookiecutter <https://github.com/audreyr/cookiecutter>`__
  213. and the
  214. `audreyr/cookiecutter-pypackage <https://github.com/audreyr/cookiecutter-pypackage>`__
  215. project template
  216. for making Python project packaging way more tolerable.
  217. .. |PyPI| image:: https://img.shields.io/pypi/v/face_recognition.svg
  218. :target: https://pypi.python.org/pypi/face_recognition
  219. .. |Build Status| image:: https://travis-ci.org/ageitgey/face_recognition.svg?branch=master
  220. :target: https://travis-ci.org/ageitgey/face_recognition
  221. .. |Documentation Status| image:: https://readthedocs.org/projects/face-recognition/badge/?version=latest
  222. :target: http://face-recognition.readthedocs.io/en/latest/?badge=latest
  223. .. |image3| image:: https://cloud.githubusercontent.com/assets/896692/23625227/42c65360-025d-11e7-94ea-b12f28cb34b4.png
  224. .. |image4| image:: https://cloud.githubusercontent.com/assets/896692/23625282/7f2d79dc-025d-11e7-8728-d8924596f8fa.png
  225. .. |image5| image:: https://cloud.githubusercontent.com/assets/896692/23625283/80638760-025d-11e7-80a2-1d2779f7ccab.png
  226. .. |image6| image:: https://cloud.githubusercontent.com/assets/896692/23625229/45e049b6-025d-11e7-89cc-8a71cf89e713.png
  227. .. |known| image:: https://cloud.githubusercontent.com/assets/896692/23582466/8324810e-00df-11e7-82cf-41515eba704d.png
  228. .. |unknown| image:: https://cloud.githubusercontent.com/assets/896692/23582465/81f422f8-00df-11e7-8b0d-75364f641f58.png
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...