#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

Advertisements

#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 (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

#VS2017 – HowTo: Share code from IDE in #Gist with a single click!

 

Hi !

For a while I decided to stop sharing code using “text” in my blog. I used to share a screen shoot of the code and then a link to the full example on GitHub. This seemed like a good idea, because on several occasions I had had unfortunate comments from people who performed a “copy & paste” portions of code from my blog, without even reading the complete sample.

Well, a while ago, a blind developer complained about those who shared code with images. And of course, after meeting a blind person who shared with me how he program every day, I did an evaluation and decided that it was best to go back to share code in text mode. (BTW: I wrote about this a while ago)

One of the best platforms for this is the Gists from GitHub, which gives us all the experience and appearance of GitHub. Yes, if you look for the option of doing it from the IDE, the next extension is more than useful Gists for Visual Studio.

The way to use it is quite simple, the Code Editor displays the context menu and you will see the new option “Create a new gist”

 

Clipboard02

The first time we use the extension, we must authenticate in Gists. After this, the next step is to define the name of the file, a description and if we want to share all the code of the file we are working on or just the selected text.

Clipboard04

The extension will create the Gist and share back the Url of the created one.

Clipboard06

Sample output for the post:

Happy Coding!

Greetings @ VSLive en Austin

El Bruno

References

#VS2017 – HowTo: Compartir código en #Gist desde el IDE con un click

 

Hola !

Durante un tiempo decidí dejar de compartir código en mi blog en formato texto, lo que solía hacer es compartir un screenshoot del código y luego un link al ejemplo completo en GitHub. Esto me parecía una buena idea, ya que en varias ocasiones, había tenido comentarios desafortunados de personas que “copiaban y pegaban” porciones de código de mi blog, sin siquiera leer el mismo.

Pues bien, hace un tiempo, un developer ciego se quejó de aquellos que compartíamos código con imágenes. Y claro, después de conocer a una persona ciega que me comentó como programaba, hice una evaluación y decidí que lo mejor era volver a compartir código en modo texto. (Ya escribí de esto hace un tiempo)

Una de las mejores plataformas para esto es Gists de GitHub, que nos brinda toda la experiencia y apariencia de GitHub. Eso sí, si buscar tener la opción de hacerlo desde el IDE, la siguiente extensión es más que útil Gists for Visual Studio.

La forma de utilizarlo es bastante simple, en el editor de código despliegas el menú contextual y verás la nueva opción “Create a new Gist”

Clipboard02

La primera vez que utilicemos la extensión, debermos autenticarnos en Gists. El siguiente paso es definir el nombre del archivo, una descripción y si queremos compartir todo el código del archivo sobre el que estamos trabajando o solo el texto seleccionado.

Clipboard04

La extensión se encarga de crear el Gist y nos retorna la URL del código publicado.

Clipboard06

El ejemplo es más que completo:

Happy Coding!

Saludos @ VSLive en Austin

El Bruno

References