Demo Project of Image Tagging
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/tagging URI. Replace the AK/SK information with the actual AK/SK to run the demo.
- Configure the AK/SK in the ImageTaggingDemo.java file. The sample code is as follows:
// 1. Configure the basic information for accessing Image Tagging 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 a local image or use the default image of the sample project, and modify the image path (data/image-tagging-demo-1.jpg) in the ImageTaggingDemo.java file.
// // 2. Construct the parameters required for accessing Image Tagging. // String uri = "/v1.0/image/tagging"; byte[] fileData = FileUtils.readFileToByteArray(new File("data/image-tagging-demo-1.jpg")); String fileBase64Str = Base64.encodeBase64String(fileData); - Execute the ImageTaggingDemo.java file. If 200 is displayed on the console, the program is successfully executed. The recognization result is shown in #image_04_0008/d0e652. Figure 1 Execution result
Last Article: Installing Eclipse and Importing SDK Projects
Next Article: Demo Project of Celebrity Recognition
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.