Litterae.eu
Humanities & IT


Face recognition with Ubuntu, update April 2023

A few years ago, I talked about face recognition with Ubuntu to organise and classify a personal photo archive. The challenging part then was the compilation of the libraries and the use of two separate pieces of software to be run together.
Today, the experience is simpler, everything having been precompiled and merged into a single package that can be conveniently installed from the terminal.
The prerequisite is to have Python 3 installed; it is generally already present on the most recent versions of Ubuntu and derivatives. Incidentally, I think the application works on every Linux distribution, but I invite those interested to try it out for themselves.

So, after opening the terminal, we just have to install the precompiled libraries, by typing
pip3 install dlib opencv-python
and then the unified package
pip3 install face_recognition
Done.

The Face Recognition packages cotains two commands:
- face_detection, which checks whether there are faces in a given photo or series of photos;
- face_recognition, which, when comparing two photos or two sets of photos, checks whether there are faces in the second one that are also present in the first one.
Let us do a practical example.

Let us assume that we have in a folder called Friends some pictures with the faces of people we already know: Mark.jpg, Nora.png, Louise.tif, etc.
In a second folder called New_pics we have other photos, for convenience all named Photo[some_number].jpg, which we have not yet looked at carefully, but in which we want to check on the fly whether any of the people in the Friends folder are portrayed.
Let us open the terminal at the location of the two folders mentioned above and type
face_recognition Friends/ New_pics/
The response will be a list of the photos in New_pics with an indication of whether or not they match one or more of those in Friends:
New_pics/Photo1.jpg,unknown_person
New_pics/Photo2.jpg,unknown_person
New_pics/Photo3.jpg,Nora

and so on.

Let us now assume instead that we have a folder named Holidays, and we are only interested in identifying which photographs contain people, regardless of who they are.
face_detection Holidays/
The response will be a list of only those images containing faces, with the x and y coordinates of the top left and bottom right corners within which they are enclosed:
Holidays/Photo1.jpg,89,192,192,89
Holidays/Photo2.png,496,1095,1266,325

Those wishing to learn more about the documentation can visit the package page or the useful tutorial on the cosine similarity underlying the algorithm.


Site designed by litterae.eu. © 2004-2025. All rights reserved.
Info GDPR EU 2016/679: no cookies used, no personal data collected.