#VSCode – Let’s do some #FaceRecognition with 20 lines in #Python (5/N)

Hi !

I’ll start with my posts

  1. Detecting Faces with 20 lines in Python
  2. Face Recognition with 20 lines in Python
  3. Detecting Facial Features with 20 lines in Python
  4. Facial Features and Face Recognition with 20 lines in Python

And after yesterday’s post I realize that the code is working, but there is room for performance improvement. So, I went back to my 1st sample, the one for face detection and I added some code to get some times for Frames per Second (FPS).

In my initial code, the app was working processing almost 6 FPS. Then I started to read the code and think on improvements and I manage to get an amazing +30FPS.

So, before moving forward, I want to remark this StackOverflow post that quickly pointed me in the easiest way to do a StopWatch in Python.

My original code, was this one:

And then, I realize that I may use some of the OpenCV functions to increase the face detection process. I really don’t need to process a full HD image (1920 x 1080), I may resize the frame to a quarter size and work with this. That’s how, based on some of the samples, I got the following code:

The line 12 perform the initial resize and then I recalculate back the positions before drawing the face frame. This process works almost 6 times faster than the original one.

I’ll continue improving the code and samples, and sharing my learning path !

Happy Coding!

Greetings @ Burlington

El Bruno

Resources

#VSCode – Let’s do some #FaceRecognition with 20 lines in #Python (4/N)

Hi !

Quick post today. I’ll pickup yesterday demo, showing the facial features and adding Face Recognition on top of that. In other words, we’ll move from this

To this

With a couple of extra lines for face recognition

There is some room for performance improvement, so I’ll focus on this in next posts.

The complete project is available here https://github.com/elbruno/Blog/tree/master/20190528%20Python%20FaceRecognition

Happy Coding!

Greetings @ Burlington

El Bruno

Resources

My Posts

  1. Detecting Faces with 20 lines in Python
  2. Face Recognition with 20 lines in Python
  3. Detecting Facial Features with 20 lines in Python

#VSCode – Let’s do some #FaceRecognition with 20 lines in #Python (3/N)

Hi !

In my previous posts I explained how to detect faces and perform face recognition in python. Today I’ll explore another feature in the face_recognition package: Find Facial Features.

The live camera output will be something like this:

Note: Special thanks to my daughter who is always OK to help me with this.

The main sample in the source code uses a photo to detect facial features and creates a new one with the features detected. In the following sample, is amazing to check that it detect a far away face behind the main ones and also, somehow, it detect some landmarks behind my girl glasses:

I wanted to see how fast this library work to perform this with a live camera feed, and the results are very good.

I spend sometime figuring out the best way to draw lines with OpenCV, at the end the PolyLine() function is the one doing all the magic (lines 14 to 17). It took me sometime, to find the best way to deal with matrix transformations and some other performance tricks, but at the end I get this up and running in 25 lines which is kind of amazing. And the final code is very simple:

The complete project is available here https://github.com/elbruno/Blog/tree/master/20190528%20Python%20FaceRecognition

Happy Coding!

Greetings @ Burlington

El Bruno

Resources

My Posts

  1. Detecting Faces with 20 lines in Python
  2. Face Recognition with 20 lines in Python

#VSCode – Let’s do some #FaceRecognition with 20 lines in #Python (2/N)

Hi !

Yesterday I explained how to write a couple of lines in Python to perform live face detection in a webcam feed [Post]. Check the resources section to find more about the tools I’m using.

Today, I’ll add some more code to perform face recognition. And as usual, I’ll work with my kids to test this out. I’ll start adding 2 face encodings for Valentino and myself. The code is simple enough, and I use a simple 300×300 head-shot photo to train and get the face encoding.

The previous function returns an set of arrays with the face encodings and the face names. In the complete file, I’ll use this to analyze the camera frame (line 31) and later to check the matches for faces (lines 34 * 36)

Last lines are cosmetic to mostly draw the frames for the detected faces, and show the names.

The complete project is available here https://github.com/elbruno/Blog/tree/master/20190521%20Python%20FaceRecognition

Happy Coding!

Greetings @ Burlington

El Bruno

Resources

My Posts

#VSCode – Let’s do some #FaceRecognition with 20 lines in #Python

Hi !

I’ve write a lot about how to use AI models in C# to perform tasks like Face recognition, speech analysis, and more. During the Chicago CodeCamp, someone ask me about how to perform Face Recognition in Python. I didn’t have any working sample to showcase this, and I failed in try to write a 2 min app. So I added this into my ToDo list.

For this demo I’ll use Anaconda as the base Python distribution and Visual Studio Code as the code editor. There are several packages to perform face detection in Python. I’ll use a mix between OpenCV and Adam Geitgey Face Recognition package to use the camera and detect and recognize faces.

I’ll start by installing some packages to use in python app: dlib, openCV and face_recognition

"C:/Program Files (x86)/Microsoft Visual Studio/Shared/Anaconda3_86/python.exe" -m pip install dlib --user  

"C:/Program Files (x86)/Microsoft Visual Studio/Shared/Anaconda3_86/python.exe" -m pip install face_recognition --user

"C:/Program Files (x86)/Microsoft Visual Studio/Shared/Anaconda3_86/python.exe" -m pip install opencv-python --user  

And, the first step will be to detect faces and draw frames around them. All of this in 20 lines of code

When we run the app, we will see the camera feed and frames around the detected faces. In my next post I’ll add some extra code to perform face recognition.

Happy Coding!

Greetings @ Toronto

El Bruno

Resources

#ComputerVision – How to create a 3D model of a face using a 2D photo (Amazing !)

Hello!

The advances in Computer Vision are becoming more and more impressive. The suite I know best and with use more is Azure Cognitive services, however, there are surprises and advances that leave me with my mouth open.

This is the case of the work published by Aaron S. Jackson, Adrian encyclical, Vasileios Argyriou and Georgios Tzimiropoulos, where he explains how he can create a 3d model from a 2d photo. The best thing is to see it in action

2017 09 25 3D face from 2D 01.gif

I recommend you also see the video where they apply the algorithm in real-time to faces in a video.

Now is the time to try to explain, with my words of a 5-year-old boy, how this works. Behind this algorithm is a Convolutional Neural Network (CNN), which has been trained with 2D images with the results expected in 3D. The interesting thing about this model is that it has reached such a level of sophistication that it does not need a specific point of reference for a face, it works on any face.

With the 2D image information, it is possible to rebuild elements of the face, including parts that are not seen in the 2D image. In this way, and after much training CNN, achieve the results that can be seen in the live demo!

Maybe it’s better to hear this in their own words

Greetings @ Toronto

El Bruno

References

#ComputerVision – Crear un modelo 3D de un rostro a partir de una foto 2D (Impresionante !)

Hola!

Los avances en Computer Vision son cada vez más impresionantes. La suite que mejor conozco y con la que trabajo son los servicios de Cognitive Services, sin embargo, hay sorpresas y avances que me dejan con la boca abierta.

Este es el caso del trabajo que han publicado Aaron S. Jackson, Adrian Bulat, Vasileios Argyriou and Georgios Tzimiropoulos, donde explica cómo puede crear un modelo 3D a partir de una foto 2D. Lo mejor es verlo en acción

2017 09 25 3D face from 2D 01.gif

Les recomiendo ver también el video donde aplica el algoritmo en tiempo real a faces en un video. Ahora es el momento de intentar explicar, con mis palabras de un niño de 5 años, como funciona esto.

Detrás de este algoritmo hay una Convolutional Neural Network (CNN), que ha sido entrenada con imágenes en 2D con los resultados esperados en 3D. Lo interesante de este modelo, es que ha llegado a un nivel de sofisticación tal, que no necesita un punto de referencia específico para un rostro, funciona sobre cualquier rostro. Con la información de la imagen 2D, es posible reconstruir elementos del rostro, inclusive de partes que no se ven en la imagen 2D. De esta forma, y después de MUCHO entrenar la CNN, logran los resultado que se pueden ver en la live demo!

Tal vez mejor es escuchar las palabras de Aaron

Saludos @ Burlington

El Bruno

References

#ProjectOxford – New features for #FaceAPI: beard, moustache, smile detection and more !!!

Hello!

New Face API and Emotion API features: detection of beards, moustaches, smiles and much more.

2016 01 29 Face API

These days I have been reviewing some projects where I’ve used some Project Oxford APIs and I found that the APIs have changed a little.

image

The Newtonsoft.Json is already a classic: updates all the time. However I made some research on the new features for Face API. So here are a couple of them

  • The documentation is now integrated within MSDN. A Must Have for a 1.0 version
  • The new ability to detect new attributes for each face like as the beard, mustache or smiles

image

  • Now we also have the possibility of obtaining landmarks in detected faces.

image

And finally the official changes that are discussed in the Project Oxford page.

  • API Signature
    In Project Oxford Face V1.0, Service root endpoint changes from “https://api.projectoxford.ai/face/v0/” to “https://api.projectoxford.ai/face/v1.0/”
    There are several signature changes for API, such as Face – Detect, Face – Identify, Face – Find Similar, Face – Group.
  • The previous version of Project Oxford Face API was not clear about the smallest face sizes the API could detect. With the new V1.0, the API correctly sets the minimal detectable size to 36×36 pixels. Faces smaller 36×36 pixels will not be detected.
  • Persisted Data
    Existing Person Group and Person data which has been setup with Project Oxford Face V0 cannot be accessed with Project Oxford Face V1.0 service. This incompatible issue will occur for only this one time, following API updates will not affect persisted data any more.

Greetings @ Madrid

-El Bruno

References

#Azure – Novedades en #ProjectOxford en #FaceAPI: detección de barba, bigote, sonrisas y más !!!

Hola !

Novedades en Face API y Emotion API, detección de barbas, bigotes, sonrisas y mucho más.

2016 01 29 Face API

En estos días he estado revisando unos proyectos en los que usamos algunas APIs de Project Oxford y me he encontrado que las APIs han cambiado un poco.

image

Lo de Newtonsoft.Json ya es un clásico, sin embargo me dió por ver que nuevas features teníamos en Face API y Emotion API. Asi que aquí van un par

  • Ahora la documentación está integrada dentro de MSDN. Normal para una versión 1.0
  • La nueva capacidad de detectar nuevos atributos como la barba, bigote o sonrisa

image

  • Ahora también tenemos la posibilidad de obtener landmarks en los rostros detectados.

image

Y por último los cambios oficiales que se comentan en la pagina de Project Oxford.

  • API Signature
    In Project Oxford Face V1.0, Service root endpoint changes from “https://api.projectoxford.ai/face/v0/” to “https://api.projectoxford.ai/face/v1.0/”
    There are several signature changes for API, such as Face – Detect, Face – Identify, Face – Find Similar, Face – Group.
  • The previous version of Project Oxford Face API was not clear about the smallest face sizes the API could detect. With the new V1.0, the API correctly sets the minimal detectable size to 36×36 pixels. Faces smaller 36×36 pixels will not be detected.
  • Persisted Data
    Existing Person Group and Person data which has been setup with Project Oxford Face V0 cannot be accessed with Project Oxford Face V1.0 service. This incompatible issue will occur for only this one time, following API updates will not affect persisted data any more.

Saludos @ Madrid

-El Bruno

References

#VS2015 – #FateDetection and Merry Christmas #Coding4Fun

Hi!

Although Christmas is gone, my children still love to play with their Santa hats. Half of them have already have been given, but I get out my dev superpowers and with 4 lines of code I add some VIRTUAL HATS in the face detection app !!!

2016 01 04 FaceDetection Merry Christmas

Like always the source is on GitHub and a couple of details

  • The app is Windows Universal App, you can install it on Windows Phone 10, and you can have the same fun in small format
  • The top 2 buttons enable the show and hide frames the face and Santa Hat
  • On the code of the routine to draw the frame, I have created that puts the Santa Hat
  • I still have pending improved the Resize of the app 😉

Greetings @ Madrid

-El Bruno

References