SDK overview

Updated at:

This topic introduces the SDKs for popular programming languages and provides usage examples.

SDK

The Optical Character Recognition (OCR) SDK encapsulates all APIs from the 2021-07-07 version. It authenticates callers using an AccessKey and automatically handles tasks like signature generation. This simplifies the development process, reduces errors, and improves code maintainability.

Alibaba Cloud Developer Center provides SDKs for popular programming languages, along with repository links, installation commands, and release notes. For more information, visit the Developer Center.

Prerequisites

  1. Enable service: First, sign up for or log in to your Alibaba Cloud account. Then, go to the Optical Character Recognition (OCR) console to enable the services you need. The Optical Character Recognition (OCR) product offers 10 types of OCR services. Each service must be enabled separately. No fees are incurred when you enable a service.

    Depending on the service you enable, you receive a monthly free quota of 200 calls or a one-time free quota of 50 calls. Each successful API call consumes one call from your free quota. After the free quota is used up, you are charged based on your usage.

  2. Obtain an access credential: You must obtain an AccessKey before you install and use the SDK.

    1. Hover over your account avatar in the upper-right corner of the console and click AccessKey.

    2. On the AccessKey page, view your AccessKey details.

      The AccessKey list includes columns such as AccessKey ID, Status, Creation Time, and Actions. In the Status column, you can check whether an AccessKey is enabled or disabled.

      If the AccessKey list is empty or contains no enabled AccessKeys, create an AccessKey.

    If you are using a RAM user for API calls, ensure the user has the AliyunOCRFullAccess permission. Otherwise, calls to the Alibaba Cloud Optical Character Recognition (OCR) service will fail.

Code examples

Note

This example shows how to integrate the SDK and call the unified recognition API to recognize text from an ID card. To recognize text from other types of documents, you only need to specify the image type using the Type parameter. You do not need to switch to a different API. For more information, see Details for the Type parameter.

Environment variables

Store your AccessKey in an environment variable to avoid hard-coding it in your code. This reduces the risk of credential leaks.

Windows

On Windows, you can configure environment variables using CMD, PowerShell, or the System Properties dialog box.

CMD

Permanent

This creates a permanent environment variable that is available in all new sessions for the current user.

  1. Run the following commands in CMD.

    # Replace <access_key_id> with your AccessKey ID and <access_key_secret> with your AccessKey Secret.
    setx ALIBABA_CLOUD_ACCESS_KEY_ID <access_key_id>
    setx ALIBABA_CLOUD_ACCESS_KEY_SECRET <access_key_secret>
  2. Open a new CMD window.

  3. In the new CMD window, run the following commands to verify the environment variables.

    echo %ALIBABA_CLOUD_ACCESS_KEY_ID%
    echo %ALIBABA_CLOUD_ACCESS_KEY_SECRET%

Temporary

To set a temporary environment variable for the current CMD session only, run the following commands.

# Replace <access_key_id> with your AccessKey ID and <ACCESS_KEY_SECRET> with your AccessKey Secret.
set ALIBABA_CLOUD_ACCESS_KEY_ID=<access_key_id>
set ALIBABA_CLOUD_ACCESS_KEY_SECRET=<access_key_secret>

You can run the following commands in the current session to verify that the environment variables are set.

echo %ALIBABA_CLOUD_ACCESS_KEY_ID%
echo %ALIBABA_CLOUD_ACCESS_KEY_SECRET%
PowerShell

Permanent

This creates a permanent environment variable that is available in all new sessions for the current user.

  1. Run the following commands in PowerShell.

    # Replace <access_key_id> with your AccessKey ID and <access_key_secret> with your AccessKey Secret.
    [Environment]::SetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_ID", "<access_key_id>", [EnvironmentVariableTarget]::User)
    [Environment]::SetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_SECRET", "<access_key_secret>", [EnvironmentVariableTarget]::User)
  2. Open a new PowerShell window.

  3. In the new PowerShell window, run the following commands to verify the environment variables.

    echo $env:ALIBABA_CLOUD_ACCESS_KEY_ID
    echo $env:ALIBABA_CLOUD_ACCESS_KEY_SECRET

Temporary

To set a temporary environment variable for the current session only, run the following commands in PowerShell.

# Replace <access_key_id> with your AccessKey ID and <access_key_secret> with your AccessKey Secret.
$env:ALIBABA_CLOUD_ACCESS_KEY_ID = "<access_key_id>"
$env:ALIBABA_CLOUD_ACCESS_KEY_SECRET = "<access_key_secret>"

You can run the following commands in the current session to verify that the environment variables are set.

echo $env:ALIBABA_CLOUD_ACCESS_KEY_ID
echo $env:ALIBABA_CLOUD_ACCESS_KEY_SECRET
System Properties
  • Right-click This PC and click Properties. In the Settings window that appears, click Advanced System Settings to open the System Properties window.

    Advanced System Settings is located in the Related settings section on the right side of the page.

  • On the Advanced tab of the System Properties window, click Environment Variables....

    The Environment Variables... button is at the bottom of this tab.

  • In the System variables section at the bottom, click New to open the New System Variable dialog box.

    Enter the Variable name(N) and Variable value(V), and then click OK to add the environment variable.

  • Create two new system variables. For the names, enter ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET. For the values, enter your <access_key_id> and <access_key_secret>, respectively.

After entering the information, click OK in all three windows to close them. The environment variables are now configured.

You can run the following commands in a terminal to verify that the environment variables are set.

echo %ALIBABA_CLOUD_ACCESS_KEY_ID%
echo %ALIBABA_CLOUD_ACCESS_KEY_SECRET%

macOS

Permanent

This creates a permanent environment variable that is available in all new sessions for the current user.

  1. Run the following command in the terminal to check your default shell type.

    echo $SHELL
  2. Follow the steps based on your default shell type.

    Zsh

    1. Run the following commands to append the environment variable settings to the ~/.zshrc file.

      # Replace <access_key_id> with your AccessKey ID and <access_key_secret> with your AccessKey Secret.
      echo "export ALIBABA_CLOUD_ACCESS_KEY_ID=<access_key_id>" >> ~/.zshrc
      echo "export ALIBABA_CLOUD_ACCESS_KEY_SECRET=<access_key_secret>" >> ~/.zshrc

      Alternatively, you can manually edit the ~/.zshrc file.

      Manual modification

      Run the following command to open the shell configuration file.

      nano ~/.zshrc

      Add the following content to the configuration file.

      # Replace <access_key_id> with your AccessKey ID and <access_key_secret> with your AccessKey Secret.
      export ALIBABA_CLOUD_ACCESS_KEY_ID=<access_key_id> 
      export ALIBABA_CLOUD_ACCESS_KEY_SECRET=<access_key_secret>

      In the nano editor, press Ctrl+X, then Y, and then Enter to save and close the file.

    2. Run the following command to apply the changes.

      source ~/.zshrc
    3. Open a new terminal window and run the following commands to verify the environment variables.

      echo $ALIBABA_CLOUD_ACCESS_KEY_ID
      echo $ALIBABA_CLOUD_ACCESS_KEY_SECRET

    Bash

    1. Run the following commands to append the environment variable settings to the ~/.bash_profile file.

      # Replace <access_key_id> with your AccessKey ID and <access_key_secret> with your AccessKey Secret.
      echo "export ALIBABA_CLOUD_ACCESS_KEY_ID=<access_key_id>" >> ~/.bash_profile
      echo "export ALIBABA_CLOUD_ACCESS_KEY_SECRET=<access_key_secret>" >> ~/.bash_profile

      Alternatively, you can manually edit the ~/.bash_profile file.

      Manual modification

      Run the following command to open the shell configuration file.

      nano ~/.bash_profile

      Add the following content to the configuration file.

      # Replace <access_key_id> with your AccessKey ID and <access_key_secret> with your AccessKey Secret.
      export ALIBABA_CLOUD_ACCESS_KEY_ID=<access_key_id> 
      export ALIBABA_CLOUD_ACCESS_KEY_SECRET=<access_key_secret>

      In the nano editor, press Ctrl+X, then Y, and then Enter to save and close the file.

    2. Run the following command to apply the changes.

      source ~/.bash_profile
    3. Open a new terminal window and run the following commands to verify the environment variables.

      echo $ALIBABA_CLOUD_ACCESS_KEY_ID
      echo $ALIBABA_CLOUD_ACCESS_KEY_SECRET
Temporary

To set a temporary environment variable for the current session only, follow these steps.

  1. Run the following commands.

    # Replace <access_key_id> with your AccessKey ID and <access_key_secret> with your AccessKey Secret.
    export ALIBABA_CLOUD_ACCESS_KEY_ID=<access_key_id> 
    export ALIBABA_CLOUD_ACCESS_KEY_SECRET=<access_key_secret>
  2. Run the following commands to verify the environment variables.

    echo $ALIBABA_CLOUD_ACCESS_KEY_ID
    echo $ALIBABA_CLOUD_ACCESS_KEY_SECRET

Linux

Permanent

This creates a permanent environment variable that is available in all new sessions for the current user.

  1. Run the following commands to append the environment variable settings to the ~/.bashrc file.

    # Replace <access_key_id> with your AccessKey ID and <access_key_secret> with your AccessKey Secret.
    echo "export ALIBABA_CLOUD_ACCESS_KEY_ID=<access_key_id>" >> ~/.bashrc
    echo "export ALIBABA_CLOUD_ACCESS_KEY_SECRET=<access_key_secret>" >> ~/.bashrc

    Alternatively, you can manually edit the ~/.bashrc file.

    Manual modification

    Run the following command to open the ~/.bashrc file.

    nano ~/.bashrc

    Add the following content to the configuration file.

    # Replace <access_key_id> with your AccessKey ID and <access_key_secret> with your AccessKey Secret.
    export ALIBABA_CLOUD_ACCESS_KEY_ID=<access_key_id> 
    export ALIBABA_CLOUD_ACCESS_KEY_SECRET=<access_key_secret>

    In the nano editor, press Ctrl+X, then Y, and then Enter to save and close the file.

  2. Run the following command to apply the changes.

    source ~/.bashrc
  3. Open a new terminal window and run the following commands to verify the environment variables.

    echo $ALIBABA_CLOUD_ACCESS_KEY_ID
    echo $ALIBABA_CLOUD_ACCESS_KEY_SECRET
Temporary

To set a temporary environment variable for the current session only, follow these steps.

  1. Run the following commands.

    # Replace <access_key_id> with your AccessKey ID and <access_key_secret> with your AccessKey Secret.
    export ALIBABA_CLOUD_ACCESS_KEY_ID=<access_key_id> 
    export ALIBABA_CLOUD_ACCESS_KEY_SECRET=<access_key_secret>
  2. Run the following commands to verify the environment variables.

    echo $ALIBABA_CLOUD_ACCESS_KEY_ID
    echo $ALIBABA_CLOUD_ACCESS_KEY_SECRET

Programming languages

Select your preferred language to call the Optical Character Recognition (OCR) API.

Java

Step 1: Configure Java environment

Java environment

Run the following command in your terminal to check if Java is installed:

java -version

Java 8 or later is required. Check the first line of the output to confirm your Java version. For example, the output openjdk version "16.0.1" 2021-04-20 indicates that the current Java version is 16. If Java is not installed or your version is earlier than 8, go to Java to download and install it.

SDK installation

For Maven projects, add the following dependency to your pom.xml file:

<dependency>
  <groupId>com.aliyun</groupId>
  <artifactId>ocr_api20210707</artifactId>
  <version>3.1.2</version>
</dependency>

Step 2: Call the OCR API

Run the following code to call the Optical Character Recognition (OCR) API:

import com.aliyun.ocr_api20210707.models.RecognizeAllTextResponse;
import com.aliyun.tea.*;
public class Sample {
    public static com.aliyun.ocr_api20210707.Client createClient() throws Exception {
        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
                // Required. Make sure the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is set.
                .setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
                // Required. Make sure the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is set.
                .setAccessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
        config.endpoint = "ocr-api.cn-hangzhou.aliyuncs.com";
        return new com.aliyun.ocr_api20210707.Client(config);
    }
    public static void main(String[] args_) throws Exception {
        java.util.List<String> args = java.util.Arrays.asList(args_);
        com.aliyun.ocr_api20210707.Client client = Sample.createClient();
        com.aliyun.ocr_api20210707.models.RecognizeAllTextRequest recognizeAllTextRequest = new com.aliyun.ocr_api20210707.models.RecognizeAllTextRequest()
                .setUrl("https://img.alicdn.com/tfs/TB1q5IeXAvoK1RjSZFNXXcxMVXa-483-307.jpg")
                .setType("IdCard");
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        try {
            RecognizeAllTextResponse resp = client.recognizeAllTextWithOptions(recognizeAllTextRequest, runtime);
            System.out.println(com.aliyun.teautil.Common.toJSONString(resp.body.data));
        } catch (TeaException error) {
            // For demonstration purposes only. In your project, handle exceptions carefully and do not ignore them.
            // Error message
            System.out.println(error.getMessage());
            // Diagnostic address
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        } catch (Exception _error) {
            TeaException error = new TeaException(_error.getMessage(), _error);
            // For demonstration purposes only. In your project, handle exceptions carefully and do not ignore them.
            // Error message
            System.out.println(error.getMessage());
            // Diagnostic address
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        }
    }
}

Click to view the result

{
	"height": 307,
	"subImageCount": 1,
	"subImages": [{
		"angle": 0,
		"kvInfo": {
			"data": {
				"address": "Honghui Famous Garden, Quxi Road, South Xizang Road, Shanghai",
				"ethnicity": "Han",
				"sex": "Female",
				"name": "Fang Dadai",
				"idNumber": "371002200610020000",
				"birthDate": "October 2, 2006"
			},
			"kvCount": 6,
			"kvDetails": {
				"address": {
					"keyName": "address",
					"keyConfidence": 100,
					"value": "Honghui Famous Garden, Quxi Road, South Xizang Road, Shanghai",
					"valueConfidence": 100,
					"valueAngle": 0
				},
				"ethnicity": {
					"keyName": "ethnicity",
					"keyConfidence": 100,
					"value": "Han",
					"valueConfidence": 100,
					"valueAngle": 0
				},
				"sex": {
					"keyName": "sex",
					"keyConfidence": 100,
					"value": "Female",
					"valueConfidence": 100,
					"valueAngle": 0
				},
				"name": {
					"keyName": "name",
					"keyConfidence": 100,
					"value": "Fang Dadai",
					"valueConfidence": 100,
					"valueAngle": 0
				},
				"idNumber": {
					"keyName": "idNumber",
					"keyConfidence": 100,
					"value": "371002200610020000",
					"valueConfidence": 100,
					"valueAngle": 0
				},
				"birthDate": {
					"keyName": "birthDate",
					"keyConfidence": 100,
					"value": "October 2, 2006",
					"valueConfidence": 100,
					"valueAngle": 0
				}
			}
		},
		"qualityInfo": {
			"isCopy": false
		},
		"subImageId": 0,
		"type": "ID card front"
	}],
	"width": 483
}

Python

Step 1: Configure Python environment
Python environment

Run the following command in your terminal to check if Python is installed:

# If the command fails, try running it again with python3 instead of python.
python -V

Python 3.0 or later is required. If Python is not installed or your version is older than 3.0, see Python for installation instructions.

Virtual environment (optional)

If Python is already installed, you can create a virtual environment to install the Optical Character Recognition (OCR) Python SDK. This helps avoid dependency conflicts with other projects.

  1. Create a virtual environment

    Run the following command to create a virtual environment named .venv:

    # If the command fails, try running it again with python3 instead of python.
    python -m venv .venv
  2. Activate the virtual environment

    On Windows, run the following command to activate the virtual environment:

    .venv\Scripts\activate

    On macOS or Linux, run the following command to activate the virtual environment:

    source .venv/bin/activate
SDK installation

Run the following command to install the Python SDK:

pip install alibabacloud_ocr_api20210707==3.1.2

Step 2: Call the OCR API

You can create a new Python file, name it hello_ocr.py, copy the following code into hello_ocr.py, and save it.

# -*- coding: utf-8 -*-
import os
import sys
from typing import List
from alibabacloud_ocr_api20210707.client import Client as ocr_api20210707Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_ocr_api20210707 import models as ocr_api_20210707_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient
class Sample:
    def __init__(self):
        pass
    @staticmethod
    def create_client() -> ocr_api20210707Client:
        config = open_api_models.Config(
            # Required. Make sure the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is set.
            access_key_id=os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'],
            # Required. Make sure the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is set.
            access_key_secret=os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET']
        )
        config.endpoint = f'ocr-api.cn-hangzhou.aliyuncs.com'
        return ocr_api20210707Client(config)
    @staticmethod
    def main(
        args: List[str],
    ) -> None:
        client = Sample.create_client()
        recognize_all_text_request = ocr_api_20210707_models.RecognizeAllTextRequest(
            url='https://img.alicdn.com/tfs/TB1q5IeXAvoK1RjSZFNXXcxMVXa-483-307.jpg',
            type='IdCard'
        )
        runtime = util_models.RuntimeOptions()
        try:
            resp = client.recognize_all_text_with_options(recognize_all_text_request, runtime)
            print(resp.body.data)
        except Exception as error:
            # For demonstration purposes only. In your project, handle exceptions carefully and do not ignore them.
            # Error message
            print(error.message)
            # Diagnostic address
            print(error.data.get("Recommend"))
            UtilClient.assert_as_string(error.message)
    @staticmethod
    async def main_async(
        args: List[str],
    ) -> None:
        client = Sample.create_client()
        recognize_all_text_request = ocr_api_20210707_models.RecognizeAllTextRequest(
            url='https://img.alicdn.com/tfs/TB1q5IeXAvoK1RjSZFNXXcxMVXa-483-307.jpg',
            type='IdCard'
        )
        runtime = util_models.RuntimeOptions()
        try:
            # The result of this asynchronous call is not printed. To see the output, assign the awaited result to a variable and print it.
            await client.recognize_all_text_with_options_async(recognize_all_text_request, runtime)
        except Exception as error:
            # For demonstration purposes only. In your project, handle exceptions carefully and do not ignore them.
            # Error message
            print(error.message)
            # Diagnostic address
            print(error.data.get("Recommend"))
            UtilClient.assert_as_string(error.message)
if __name__ == '__main__':
    Sample.main(sys.argv[1:])

Click to view the result

{
	'Height': 307,
	'SubImageCount': 1,
	'SubImages': [{
		'Angle': 0,
		'FigureInfo': {},
		'KvInfo': {
			'Data': {
				'address': 'Honghui Famous Garden, Quxi Road, South Xizang Road, Shanghai',
				'ethnicity': 'Han',
				'sex': 'Female',
				'name': 'Fang Dadai',
				'idNumber': '371002200610020000',
				'birthDate': 'October 2, 2006'
			},
			'KvCount': 6,
			'KvDetails': {
				'address': {
					'KeyName': 'address',
					'KeyConfidence': 100,
					'Value': 'Honghui Famous Garden, Quxi Road, South Xizang Road, Shanghai',
					'ValueConfidence': 100,
					'ValuePoints': [],
					'ValueAngle': 0
				},
				'ethnicity': {
					'KeyName': 'ethnicity',
					'KeyConfidence': 100,
					'Value': 'Han',
					'ValueConfidence': 100,
					'ValuePoints': [],
					'ValueAngle': 0
				},
				'sex': {
					'KeyName': 'sex',
					'KeyConfidence': 100,
					'Value': 'Female',
					'ValueConfidence': 100,
					'ValuePoints': [],
					'ValueAngle': 0
				},
				'name': {
					'KeyName': 'name',
					'KeyConfidence': 100,
					'Value': 'Fang Dadai',
					'ValueConfidence': 100,
					'ValuePoints': [],
					'ValueAngle': 0
				},
				'idNumber': {
					'KeyName': 'idNumber',
					'KeyConfidence': 100,
					'Value': '371002200610020000',
					'ValueConfidence': 100,
					'ValuePoints': [],
					'ValueAngle': 0
				},
				'birthDate': {
					'KeyName': 'birthDate',
					'KeyConfidence': 100,
					'Value': 'October 2, 2006',
					'ValueConfidence': 100,
					'ValuePoints': [],
					'ValueAngle': 0
				}
			}
		},
		'QualityInfo': {
			'IsCopy': False
		},
		'SubImageId': 0,
		'SubImagePoints': [],
		'Type': 'ID card front'
	}],
	'Width': 483
}

Go

Step 1: Configure Go environment
Go environment

Run the following command in your terminal to check if Go is installed:

go version

Go 1.10 or later is required. Check the first line of the output to confirm your Go version. For example, the output go version go1.22.2 indicates that the current Go version is 1.22.2. If Go is not installed or your version is earlier than 1.10, download and install it from Go.

SDK installation

Run the following command to install the Go SDK dependency:

go get github.com/alibabacloud-go/ocr-api-20210707/v3

Step 2: Call the OCR API

You can create a new Go file named hello_ocr.go, copy the following code into hello_ocr.go, and save the file.

package main
import (
	"encoding/json"
	"fmt"
	openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
	ocr_api20210707 "github.com/alibabacloud-go/ocr-api-20210707/v3/client"
	util "github.com/alibabacloud-go/tea-utils/v2/service"
	"github.com/alibabacloud-go/tea/tea"
	"os"
	"strings"
)
func CreateClient() (_result *ocr_api20210707.Client, _err error) {
	config := &openapi.Config{
		// Required. Make sure the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is set.
		AccessKeyId: tea.String(os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")),
		// Required. Make sure the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is set.
		AccessKeySecret: tea.String(os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")),
	}
	config.Endpoint = tea.String("ocr-api.cn-hangzhou.aliyuncs.com")
	_result = &ocr_api20210707.Client{}
	_result, _err = ocr_api20210707.NewClient(config)
	return _result, _err
}
func _main(args []*string) (_err error) {
	client, _err := CreateClient()
	if _err != nil {
		return _err
	}
	recognizeAllTextRequest := &ocr_api20210707.RecognizeAllTextRequest{
		Url:  tea.String("https://img.alicdn.com/tfs/TB1q5IeXAvoK1RjSZFNXXcxMVXa-483-307.jpg"),
		Type: tea.String("IdCard"),
	}
	runtime := &util.RuntimeOptions{}
	tryErr := func() (_e error) {
		defer func() {
			if r := tea.Recover(recover()); r != nil {
				_e = r
			}
		}()
		resp, _err := client.RecognizeAllTextWithOptions(recognizeAllTextRequest, runtime)
		if _err != nil {
			return _err
		}
		fmt.Println(resp.Body.Data)
		return nil
	}()
	if tryErr != nil {
		var error = &tea.SDKError{}
		if _t, ok := tryErr.(*tea.SDKError); ok {
			error = _t
		} else {
			error.Message = tea.String(tryErr.Error())
		}
		// For demonstration purposes only. In your project, handle exceptions carefully and do not ignore them.
		// Error message
		fmt.Println(tea.StringValue(error.Message))
		// Diagnostic address
		var data interface{}
		d := json.NewDecoder(strings.NewReader(tea.StringValue(error.Data)))
		d.Decode(&data)
		if m, ok := data.(map[string]interface{}); ok {
			recommend, _ := m["Recommend"]
			fmt.Println(recommend)
		}
		_, _err = util.AssertAsString(error.Message)
		if _err != nil {
			return _err
		}
	}
	return _err
}
func main() {
	err := _main(tea.StringSlice(os.Args[1:]))
	if err != nil {
		panic(err)
	}
}

Click to view the result

{
   "Height": 307,
   "SubImageCount": 1,
   "SubImages": [
      {
         "Angle": 0,
         "KvInfo": {
            "Data": {
               "address": "Honghui Famous Garden, Quxi Road, South Xizang Road, Shanghai",
               "birthDate": "October 2, 2006",
               "ethnicity": "Han",
               "idNumber": "371002200610020000",
               "name": "Fang Dadai",
               "sex": "Female"
            },
            "KvCount": 6,
            "KvDetails": {
               "address": {
                  "KeyName": "address",
                  "KeyConfidence": 100,
                  "Value": "Honghui Famous Garden, Quxi Road, South Xizang Road, Shanghai",
                  "ValueConfidence": 100,
                  "ValueAngle": 0
               },
               "birthDate": {
                  "KeyName": "birthDate",
                  "KeyConfidence": 100,
                  "Value": "October 2, 2006",
                  "ValueConfidence": 100,
                  "ValueAngle": 0
               },
               "ethnicity": {
                  "KeyName": "ethnicity",
                  "KeyConfidence": 100,
                  "Value": "Han",
                  "ValueConfidence": 100,
                  "ValueAngle": 0
               },
               "idNumber": {
                  "KeyName": "idNumber",
                  "KeyConfidence": 100,
                  "Value": "371002200610020000",
                  "ValueConfidence": 100,
                  "ValueAngle": 0
               },
               "name": {
                  "KeyName": "name",
                  "KeyConfidence": 100,
                  "Value": "Fang Dadai",
                  "ValueConfidence": 100,
                  "ValueAngle": 0
               },
               "sex": {
                  "KeyName": "sex",
                  "KeyConfidence": 100,
                  "Value": "Female",
                  "ValueConfidence": 100,
                  "ValueAngle": 0
               }
            }
         },
         "QualityInfo": {
            "IsCopy": false
         },
         "SubImageId": 0,
         "Type": "ID card front"
      }
   ],
   "Width": 483
}