Face recognition with Ubuntu
It has been a while now, artificial intelligence applied to face recognition became a common practice, not only by police and security forces, but also by numerous app developers and Internet sites.
Ever since digital photography (first digital cameras, then smart phones) replaced films and slides, each of us takes exponentially more photos at every opportunity; it is easy, for example, to take up to a thousand photos in a week's holiday, as opposed to the maximum of two 36-pose films of a few decades ago. All these photos end up, in the most virtuous cases, crammed into some hard disk, where they can quickly become tens of thousands. And you know that there will never be a sorting process to print the best ones and that, perhaps apart from the first few days after returning from holiday, you will never even look at them again. Why? Simply because there are too many of them.
Well, this is precisely a case where a face recognition software could come to the rescue. So let's see how to proceed, having Ubuntu as the operating system.
The first is Facedetect, developed by Yuri d'Elia. As the developer states, Facedetect does only two things: it recognises if there is a person's face in a photo and, by interacting with the Imagemagick library, it is able to extract the face alone, saving it to a new image file. An extremely useful function, as we shall see a little further on. The software's limitation is that, if a face in the foreground protrudes beyond the borders of the image, it is not recognised.
The second alternative is Face_recognition, developed by Adam Geitgey. This second one does exactly, and with great accuracy, what is expected: given one or a few control images which contain the face of a known person, it searches one or more photos to see if the person appears in them and, if so, indicates in which ones. The astonishing thing is that, use after use, the algorithm called up by Face_recognition increases its recognition ability; it is enough to add to the control images the close-ups of the person recognised in a previous step (and here the use of Facedetect's extraction function is extremely useful) to see the software's already high accuracy grow exponentially. According to the developer, after a bit of training, the model reaches an accuracy of 99.38%.
Proved the effectiveness of the two softwares working together, I just had to write a small bash launcher to make them work automatically in succession and pass the results to a PHP script, which I entrusted with the task of organising all the information provided by the two detectors in a database that would gradually collect the various tags relating to a cyclopic digital photo archive which had remained silent and anonymous until recently.
See update.
Uses that, while involving ordinary citizens as targets of potential recognition, are far from being of their own interest. But this does not deny that face recognition could have for them too a good daily uselfulness.
And then again, who is going to rummage through those tons of digital stuff after 3, 5, 10 years to find the picture of that girl they met on the beach or their grandson on skis? Too bad, it was such a nice photo...
Ubuntu currently offers two alternatives based respectively on Dlib and Tensorflow. But we will see in a moment that they can work in a complementary manner.
After a bit of experimentation, I can confirm the results are amazing; and after a few steps Face_recognition is even able to overcome the limitation, initially shared with Facedetect, of not recognising a face protruding beyond the borders of the image.