Demo Project of Celebrity Recognition
Two authentication methods, token authentication and AK/SK authentication, are available. This section uses AK/SK authentication as an example.
This demo project corresponds to the POST /v1.0/image/celebrity-recognition URI. Replace the AK/SK information with the actual AK/SK to run the demo.
- Configure the AK/SK in the CelebrityRecognitionDemo.java file. The sample code is as follows:
// 1. Configure the basic information for accessing Celebrity Recognition and generate a client connection object. AisAccess service = ServiceAccessBuilder.builder() .ak("######") // your ak .sk("######") // your sk .region("cn-north-1") // Configuration of Image Recognition in the CN North-Beijing1 region .connectionTimeout(5000) // Timeout limit for connecting to the target URL .connectionRequestTimeout(1000) // Timeout limit for obtaining available connections from the connection pool .socketTimeout(20000) // Timeout limit for obtaining server response data .build(); - Select an image of a political figure or Internet celebrity, and modify the image path (data/celebrity-recognition.jpg) in the CelebrityRecognitionDemo.java file.
// // 2. Construct the parameters required for accessing Celebrity Recognition. // String uri = "/v1.0/image/celebrity-recognition"; /** * TODO In this example, the image to be recognized can be placed in the data directory. Replace the name of the example image with the name of the image to be recognized. */ byte[] fileData = FileUtils.readFileToByteArray(new File("data/celebrity-recognition.jpg")); String fileBase64Str = Base64.encodeBase64String(fileData); - Execute the CelebrityRecognitionDemo.java file. If 200 is displayed on the console, the program is successfully executed. The recognition result is shown in Figure 1.
Last Article: Demo Project of Image Tagging
Next Article: Demo Project of Recapture Detection

Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.