Demo Project of Distortion Correction
This demo project corresponds to the POST /v1.0/moderation/image/distortion-correct URI. Replace the AK/SK information with the actual AK/SK to run the demo.
Sample Code
- Configure the AK/SK in the ModerationDistortionCorrectDemo.java file.
1 2 3 4 5 6 7 8 9
// 1. Configure the basic information for accessing Distortion Correction and generate a client connection object. AisAccess service = ServiceAccessBuilder.builder() .ak("######") // your ak .sk("######") // your sk .region("cn-north-1") // Configuration of Content Moderation in the CN North-Beijing1 (cn-north-1) 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 file path (data/moderation-demo-1.jpg) in the ModerationDistortionCorrectDemo.java file.
1 2 3 4 5 6
// // 2. Construct the parameters required for accessing Distortion Correction. // String uri = "/v1.0/moderation/image/distortion-correct"; byte[] fileData = FileUtils.readFileToByteArray(new File("data/moderation-demo-1.jpg")); String fileBase64Str = Base64.encodeBase64String(fileData);
- Specify the path for saving the corrected image, for example, data/moderation-distortion.corrected.jpg. The sample code example is as follows:
1 2 3 4 5 6 7 8
// 4. Check whether the API call is successful. If 200 is returned, the API call succeeds. Otherwise, it fails. if(ResponseProcessUtils.isRespondedOK(response)) { ResponseProcessUtils.processResponseWithImage(response, "data/moderation-distortion.corrected.jpg"); } else { // 5. Process the character stream returned by the service and output the recognition result. ResponseProcessUtils.processResponseStatus(response); ResponseProcessUtils.processResponse(response); }
- Execute the ModerationDistortionCorrectDemo.java file. If 200 is displayed on the console, the program is successfully executed. The recognition result is displayed on the console, as shown in Figure 1.
Last Article: Using Java SDK (Deprecated)
Next Article: Demo Project of Image Clarity Detect


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