Home > other >  For face recognition using the go live
For face recognition using the go live

Time:09-16

Apply to a people
1.1 apply to don't understand face recognition algorithm of classmate
1.2 projects need facial recognition
1.3 this speaks of from the server API call human face, the front is not limited to PC, mobile devices such as
1.4 this registration complete human face, human face, human face to delete, living, and dealing with face returned data
1.5 use baidu ai QPS to collect fees, free bring 2, basic can meet the demand of the general project

Second, ready to work
2.1 log on to https://console.bce.baidu.com/, after the success of the login to see the following interface, click on the face recognition


2.2 create application, fill in relevant information




2.3 after creating an get we need to call API ApiKey and SecretKey, create good click management application can see

Three, the development of interface
Development considerations: this interface calls using the go gin framework to complete human face


3.1 create a face structure used to get token

The type Face struct {
Refresh_token string
Expires_in int
The Scope string
Session_key string
Access_token string
Session_secret string
}


Here can be used to just two fields
Access_token: to get the Access Token
Expires_in: the validity of the Access Token (seconds, usually for a month)

Create a go script, we started for the first step in the operation, access token and store down

Func GetFaceToken () Face {
_face: Face={}
Resp, err:=HTTP. PostForm (" https://aip.baidubce.com/oauth/2.0/token ",
Url. Values {" grant_type ": {}" client_credentials ", "client_id" : {} "API Key", "client_secret" : {" Secret Key "}})

Defer resp. Body. The Close ()
If (err!=nil) {
FMT. Print (err)
} else {
Body, _ :=ioutil ReadAll (resp. Body)
Json. The Unmarshal (byte [] (string (body), & amp; _face)

}
Return _face
}
Write to create your own application in apiKey and secretKey when two content
3.2 create FaceState after calling the API structure stored data returned by the

Type FaceState struct {
Error_code int
Error_msg string
Log_id int
Timestamp int
Cached int
Result the Result
}

1. Successful Error_code call and parameters correctly returns 0
2. The error code of https://cloud.baidu.com/doc/FACE/s/5k37c1ujz
3. Error_msg error feedback
4. The Result face return data, token, and user list
Type the Result struct {
Face_token string
User_list [] UserList
}
5. The UserList user information list

Type the UserList struct {
Group_id string
User_id string
User_info string
Score the string
}

1. Group_id: user belongs group_id
2. User_id user_id: user
3. Carry user_info: when registered users user_info
4. The score: user matching score 80 points can be judged for the same person, the corresponding one over ten thousand course score rate


3.3 face registered interface

Func AddFaceImage (Imager string, the user user) FaceState {
_face:=GetFaceToken ()
_faceState: FaceState={}

Resp, err:=HTTP. PostForm (" https://aip.baidubce.com/rest/2.0/face/v3/faceset/user/add? Access_token="+ _face access_token, url. Values {" image" : {Imager}, "image_type" : {} "BASE64", "group_id" : {} "Admin", "user_id" : {user. Userid}, "user_info" : {user. Fullname}, "quality_control" : {} "NONE", "liveness_control" : {" NONE "}})
Defer resp. Body. The Close ()


Full contents see https://articles.zsxq.com/id_veqpo7oo1738.html

CodePudding user response:

Ask a question,
How can structure in the User_list empty array?
This kind of case result [] * result
For [] user_list how value is empty,
  • Related