Sunday, March 7, 2021
  • Setup menu at Appearance » Menus and assign menu to Top Bar Navigation
Advertisement
  • AI Development
    • Artificial Intelligence
    • Machine Learning
    • Neural Networks
    • Learn to Code
  • Data
    • Blockchain
    • Big Data
    • Data Science
  • IT Security
    • Internet Privacy
    • Internet Security
  • Marketing
    • Digital Marketing
    • Marketing Technology
  • Technology Companies
  • Crypto News
No Result
View All Result
NikolaNews
  • AI Development
    • Artificial Intelligence
    • Machine Learning
    • Neural Networks
    • Learn to Code
  • Data
    • Blockchain
    • Big Data
    • Data Science
  • IT Security
    • Internet Privacy
    • Internet Security
  • Marketing
    • Digital Marketing
    • Marketing Technology
  • Technology Companies
  • Crypto News
No Result
View All Result
NikolaNews
No Result
View All Result
Home Neural Networks

Face Recognition Library With Python

October 8, 2019
in Neural Networks
Face Recognition Library With Python
587
SHARES
3.3k
VIEWS
Share on FacebookShare on Twitter

The world’s simplest facial recognition API for Python and the command line.

Everyone is a value carrier with information that can be utilized to enhance your business and add an extra layer of security.

You might also like

Deploy AI models -Part 3 using Flask and Json | by RAVI SHEKHAR TIWARI | Feb, 2021

Labeling Service Case Study — Video Annotation — License Plate Recognition | by ByteBridge | Feb, 2021

5 Tech Trends Redefining the Home Buying Experience in 2021 | by Iflexion | Mar, 2021

Facial recognition software analyzes video streams and matches the results against previously stored images and information in your database, it can also analyze recorded footage for forensic use.

The nature of the information and its use is strictly up to you as an invaluable asset, also it can add quality or security to your daily operations.

Systems with facial recognition are very effective and have the added benefit of spotting tailgating. Facial recognition offers valuable benefits for casinos, banks, stadiums, corporate buildings, airports, and high-end retail stores to name a few.

Image by teguhjati pras from Pixabay

In this article, we are going to see how to use the face recognition library in python.

So first face recognition is a python library that builds on top of many libraries like Dlib library which is a modern C++ toolkit containing machine learning algorithms and tools for creating complex software in C++ and other machine learning algorithms.

Working with face recognition library

In my case, I prefer using Pycharm for creating python codes, if you don’t know what is Pycharm or how to install it. well, watch this video:

Install Pycharm on Windows:

Install Pycharm on Linux:

Now you need to install the face recognition library on Pycharm, this is the documentation of this tool on Github here and the PyPI documentation here.

If you don’t know how to install a python library on Pycharm, watch this video:

Enough talking, let’s jump to the code.

Find faces in pictures

Before we start coding you can download all the code and pictures here.

First, create a python file on Pycharm called Face_Recognition or whatever you want, I found this name suitable.

The first program that we are going to create a code that gives you all the faces that appear in a picture.

The first line in code as shown in the image above imports the face recognition library.

import face recognition

Then after that, we create a variable called image and set that variable to the library face_recognition and there is a method called load_image_file so here we are going to pass the image that we want to find all the faces within it.

image = face_recognition.load_image_file("path_of_image")

Now after that, we create another variable called face_locations and set that variable to the library face_recognition and there is a method called face_locations that will find all the faces in that image.

Don’t forget to pass to it the image variable that we have created earlier.

face_locations = face_recognition.face_locations(image)

So it knows what is the image that you wanna find faces within it, and this method will return an array of coordinates for each face and we can print that out if you want.

print(face_locations)

As you see at the image above, the code has return four parentheses every one refer to one person and it has four values (top, right, bottom, left)

Count how many peoples within an image

The code above is the same code that we have discussed earlier except just add to it this following line:

print(“There are {} faces in the image”.format(len(face_locations)))

So we count how many people by counting the length of the variable face_locations, and you can see that the python code has print:

There are 4 people in the image

Recognize who is in the picture

First, we import the face recognition library, then we create a variable called image_of_obama and we set that variable to face_recognition and then we load the image of Obama.

import face_recognition
image_of_obama = face_recognition.load_image_file("path")

In the next line, we need to extract the landmarks or the face encoding so then we can compare it with the other faces.

obama_face_encoding = face_recognition.face_encodings(image_of_obama)[0]

The face encoding algorithm will return an array of numbers that represent the landmarks of the face.

Don’t forget to pass it the image_of_obama variable to the face_encodings algorithm.

Next, we repeat the process with another image so we create a variable called unknown_image and we load the image in this variable, then we create another variable called unknown_face_encoding and we also find the landmarks of that unknown image.

unknown_image = face_recognition.load_image_file(path)
unknown_face_encoding = face_recognition.face_encodings(unknown_image)[0]

Now, we need to compare the faces and find if there is a match or not at a particular image.

Go ahead and create a variable called result and set it to this function face_recognition.compre_faces and pass in the first argument the obama_face_encoding in curly brackets and the second argument pass the unknown_face_encoding variable this method will return true or false.

We can print that out if we want and as you can see the result shows True because it found a match in the two images and I have feed it two images of Obama’s faces.

result = face_recognition.compare_faces([obama_face_encoding], unknown_face_encoding)
print(result[0])

Now change the image in unknown_image with other person and see what you will get, as you can see in the image below with a picture of Donald Trump it returns False

Pull the faces within an image

The first thing to do here is we import the dependencies which are:

from PIL import Image
import face_recognition

As usual, we load the image and we find the faces with the face_locations method.

image = face_recognition.load_image_file(path)
face_locations = face_recognition.face_locations(image)

Then we loop through the faces with this code:

for face_location in face_locations

Then we determine the faces locations with :

top, right, bottom, left = face_location

After that, we pull the faces with:

pil_image = image[top:bottom, left:right]

Now, we need to convert the images to a format that the PIL library can recognize it with the following code:

face_image = Image.fromarray(face_image)

Then we need to show the images with the following code:

pil_image.show()

You can save the images to your computer by typing the following code:

pil_image.save(“{}.jpg”.format(top))

So we name every person picture with the top value as you see in the image below.

That was a brief introduction to the face recognition library in python you can check out the documentation here for more details.

Credit: BecomingHuman By: Abdelhakim Ouafi

Previous Post

A 7-Step Guide to Creating a Marketing Plan

Next Post

The Machine Learning Master Class Bundle Can Be Yours For Just $39 If You Avail This Deal On Time

Related Posts

Deploy AI models -Part 3 using Flask and Json | by RAVI SHEKHAR TIWARI | Feb, 2021
Neural Networks

Deploy AI models -Part 3 using Flask and Json | by RAVI SHEKHAR TIWARI | Feb, 2021

March 6, 2021
Labeling Service Case Study — Video Annotation — License Plate Recognition | by ByteBridge | Feb, 2021
Neural Networks

Labeling Service Case Study — Video Annotation — License Plate Recognition | by ByteBridge | Feb, 2021

March 6, 2021
5 Tech Trends Redefining the Home Buying Experience in 2021 | by Iflexion | Mar, 2021
Neural Networks

5 Tech Trends Redefining the Home Buying Experience in 2021 | by Iflexion | Mar, 2021

March 6, 2021
Labeling Case Study — Agriculture— Pigs’ Productivity, Behavior, and Welfare Image Labeling | by ByteBridge | Feb, 2021
Neural Networks

Labeling Case Study — Agriculture— Pigs’ Productivity, Behavior, and Welfare Image Labeling | by ByteBridge | Feb, 2021

March 5, 2021
8 concepts you must know in the field of Artificial Intelligence | by Diana Diaz Castro | Feb, 2021
Neural Networks

8 concepts you must know in the field of Artificial Intelligence | by Diana Diaz Castro | Feb, 2021

March 5, 2021
Next Post
How Machine Learning is Changing the World

The Machine Learning Master Class Bundle Can Be Yours For Just $39 If You Avail This Deal On Time

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recommended

Plasticity in Deep Learning: Dynamic Adaptations for AI Self-Driving Cars

Plasticity in Deep Learning: Dynamic Adaptations for AI Self-Driving Cars

January 6, 2019
Microsoft, Google Use Artificial Intelligence to Fight Hackers

Microsoft, Google Use Artificial Intelligence to Fight Hackers

January 6, 2019

Categories

  • Artificial Intelligence
  • Big Data
  • Blockchain
  • Crypto News
  • Data Science
  • Digital Marketing
  • Internet Privacy
  • Internet Security
  • Learn to Code
  • Machine Learning
  • Marketing Technology
  • Neural Networks
  • Technology Companies

Don't miss it

Video Highlights: Deep Learning for Probabilistic Time Series Forecasting
Machine Learning

Video Highlights: Deep Learning for Probabilistic Time Series Forecasting

March 7, 2021
Machine Learning Market Expansion Projected to Gain an Uptick During 2021-2027
Machine Learning

Machine Learning Market Expansion Projected to Gain an Uptick During 2021-2027

March 7, 2021
Maza Russian cybercriminal forum suffers data breach
Internet Security

Maza Russian cybercriminal forum suffers data breach

March 7, 2021
Clinical presentation of COVID-19 – a model derived by a machine learning algorithm
Machine Learning

Clinical presentation of COVID-19 – a model derived by a machine learning algorithm

March 7, 2021
Okta and Auth0: A $6.5 billion bet that identity will warrant its own cloud
Internet Security

Okta and Auth0: A $6.5 billion bet that identity will warrant its own cloud

March 7, 2021
Researchers at Utrecht University Develop an Open-Source Machine Learning (ML) Framework Called ASReview to Help Researchers Carry Out Systematic Reviews
Machine Learning

Researchers at Utrecht University Develop an Open-Source Machine Learning (ML) Framework Called ASReview to Help Researchers Carry Out Systematic Reviews

March 7, 2021
NikolaNews

NikolaNews.com is an online News Portal which aims to share news about blockchain, AI, Big Data, and Data Privacy and more!

What’s New Here?

  • Video Highlights: Deep Learning for Probabilistic Time Series Forecasting March 7, 2021
  • Machine Learning Market Expansion Projected to Gain an Uptick During 2021-2027 March 7, 2021
  • Maza Russian cybercriminal forum suffers data breach March 7, 2021
  • Clinical presentation of COVID-19 – a model derived by a machine learning algorithm March 7, 2021

Subscribe to get more!

© 2019 NikolaNews.com - Global Tech Updates

No Result
View All Result
  • AI Development
    • Artificial Intelligence
    • Machine Learning
    • Neural Networks
    • Learn to Code
  • Data
    • Blockchain
    • Big Data
    • Data Science
  • IT Security
    • Internet Privacy
    • Internet Security
  • Marketing
    • Digital Marketing
    • Marketing Technology
  • Technology Companies
  • Crypto News

© 2019 NikolaNews.com - Global Tech Updates