In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
This document will use Jingdongyun AI SDK to practice the face search function in face recognition, which mainly involves group creation / deletion, group list acquisition, face creation / deletion, and face search. The final effect of this practice is to create a face database and search the one with the highest similarity in the face database to achieve face recognition of 1N. The operation diagram is as follows:
First, the preparatory work 1. Create AK/SK and log in to JD.com Cloud console: https://console.jdcloud.com, click the account AccessKey in the upper right corner to manage, and then click to create AccessKey 2 as shown. For the purchase of face search service, face search is billed by the number of API calls. Currently, there is a free trial of face search function for 0 CNY, and the call amount is limited to 13. We log in to JD.com Cloud console, click on the left navigation artificial intelligence-face recognition-face search, and click Buy now to complete the purchase operation. 3. After downloading SDK, return to the face search console. Click download SDK to complete the download operation of Jingdong Cloud AI SDK 4. Download Eclipse and install Eclipse download address: eclipse https://www.eclipse.org/downloads/ Magi eclipse installation method please own Baidu. Second, the beginning of practical operation. Open Eclipse for the new JAVA project, click File- New- Java Project, enter Project name as set in the following figure, and click Finish- Don't Create
Right-click the src directory in the JAVA project, and click new- Package
Next, we create Class related to grouping creation (faceGroupCreate) / deletion (faceGroupDelete), grouping list acquisition (getFaceGroupList), face creation (faceCreate) / deletion (faceDelete), and face search (faceSearch). The method to create a new Class is as follows:
After all the Class is created, it is shown below:
two。 Load Jingdongyun AI SDK to decompress our downloaded Jingdongyun AI SDK, and then copy it to the root directory of our new JAVA project.
Refresh the Package Explorer in Eclipse to see the copied Jingdong Cloud AI SDK files. Select all the jar package files, right-click, and click Build Path- Add to Build Path to rebuild the path (Build Path).
After rebuilding the path, we can see Referenced Libraries in the Package Explorer of Eclipse, which contains all the jar packages of our reconstructed path
3. Debug interface creation grouping (faceGroupCreate) enter the following in the faceGroupCreate class as debug code 1package facesearch
two
3import com.jdcloud.apigateway.signature.JdcloudSDKClient
4import com.jdcloud.sdk.utils.BinaryUtils
5import com.google.api.client.http.HttpResponse
6import java.io.IOException
7import java.util.HashMap
8import java.util.Map
nine
10import static com.jdcloud.sdk.http.Protocol.HTTP
eleven
12Universe / create grouping
13public class faceGroupCreate {
14 public static void main (String [] args) {
15 String accessKey = "Please enter your AK"
16 String secretKey = "Please enter your SK"
17 String endPoint = "aiapi.jdcloud.com"
18 String path = "/ jdai/faceGroupCreate"
19 String method = "POST"
20 Map headers = new HashMap ()
21 Map queryMap = new HashMap ()
22 / / queryMap.put ("groupId", "10")
23 queryMap.put ("groupName", "Please enter a group name")
24 queryMap.put ("groupInfo", "Please enter a group description")
25 String body = "\"\ "
26 try {
27 HttpResponse response = JdcloudSDKClient.execute (accessKey, secretKey, HTTP
28 endPoint, path, method, headers, queryMap, body)
29 System.out.println (new String (BinaryUtils.toByteArray (response.getContent ()
30} catch (IOException e) {
31 System.out.println (e.getMessage ())
32}
33}
34}
Right-click the code and click Run as- 1 Java Application to run the code.
After running, it is found that the error message is as follows (although an error has been reported here, the group whose name we defined is enter the grouping name has been created successfully:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder" .SLF4J: Defaulting to no-operation (NOP) logger implementationSLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
From this, we can see that the error is mainly reported in slf4j's jar package, and the Failed to load class "org.slf4j.impl.StaticLoggerBinder" in the fault code means that it failed to load the class file org.slf4j.impl.StaticLoggerBinder.
We can download slf4j-nop.jar and add it to build path just like adding AI SDK jar package. I have packaged the slf4j-nop.jarjar package and uploaded it to Jingdong Cloud COS. The download address is: https://pocenv-hcc.s3.cn-north-1.jdcloud-oss.com/slf4j-nop-1.7.28.jar, download the slf4j package and copy it to the Jingdong Cloud AI SDK folder, and then add it to the construction path in Eclipse.
Next, create other class files in turn.
Note: the part of the following code that involves String body = "imageBase64="; needs to convert the image to Base64 with the address of http://imgbase64.duoshitong.com/, and then copy the converted code to imageBase64= (the converted code needs to be removed from "data:image/jpeg;base64," and then copied). Delete grouping (`faceGroupDelete`) 1package facesearch
two
3import com.jdcloud.apigateway.signature.JdcloudSDKClient
4import com.jdcloud.sdk.utils.BinaryUtils
5import com.google.api.client.http.HttpResponse
6import java.io.IOException
7import java.util.HashMap
8import java.util.Map
nine
10import static com.jdcloud.sdk.http.Protocol.HTTP
eleven
12Universe / deletion grouping
13public class faceGroupDelete {
14 public static void main (String [] args) {
15 String accessKey = "Please enter your AK"
16 String secretKey = "Please enter your SK"
17 String endPoint = "aiapi.jdcloud.com"
18 String path = "/ jdai/faceGroupDelete"
19 String method = "POST"
20 Map headers = new HashMap ()
21 Map queryMap = new HashMap ()
22 / / queryMap.put ("groupId", "10")
23 queryMap.put ("groupName", "Please enter a group name")
24 String body = "{}"
25 try {
26 HttpResponse response = JdcloudSDKClient.execute (accessKey, secretKey, HTTP
27 endPoint, path, method, headers, queryMap, body)
28 System.out.println (new String (BinaryUtils.toByteArray (response.getContent ()
29} catch (IOException e) {
30 System.out.println (e.getMessage ())
31}
32}
33}
Group list acquisition (`getFaceGroupList`) 1package facesearch
two
3import com.jdcloud.apigateway.signature.JdcloudSDKClient
4import com.jdcloud.sdk.utils.BinaryUtils
5import com.google.api.client.http.HttpResponse
6import java.io.IOException
7import java.util.HashMap
8import java.util.Map
nine
10import static com.jdcloud.sdk.http.Protocol.HTTP
eleven
12Universe / get grouping list
13public class getFaceGroupList {
14 public static void main (String [] args) {
15 String accessKey = "Please enter your AK"
16 String secretKey = "Please enter your SK"
17 String endPoint = "aiapi.jdcloud.com"
18 String path = "/ jdai/getFaceGroupList"
19 String method = "POST"
20 Map headers = new HashMap ()
21 Map queryMap = new HashMap ()
22 queryMap.put ("start", "0")
23 queryMap.put ("length", "5")
24 String body = "aaa"
25 try {
26 HttpResponse response = JdcloudSDKClient.execute (accessKey, secretKey, HTTP
27 endPoint, path, method, headers, queryMap, body)
28 System.out.println (new String (BinaryUtils.toByteArray (response.getContent ()
29} catch (IOException e) {
30 System.out.println (e.getMessage ())
31}
32}
33}
Face creation (`faceCreate`) 1package facesearch
two
3import com.jdcloud.apigateway.signature.JdcloudSDKClient
4import com.jdcloud.sdk.utils.BinaryUtils
5import com.google.api.client.http.HttpResponse
6import java.io.IOException
7import java.util.HashMap
8import java.util.Map
nine
10import static com.jdcloud.sdk.http.Protocol.HTTP
eleven
12X / create a face
13public class faceCreate {
14 public static void main (String [] args) {
15 String accessKey = "Please enter your AK"
16 String secretKey = "Please enter your SK"
17 String endPoint = "aiapi.jdcloud.com"
18 String path = "/ jdai/faceCreate"
19 String method = "POST"
20 / / create
21 Map dataMap = new HashMap ()
22 / / online pictures are transferred to base64: http://imgbase64.duoshitong.com/
23 dataMap.put ("marin1", "code after imageBase64= image is converted to Base64 (remove the previous data:image/jpeg;base64,)")
24 dataMap.put ("marin2", "code after imageBase64= image is converted to Base64 (remove the previous data:image/jpeg;base64,)")
25 dataMap.put ("corona", "code after imageBase64= image is converted to Base64 (remove the previous data:image/jpeg;base64,)")
26 dataMap.put ("dog", "code after imageBase64= image is converted to Base64 (remove the previous data:image/jpeg;base64,)")
27 Map headers = new HashMap ()
28 Map queryMap = new HashMap ()
29 queryMap.put ("groupName", "Please enter a group name")
30 String body
31 for (Map.Entry entry: dataMap.entrySet ()) {
32 queryMap.put ("outerId", entry.getKey ())
33 body = entry.getValue ()
34 try {
35 HttpResponse response = JdcloudSDKClient.execute (accessKey, secretKey, HTTP
36 endPoint, path, method, headers, queryMap, body)
37 System.out.println (new String (BinaryUtils.toByteArray (response.getContent ()
38} catch (IOException e) {
39 System.out.println (e.getMessage ())
40}
41 queryMap.remove ("outerId")
42}
43}
44}
Face deletion (`faceDelete`) 1package facesearch
two
3import com.jdcloud.apigateway.signature.JdcloudSDKClient
4import com.jdcloud.sdk.utils.BinaryUtils
5import com.google.api.client.http.HttpResponse
6import java.io.IOException
7import java.util.HashMap
8import java.util.Map
nine
10import static com.jdcloud.sdk.http.Protocol.HTTP
eleven
12x / Delete face
13public class faceDelete {
14 public static void main (String [] args) {
15 String accessKey = "Please enter your AK"
16 String secretKey = "Please enter your SK"
17 String endPoint = "aiapi.jdcloud.com"
18 String path = "/ jdai/faceDelete"
19 String method = "POST"
20 Map headers = new HashMap ()
21 Map queryMap = new HashMap ()
22 queryMap.put ("groupName", "Please enter a group name")
23 queryMap.put ("outerId", "marin1")
24 queryMap.put ("outerId", "marin2")
25 queryMap.put ("outerId", "corona")
26 queryMap.put ("outerId", "dog")
27 String body = "{}"
28 try {
29 HttpResponse response = JdcloudSDKClient.execute (accessKey, secretKey, HTTP
30 endPoint, path, method, headers, queryMap, body)
31 System.out.println (new String (BinaryUtils.toByteArray (response.getContent ()
32} catch (IOException e) {
33 System.out.println (e.getMessage ())
34}
35}
36}
Face search (`faceSearch`) 1package facesearch
two
3import com.jdcloud.apigateway.signature.JdcloudSDKClient
4import com.jdcloud.sdk.utils.BinaryUtils
5import com.google.api.client.http.HttpResponse
6import java.io.IOException
7import java.util.HashMap
8import java.util.Map
nine
10import static com.jdcloud.sdk.http.Protocol.HTTP
eleven
12max / face search
13public class faceSearch {
14 public static void main (String [] args) {
15 String accessKey = "Please enter your AK"
16 String secretKey = "Please enter your SK"
17 String endPoint = "aiapi.jdcloud.com"
18 String path = "/ jdai/faceSearch"
19 String method = "POST"
20 Map headers = new HashMap ()
21 Map queryMap = new HashMap ()
22 queryMap.put ("groupName", "Please enter a group name")
23 / / fill in the third face Base64 code of the same person for face search. Here, face marin.jpg is used.
24 String body = "Code after the imageBase64= image is converted to Base64 (remove the previous data:image/jpeg;base64,)"
25 try {
26 HttpResponse response = JdcloudSDKClient.execute (accessKey, secretKey, HTTP
27 endPoint, path, method, headers, queryMap, body)
28 System.out.println (new String (BinaryUtils.toByteArray (response.getContent ()
29} catch (IOException e) {
30 System.out.println (e.getMessage ())
31}
32}
33}
4. To demonstrate the following demo, right-click the corresponding code to execute Run as- 1 Java Application to run the code to view the result of creating a grouping to run faceGroupCreate.java. The result is as follows: get the grouping list and run getFaceGroupList.java. The result is as follows: create a face database and run faceCreate.java. The result is as follows: face search runs faceSearch.java, and the result is as follows: delete face and run faceDelete.java. The result is as follows: delete the group and run faceGroupDelete.java, and the result is as follows:
As above, we created the face database through marin1.jpg, marin2.jpg, corona.jpg and dog.jpg, and finally searched out the marin1.jpg with the highest similarity through marin.jpg. At this point, the operation demonstration is over.
Click "Jingdongyun" to learn about the comparison of Jingdongyun faces.
Welcome to click "Jingdong Yun" to learn more wonderful content.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.