All right, guys, I’m back. Say I drag more don’t write an article can come over with your small fist hard life beat my chest….

So today we will talk about using python+opencv+face++ to implement face authentication and face unlock. It’s also a small amount of code, and you can apply that code to other areas of intelligence, like smart homes, where you know who you are when you walk in the door, and you can add machine learning to determine whether that person is a guest or an acquaintance. Before we do that, we’re going to do a proper topology on face recognition. OK, let’s cut to the chase.

Unlocking principle:

The principle, of course, is simple, not that complicated (except for the official language). We first say the use of Face++ to achieve the principle of face matching. Recommend a place to learn and communicate: 719+139+688, now you open the camera, and then you happen to press grab. Once captured, your face image is uploaded to a remote server, which then takes your face and generates a unique fingerprint (id). This fingerprint is called face_token in Face++, which we’ll talk about later, and this fingerprint represents your current identity.

After the upload is analyzed and collected by the server, the server will send you a packet through JSON, which contains all the features of your face.

When you get the JSON returned from the server, extract the face_token (this is important, the face_token is like a key) and then put the face_token in Python’s if to determine if the face_token matches and the validation succeeds. If they do not match, the unlock fails.

Environment topology:

Operating system: windows7

Python version: python2.7

OpenCV version: 2.x

Face++ interface

Implementation scheme:

1. After uploading the face (we have realized camera capture in the previous article, we will directly use a face picture instead of being verbose in this article), the FACE fingerprint (face_token) will be returned after uploading json.

2. Create a face set and add the Face_token returned in Step 1 to the set

3. Check whether the current face is included by using Python’s if function

Code part:

1. Get face_token:

Here are some highlights of the request:

The API says post, so request.post() is used instead.

The content transferred is the requested URL, image path (mandatory! It can be a local absolute path, or a network image. It can be image_file, image_URL, or data.

Apikey/APISECRET Mandatory Apply by yourself

The return_Attributes TAB has the data to return, age, gender, and so on

Return_landmark Indicates whether to detect. 0 indicates that the key points are not returned. 1 indicates that 83 key points are detected

Operation effect:

Let’s find a random photo (remember if you have a requirement for pixels, some of them may be wrong)

We can see that there are many values in the returned JSON package. The most important thing is to get the face_toen of the face and save it for inclusion on the server.

Note: here may be some friends on the Internet to find photos may be wrong, this is likely to be the picture pixel problem, try to find hd, after running, the face part will be marked by green box.

2. Create a face set and add the face_token

Face_tokens = Face_tokens = President Obama tokens = Face_tokens

I want to remember the name of the face set as well, because I’ll be looking it up later.

Add the Face_token obtained in the previous section to a new face set.

The next face comparison will be directly with the server collected fingerprint comparison. Payload = payload payload = payload

Display_name: The name of the face collection

Outer_id: indicates the FaceSet global user-defined id

Force_merge:

0: Do not add Face_tokens to existing FaceSet, return FACESET_EXIST error

1: Add Face_tokens to existing FaceSet

Face_tokens: Incoming face identifiers

Operation effect:

When it’s done, it will return a faceset_token, which we need to record, because we have uploaded our Obama facetoken to the set we created on the server. This faceset token is our faceset id or a photo album.

3. Check whether you are an administrator:

We put Obama’s Face token into python’s if, and set the set of faces we are going to query to be the faceset tokens we obtained earlier. Then we will take a photo and match it.

Laptop camera is too low, it is difficult to identify, just to see the effect, direct face recognition is also ok.

Complete the ~

Of course, there should be trolls by now, and it’s not safe to use pictures to unlock it, but if you want to go a little further, you can always add a little head-shaking and winking and all that crap.