Article Directory
written in front
Because it is a bit boring to talk about the code directly, follow the personal style of doing things, first look at the overall effect, and then understand it in detail. This is similar to starting with appearance and being loyal to character. After introducing the functions in this chapter, interested students can gain an in-depth understanding through the code analysis in the next chapter. For the author, it can be regarded as the completion of a demo development of the basic function of face recognition.
1. Face registration
I found some well-known celebrities on the Internet, and saved photos with clear avatars. For face registration, you need to upload a photo of your avatar, enter the user ID and user information at the same time, and write 2 fields, because in real situations, there will be In the case of duplicate names, the user ID can be used as the only one, and the user information can be used as the name. Of course, it is also possible to make adjustments according to the needs. This is just an introduction.
The design logic is briefly mentioned. After the user uploads the picture, the picture data, user ID, and user information are taken as objects and sent to the back-end service. The back-end will acquire the feature points of the avatar. After the acquisition is successful, it will be saved.
2. Face update
After completing the faces that need to be entered, if you need to update the photos of the people in the library, you need to update the faces. The current logic of face updates is to use the user ID as the only check value to update other information, including users. Information and user's face photo.
3. Face deletion
According to the user ID in the library, delete the data that the user has registered with the face, including the picture data of the user's avatar stored in the background, so as to ensure that the server does not retain deleted useless data.
4. Face database query
The face database query uses a relatively rough method to check the top n data in the database, and other modules above have performed database query after the operation is completed, so the example diagram will not be shown here.
5. Face recognition
Next comes the most important face recognition module. We input a photo of a person, compare the photo with the user information in the face database, and return the user information with the highest similarity in the face database. If input The most important thing is the photos of people in the library, so the accuracy of finding the corresponding person will be relatively high. Generally, a similarity of more than 92% means that they are the same person. Of course, if you need to distinguish twins, the threshold will be higher. Here is just a brief mention. In a real engineering project, there are far more things to consider.
Below we upload a headshot of a person outside the face database for testing. You can see the result. The similarity between Hermione and Di Lieba is 87%. Although it is easy to distinguish from a human, the calculated similarity is not Low, it's really not the same person.
6. Extended Thinking
Although it looks like a system, in fact, there are many things that need to be considered for real engineering. Here are a few simple points. If there is time and necessity, I will introduce it later.
- Face database can be expanded
Only one library is used in the example, and all registration, update, deletion, and comparison are in the same library. In actual real scenarios, we can add different libraries, so that it can be used for the management of multiple libraries. For example, there are 8 buildings in the community, and each building has different owners, so the face information of each owner needs to be recorded in 8 different groups and verified separately, so that there will be no one building The owners of the 8 buildings can use face recognition to open the access control of the owners.
- Face recognition accuracy
This is the most important thing in face recognition. The model we use shape_predictor_68_face_landmarks.dat
is actually trained using foreign face data. It’s okay to do a demo. If you want to be really practical, you need a dedicated image engineer for data processing and models. For parameter adjustment/training, the robustness under different light conditions must also be considered, and the feature points may be more than this. Domestic face recognition is better done by Megvii, Yitu, BAT, etc., and they all have special images. The algorithm team is doing this.
- Face database search efficiency
In the example, after a photo is passed in, it will be compared with the avatar information of each user in the library to calculate the cosine similarity, and the time consumed is linear. If each calculation consumes 100ms, then if there are 100 users in the library , it takes 10 seconds, which is definitely unrealistic, and in a real environment, it is normal to have 1000 users or more, and it is impossible to use this linear method all the time. You can consider using Milvus and other similar vector databases to query top n, take out top n for calculation, and solve the problem of face search efficiency.