Help Center> Image Recognition> SDK Reference> Using Java SDK> Demo Project of Super Resolution

Demo Project of Super Resolution

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/vision/super-resolution URI. Replace the AK/SK information with the actual AK/SK to run the demo.

  1. Configure the AK/SK in the SuperResolutionDemo file. The sample code is as follows:

    // 1. Configure the basic information for accessing Super Resolution 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();

  2. Select a local image or use the default image of the sample project, and modify the original image path (data/super-resolution-demo-1.png) and the path for saving the image generated after processing (data/super-resolution-demo-1.cooked.png) in the SuperResolutionDemo.java file.

    //
    // 2. Construct the parameters required for accessing Super Resolution.
    //
    String uri = "/v1.0/vision/super-resolution";
    byte[] fileData = FileUtils.readFileToByteArray(new File("data/super-resolution-demo-1.png"));
    String fileBase64Str = Base64.encodeBase64String(fileData);
    			
    JSONObject json = new JSONObject();
    json.put("image", fileBase64Str);
    json.put("scale", 3);
    json.put("model", "ESPCN");
    
    // 3. Pass the URI and required parameters of Super Resolution.
    // Pass the parameters in JSON objects and call the service using POST.
    HttpResponse response = service.post(uri, json.toJSONString());
    // 4. Check whether the API call is successful. If 200 is returned, the API call succeeds. Otherwise, it fails.
    ResponseProcessUtils.processResponseStatus(response);
    // 5. Process the character stream returned by the service and create the image file processed by Super Resolution.
    ResponseProcessUtils.processResponseWithImage(response, "data/super-resolution-demo-1.cooked.png");

  3. Execute the SuperResolutionDemo.java file. The recognition result is output. If 200 is displayed on the console, the program is successfully executed.

    Figure 1 shows the original image and reconstructed image.
    Figure 1 Comparison between the original image and reconstructed image