Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The simplest face recognition project in history is on the GitHub trend list.

2025-01-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

Source | GitHub Trending

Collate | Freesia

Translator | TommyZihao

Produced | AI Technology Camp (ID: rgznai100)

[introduction] recently, a face recognition project called face_recognition has made its mark on the GitHub Trending trend list. From the opening source to the deadline, the number of Star of this project on Github has reached 26,500 and reached 7117. This paper mainly introduces the instructions and methods of the project, which is convenient for domestic developers to study and study.

Face_recognition claims to be the most powerful and simplest face recognition project in history. It is reported that the project, developed by software engineering developer and consultant Adam Geitgey, is powerful because it is not only based on the deep learning model in dlib, the industry-leading open source library of C++, but also the face data set produced by Labeled Faces in the Wild, which is produced by the University of Massachusetts Amherst in the United States. it contains more than 13000 facial images collected from the Internet, with an accuracy of 99.38%. In addition, the project is equipped with complete development documentation and application cases, especially the compatible raspberry pie system. The simple point is that operators can directly use Python and command-line tools to extract, recognize and manipulate faces.

At present, the description of the project has been translated into Chinese, and this article has been authorized by the translator (GitHub ID:TommyZihao) to quote the translation to briefly introduce the project.

As usual, we send you a link to the GitHub project:

Https://github.com/ageitgey/face_recognitio

Feature to find and locate all faces in the picture: import face_recognition

Image = face_recognition.load_image_file ("your_file.jpg")

Face_locations = face_recognition.face_locations (image)

two。 Identify face key points (including eyes, nose, mouth and chin)

Import face_recognition

Image = face_recognition.load_image_file ("your_file.jpg")

Face_landmarks_list = face_recognition.face_landmarks (image)

My face recognition project not only plays an important role in some key areas, but also has a digital make-up automatic makeup function that may cause "playfulness" (similar to Meitu).

3. Identify who is in the picture.

Import face_recognition

Known_image = face_recognition.load_image_file ("biden.jpg")

Unknown_image = face_recognition.load_image_file ("unknown.jpg")

Biden_encoding = face_recognition.face_encodings (known_image) [0]

Results = face_recognition.compare_faces ([biden_encoding], unknown_encoding)

4. With other Python libraries (such as opencv), the project can also implement real-time face detection. For more information, please see:

Https://github.com/ageitgey/face_recognition/blob/master/examples/facerec_from_webcam_faster.py

Installation

Environment configuration:

Python 3.3 + or Python 2.7macOS or LinuxWindows (not officially supported, but some great gods have figured out a way to run on Windows)

Installation methods for different operating systems:

1. Install this project on Mac or Linux:

Method 1:

First install dlib and related Python dependencies:

Https://gist.github.com/ageitgey/629d75c1baac34dfa5ca2a1928a7aeaf

Then install it through pip3 or the pip2 of Python 2 with the following code

Pip3 install face_recognition

If the installation is not successful, you can install it with the Ubuntu virtual machine, see this tutorial:

Https://medium.com/@ageitgey/try-deep-learning-in-python-now-with-a-fully-pre-configured-vm-1d97d4c3e9b

(need to install VMWare Player or VirtualBox on your computer)

Method 2:

Modify your pip image source to Tsinghua image, and then use pip install face_recognition to automatically install various dependencies, including dlib. It's just that there may be a problem when installing dlib, because dlib needs to be compiled, and the problem is usually the gcc or Gmail + version, so before pip install face_recognition, you can type on the command line

Export CC=/usr/local/bin/gcc

Export CXX=/usr/local/bin/g++

To specify the location of your gcc and Gmail + (these two sentences will temporarily modify the current terminal's environment variable / usr/local/bin/gcc corresponding to your own gcc or Gmail + directory).

two。 Install on raspberry pie:

Installation guide for raspberry pie:

Https://gist.github.com/ageitgey/1ac8dbe8572f3f533df6269dab35df65

3. Install on Windows: although the project does not officially support Windows, some great minds have figured out how to run the project on Windows: @ masoudr wrote a tutorial on how to install the dlib library and the face_recognition project on a Win10 system:

Https://github.com/ageitgey/face_recognition/issues/175#issue-257710508

Use the Ubuntu virtual machine image file to install and configure the virtual machine. This project is already included in this image.

Https://medium.com/@ageitgey/try-deep-learning-in-python-now-with-a-fully-pre-configured-vm-1d97d4c3e9b

Usage

1. Use the command line tool

After this project is installed, two command line tools are available:

Face_recognition-identify a person's face in a single picture or in a picture folder. Face_detection-locate the face in a single picture or in a picture folder.

Face_recognition command line tool:

The face_recognition command line tool can identify people's faces in a single picture or in a picture folder. First of all, you need a folder of face pictures that you already know the name, one picture for each person, and the file name of the picture is the name of the corresponding person. Then, you need a second picture folder, which contains the pictures you want to identify:

Then, switch to the path of the two folders on the command line, use the face_recognition command line, pass in the two picture folders, and then output the names of the people in the unknown pictures:

$face_recognition. / pictures_of_people_i_know/. / unknown_pictures/

/ unknown_pictures/unknown.jpg,Barack Obama

/ face_recognition_test/unknown_pictures/unknown.jpg,unknown_person

Each line of the output corresponds to a face in the picture, and the picture name and the corresponding face recognition result are separated by a comma.

If the result outputs unknown_person, it means that the face does not correspond to anyone in the known face picture folder.

Face_detection command line tool

The face_detection command line tool can locate the human face (output pixel coordinates) in a single image or in a picture folder. Use face_detection on the command line and pass in an image folder or a single image file for face location detection:

$face_detection. / folder_with_pictures/

Examples/image1.jpg,65215169112

Examples/image2.jpg,62394211244

Examples/image2.jpg,95941244792

Each line of the output corresponds to a face in the picture, and the output coordinates represent the top, right, bottom, and left pixel coordinates of the face.

Adjust the fault tolerance and sensitivity of face recognition

If a face recognizes more than one result, it means he looks too much like others (in addition, the project's face recognition accuracy for children and Asians needs to be improved). You can lower the fault tolerance rate to make the recognition result more strict. This function can be achieved by passing in the parameter-tolerance. The default fault tolerance rate is 0.6. the lower the fault tolerance rate, the more rigorous and accurate the identification.

$face_recognition-- tolerance 0.54. / pictures_of_people_i_know/. / unknown_pictures/

/ unknown_pictures/unknown.jpg,Barack Obama

/ face_recognition_test/unknown_pictures/unknown.jpg,unknown_person

The specific value of face matching can be viewed by passing the parameter-show-distance true.

$face_recognition-- show-distance true. / pictures_of_people_i_know/. / unknown_pictures/

/ unknown_pictures/unknown.jpg,Barack Obama,0.378542298956785

/ face_recognition_test/unknown_pictures/unknown.jpg,unknown_person,None

What if I am not satisfied with the recognition speed?

If your CPU is multicore, you can speed up face recognition through parallel computing. For example, if your CPU has four cores, you can increase your computing speed by about four times through parallel computing.

If you use Python3.4 or newer version, you can pass in the-- cpus parameter:

$face_recognition-- cpus 4. / pictures_of_people_i_know/. / unknown_pictures/

(you can call all the cores of cpu by passing in the-- cpus-1 parameter. In addition, Zihao brother Tommy said that raspberry pie 3B has four CPU cores, and the introduction of multi-core parameters can significantly improve the speed of image recognition.

More cases

If you don't care about the file name of the picture and just want to know who is in the picture in the folder, you can use this pipe command:

$face_recognition. / pictures_of_people_i_know/. / unknown_pictures/ | cut-d','- f2

Barack Obama

Unknown_person

two。 Use Python

Import face_recognition module in Python, call rich API interface, and you can easily play with various face recognition functions with a few lines of code! API API documentation:

Https://face-recognition.readthedocs.io

How to locate the face or recognize the identity of other people's faces?

In Python, you can use the following code to locate the face in the picture.

Import face_recognition

Image = face_recognition.load_image_file ("my_picture.jpg")

Face_locations = face_recognition.face_locations (image)

# face_locations is now an array listing the co-ordinates of each face

Reference case:

Https://github.com/ageitgey/face_recognition/blob/master/examples/find_faces_in_picture.py

Recognize other people's faces in the picture

Import face_recognition

Picture_of_me = face_recognition.load_image_file ("me.jpg")

My_face_encoding = face_recognition.face_encodings (picture_of_me) [0]

# my_face_encoding now contains a universal 'encoding' of my facial features that can be compared to any other picture of a face!

Unknown_picture = face_recognition.load_image_file ("unknown.jpg")

Unknown_face_encoding = face_recognition.face_encodings (unknown_picture) [0]

# Now we can see the two face encodings are of the same person with `compare_ faces`!

Results = face_recognition.compare_faces ([my_face_encoding], unknown_face_encoding)

If results [0] = = True:

Print ("It's a picture of me!")

Else:

Print ("It's not a picture of"

Reference case:

Https://github.com/ageitgey/face_recognition/blob/master/examples/recognize_faces_in_pictures.py

What if there are precise requirements for face recognition?

You can use a deep learning model to achieve more accurate face location, but note: this method requires GPU acceleration (through the CUDA library driver of the Nvidia graphics card), and CUDA support needs to be enabled when compiling and installing dlib.

Import face_recognition

Image = face_recognition.load_image_file ("my_picture.jpg")

Face_locations = face_recognition.face_locations (image, model= "cnn")

# face_locations is now an array listing the co-ordinates of each face

Reference case:

Https://github.com/ageitgey/face_recognition/blob/master/examples/find_faces_in_picture_cnn.py

If you have a large number of images to identify and GPU at the same time, you can refer to this example:

Https://github.com/ageitgey/face_recognition/blob/master/examples/find_faces_in_batches.py

How to identify the key points of a face in a single picture?

Import face_recognition

Image = face_recognition.load_image_file ("my_picture.jpg")

Face_landmarks_list = face_recognition.face_landmarks (image)

# face_landmarks_list is now an array with the locations of each facial feature in each face.

# face_landmarks_list [0] ['left_eye'] would be the location and outline of the first person's left eye

Reference case:

Https://github.com/ageitgey/face_recognition/blob/master/examples/find_facial_features_in_picture.py

Identify the key points of Obama and Biden's faces

More cases:

Https://github.com/ageitgey/face_recognition/tree/master/examples

Face location

Case: locate Biden's face

Https://github.com/ageitgey/face_recognition/blob/master/examples/find_faces_in_picture_cnn.py

Case: using convolution neural network deep learning model to locate Biden's face

Https://github.com/ageitgey/face_recognition/blob/master/examples/find_faces_in_picture_cnn.py

Case: batch recognition of faces in pictures using convolution neural network deep learning model

Https://github.com/ageitgey/face_recognition/blob/master/examples/find_faces_in_batches.py

Case: Gaussian blur of faces from webcam videos (need to install OpenCV)

Https://github.com/ageitgey/face_recognition/blob/master/examples/blur_faces_on_webcam.py

Face key point recognition

Case study: extracting facial key points of Obama and Biden

Https://github.com/ageitgey/face_recognition/blob/master/examples/find_facial_features_in_picture.py

Case study: putting makeup on US Vice President Joe Biden

Https://github.com/ageitgey/face_recognition/blob/master/examples/digital_makeup.py

Face recognition

Case: is it Obama or Biden?

Https://github.com/ageitgey/face_recognition/blob/master/examples/recognize_faces_in_pictures.py

Case: draw a frame and mark the name on the original image after face recognition

Https://github.com/ageitgey/face_recognition/blob/master/examples/identify_and_draw_boxes_on_faces.py

Case: compare whether two faces belong to one person in different precision

Https://github.com/ageitgey/face_recognition/blob/master/examples/face_distance.py

Case: get video from camera for face recognition-slower version (OpenCV is required)

Https://github.com/ageitgey/face_recognition/blob/master/examples/facerec_from_webcam.py

Case: get video from camera for face recognition-faster version (OpenCV is required)

Https://github.com/ageitgey/face_recognition/blob/master/examples/facerec_from_webcam_faster.py

Case: recognize someone's face from a video file and output the recognition result to a new video file (OpenCV needs to be installed)

Https://github.com/ageitgey/face_recognition/blob/master/examples/facerec_from_video_file.py

Case: face count and face identification through raspberry pie camera

Https://github.com/ageitgey/face_recognition/blob/master/examples/facerec_on_raspberry_pi.py

Case: visit the web server through the browser HTTP for face recognition (need to install Flask backend development framework)

Https://github.com/ageitgey/face_recognition/blob/master/examples/web_service_example.py

Case: face recognition based on K-nearest neighbor KNN classification algorithm

Https://github.com/ageitgey/face_recognition/blob/master/examples/face_recognition_knn.py

Articles and tutorials on face_recognition

An article written by the author of this project Modern Face Recognition with Deep Learning:

Https://medium.com/@ageitgey/machine-learning-is-fun-part-4-modern-face-recognition-with-deep-learning-c3cffc121d78

Main content: basic algorithm and principle Face recognition with OpenCV, Python, and deep learning by Adrian Rosebrock:

Https://www.pyimagesearch.com/2018/06/18/face-recognition-with-opencv-python-and-deep-learning/

Main content: how to actually use the Raspberry Pi Face Recognition by Adrian Rosebrock of this project

Https://www.pyimagesearch.com/2018/06/25/raspberry-pi-face-recognition/

Main content: how to use this project Face clustering with Python by Adrian Rosebrock on raspberry pie

Https://www.pyimagesearch.com/2018/07/09/face-clustering-with-python/

Main content: using unsupervised learning algorithm to realize Gaussian blur of faces in pictures.

The principle of face recognition

If you want to learn more about the black box principle of face recognition, please read this article:

Https://medium.com/@ageitgey/machine-learning-is-fun-part-4-modern-face-recognition-with-deep-learning-c3cffc121d78

Warning description

The face recognition model of this project is based on adults and may have a general effect on children. If there is a child in the picture, it is recommended that the critical value be set to 0.6. The identification results of different races may be different. See the wiki encyclopedia page for more details.

Deploy this project on CVM (Heroku, AWS, etc.)

This project is based on the C++ library dlib, so it is wise to deploy the project on Heroku or AWS cloud servers.

To simplify this process, there is a Dockerfile case that teaches you how to package app developed by face_recognition into Docker container files, which you can deploy on all cloud services that support Docker images.

What happened to the moth?

If something goes wrong, check for common errors before Github submits the Issue.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report