### Initialize OCR Client Source: https://context7.com/alibabacloud-go/ocr-api-20210707/llms.txt Create and configure the OCR client with your Alibaba Cloud credentials and target region. Ensure your Access Key ID and Secret are correctly set. ```go package main import ( "fmt" openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client" ocr "github.com/alibabacloud-go/ocr-api-20210707/v3/client" "github.com/alibabacloud-go/tea/tea" ) func createClient() (*ocr.Client, error) { config := &openapi.Config{ AccessKeyId: tea.String("YOUR_ACCESS_KEY_ID"), AccessKeySecret: tea.String("YOUR_ACCESS_KEY_SECRET"), // Endpoint for OCR API; omit to use automatic endpoint resolution Endpoint: tea.String("ocr-api.cn-hangzhou.aliyuncs.com"), } client, err := ocr.NewClient(config) if err != nil { return nil, fmt.Errorf("failed to create client: %w", err) } return client, nil } func main() { client, err := createClient() if err != nil { panic(err) } _ = client fmt.Println("Client initialized successfully") } ``` -------------------------------- ### Client Initialization Source: https://context7.com/alibabacloud-go/ocr-api-20210707/llms.txt Demonstrates how to create and configure an OCR client using your Alibaba Cloud credentials and the target region. ```APIDOC ## Client Initialization Create and configure the `Client` with your Alibaba Cloud credentials and target region before calling any API. ```go package main import ( "fmt" openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client" ocr "github.com/alibabacloud-go/ocr-api-20210707/v3/client" "github.com/alibabacloud-go/tea/tea" ) func createClient() (*ocr.Client, error) { config := &openapi.Config{ AccessKeyId: tea.String("YOUR_ACCESS_KEY_ID"), AccessKeySecret: tea.String("YOUR_ACCESS_KEY_SECRET"), // Endpoint for OCR API; omit to use automatic endpoint resolution Endpoint: tea.String("ocr-api.cn-hangzhou.aliyuncs.com"), } client, err := ocr.NewClient(config) if err != nil { return nil, fmt.Errorf("failed to create client: %w", err) } return client, nil } func main() { client, err := createClient() if err != nil { panic(err) } _ = client fmt.Println("Client initialized successfully") } ``` ``` -------------------------------- ### WithOptions Variant and RuntimeOptions Source: https://context7.com/alibabacloud-go/ocr-api-20210707/llms.txt Demonstrates how to use the `*WithOptions` variant of API calls to customize runtime behavior, such as setting timeouts, enabling retries, and configuring proxy settings. ```APIDOC ## WithOptions Variant and RuntimeOptions Every API has a `*WithOptions` variant for controlling timeout, retry, and proxy behavior at the call level. ### Parameters #### Request Body (for `RecognizeGeneralWithOptions`) - **Url** (string) - Required - The URL of the image to process. #### Runtime Options - **ConnectTimeout** (int) - Optional - Connection timeout in milliseconds. - **ReadTimeout** (int) - Optional - Read timeout in milliseconds. - **Autoretry** (bool) - Optional - Whether to enable automatic retries. - **MaxAttempts** (int) - Optional - The maximum number of retry attempts. ### Request Example ```go import util "github.com/alibabacloud-go/tea-utils/v2/service" runtime := &util.RuntimeOptions{ ConnectTimeout: tea.Int(5000), ReadTimeout: tea.Int(10000), Autoretry: tea.Bool(true), MaxAttempts: tea.Int(3), } req := &ocr.RecognizeGeneralRequest{ Url: tea.String("https://example.com/image.jpg"), } resp, err := client.RecognizeGeneralWithOptions(req, runtime) ``` ### Response Example ```json { "RequestId": "some-request-id", "Body": { "Data": "{\"text\": \"...\"}" } } ``` ``` -------------------------------- ### OCR API with Custom Runtime Options Source: https://context7.com/alibabacloud-go/ocr-api-20210707/llms.txt Utilize the `*WithOptions` variant of OCR API methods to control runtime behavior like connection timeout, read timeout, automatic retries, and maximum retry attempts. ```go import util "github.com/alibabacloud-go/tea-utils/v2/service" func recognizeWithCustomRuntime(client *ocr.Client) { runtime := &util.RuntimeOptions{ ConnectTimeout: tea.Int(5000), // 5 second connection timeout ReadTimeout: tea.Int(10000), // 10 second read timeout Autoretry: tea.Bool(true), MaxAttempts: tea.Int(3), } req := &ocr.RecognizeGeneralRequest{ Url: tea.String("https://example.com/image.jpg"), } resp, err := client.RecognizeGeneralWithOptions(req, runtime) if err != nil { fmt.Println("Error:", err) return } fmt.Println("Data:", tea.StringValue(resp.Body.Data)) } ``` -------------------------------- ### Recognize General OCR via File Stream Source: https://context7.com/alibabacloud-go/ocr-api-20210707/llms.txt Perform general OCR on an image by reading its binary content from a local file. Ensure the file path is correct and the file is properly closed after use. ```go // --- Option B: via local file stream --- f, err := os.Open("/path/to/image.jpg") if err != nil { panic(err) } defer f.Close() reqStream := &ocr.RecognizeGeneralRequest{Body: f} respStream, err := client.RecognizeGeneral(reqStream) if err != nil { fmt.Println("Error:", err) return } // Body.Data contains a JSON string with detected text blocks fmt.Println("Data:", tea.StringValue(respStream.Body.Data)) // Expected output (Data field is JSON): // {"content":"Hello World\nLine two","prism_wordsInfo":[{"word":"Hello World","x":10,"y":20,...},...]} ``` -------------------------------- ### Recognize Advanced OCR with Options Source: https://context7.com/alibabacloud-go/ocr-api-20210707/llms.txt Perform high-precision OCR with advanced features like table extraction, figure detection, and paragraph grouping. Configure options such as auto-rotation, multi-page sorting, and output details. ```go func recognizeAdvanced(client *ocr.Client) { req := &ocr.RecognizeAdvancedRequest{ Url: tea.String("https://img.alicdn.com/tfs/TB1Wo7eXAvoK1RjSZFDXXXY3pXa-2512-3509.jpg"), NeedRotate: tea.Bool(true), // auto-rotate skewed images NeedSortPage: tea.Bool(true), // sort multi-page PDFs OutputTable: tea.Bool(true), // include table structure in output OutputFigure: tea.Bool(true), // include figure regions OutputCharInfo: tea.Bool(false), // skip per-character bounding boxes NoStamp: tea.Bool(false), // do not remove stamps Paragraph: tea.Bool(true), // group lines into paragraphs Row: tea.Bool(false), } resp, err := client.RecognizeAdvanced(req) if err != nil { fmt.Println("Error:", err) return } fmt.Println("Code:", tea.StringValue(resp.Body.Code)) fmt.Println("Data:", tea.StringValue(resp.Body.Data)) // Data JSON includes "content", "prism_wordsInfo", "prism_tablesInfo", "prism_figuresInfo" ``` -------------------------------- ### Recognize Document Structure and General Structure Source: https://context7.com/alibabacloud-go/ocr-api-20210707/llms.txt Analyze document layout to extract structured key-value pairs and regions. `RecognizeGeneralStructure` supports image streams with advanced configurations. ```go func recognizeStructure(client *ocr.Client) { docReq := &ocr.RecognizeDocumentStructureRequest{ Url: tea.String("https://example.com/structured-form.jpg"), NeedRotate: tea.Bool(true), NoStamp: tea.Bool(false), OutputFigure: tea.Bool(true), OutputTable: tea.Bool(true), Paragraph: tea.Bool(true), } docResp, err := client.RecognizeDocumentStructure(docReq) if err != nil { fmt.Println("Error:", err) return } fmt.Println("Document Structure:", tea.StringValue(docResp.Body.Data)) // General structure (added in v3.1.0) genReq := &ocr.RecognizeGeneralStructureRequest{ Url: tea.String("https://example.com/form.jpg"), } genResp, err := client.RecognizeGeneralStructure(genReq) if err != nil { fmt.Println("Error:", err) return } fmt.Println("General Structure:", tea.StringValue(genResp.Body.Data)) } ``` -------------------------------- ### Recognize All Text with OCR API Source: https://context7.com/alibabacloud-go/ocr-api-20210707/llms.txt Use this unified API for general text recognition, routing to specialized recognizers based on the 'Type' parameter. Configure advanced options for ID cards, multi-language, and tables. ```go func recognizeAllText(client *ocr.Client) { req := &ocr.RecognizeAllTextRequest{ Type: tea.String("Advanced"), Url: tea.String("https://example.png"), OutputBarCode: tea.Bool(true), OutputQrcode: tea.Bool(true), OutputStamp: tea.Bool(true), OutputFigure: tea.Bool(false), OutputKVExcel: tea.Bool(false), OutputOricoord: tea.Bool(false), PageNo: tea.Int32(1), // Optional: configure ID card LLM recognition IdCardConfig: &ocr.RecognizeAllTextRequestIdCardConfig{}, // Optional: configure multi-language settings MultiLanConfig: &ocr.RecognizeAllTextRequestMultiLanConfig{}, } resp, err := client.RecognizeAllText(req) if err != nil { fmt.Println("Error:", err) return } fmt.Println("RequestId:", tea.StringValue(resp.Body.RequestId)) fmt.Println("Data:", tea.StringValue(resp.Body.Data)) } ``` -------------------------------- ### RecognizeInvoice Source: https://context7.com/alibabacloud-go/ocr-api-20210707/llms.txt Recognizes Chinese value-added tax (VAT) invoices, extracting invoice number, code, date, buyer/seller information, and total amount. Supports multi-page PDF input via `PageNo`. ```APIDOC ## RecognizeInvoice Recognizes Chinese value-added tax (VAT) invoices, extracting invoice number, code, date, buyer/seller information, and total amount. Supports multi-page PDF input via `PageNo`. ### Request Example ```go req := &ocr.RecognizeInvoiceRequest{ Url: tea.String("https://img.alicdn.com/tfs/TB1qIIfXAPoK1RjSZKbXXX1IXXa-808-523.jpg"), PageNo: tea.Int32(1), // for multi-page PDFs } ``` ### Response Example ```go // Assuming 'resp' is the response object from client.RecognizeInvoice(req) fmt.Println("Code:", tea.StringValue(resp.Body.Code)) fmt.Println("RequestId:", tea.StringValue(resp.Body.RequestId)) fmt.Println("Data:", tea.StringValue(resp.Body.Data)) // Data JSON example: // {"invoiceNum":"12345678","invoiceCode":"044001900211","invoiceDate":"20230601", // "buyerName":"某公司","sellerName":"某供应商","totalAmount":"1000.00",...} ``` ``` -------------------------------- ### RecognizeBusinessLicense Source: https://context7.com/alibabacloud-go/ocr-api-20210707/llms.txt Recognizes Chinese business license documents, extracting key information such as company name, registration number, legal person, registered capital, business scope, and address. ```APIDOC ## RecognizeBusinessLicense ### Description Recognizes Chinese business license documents, extracting company name, registration number, legal person, registered capital, business scope, and address. ### Method POST (Assumed based on typical API patterns for recognition) ### Endpoint /recognizeBusinessLicense ### Parameters #### Request Body - **Url** (string) - Required - The URL of the business license image. ### Request Example ```json { "Url": "https://example.com/business-license.jpg" } ``` ### Response #### Success Response (200) - **Data** (object) - Contains the extracted information from the business license. - **companyName** (string) - The name of the company. - **registrationNumber** (string) - The company's registration number. - **legalPerson** (string) - The legal person of the company. - **registeredCapital** (string) - The registered capital of the company. - **businessScope** (string) - The business scope of the company. - **address** (string) - The registered address of the company. ### Response Example ```json { "Data": { "companyName": "某有限公司", "registrationNumber": "91110108XXXXXXXX", "legalPerson": "李四", "registeredCapital": "100万元人民币", "businessScope": "..., "address": "..." } } ``` ``` -------------------------------- ### Recognize Chinese Business License Source: https://context7.com/alibabacloud-go/ocr-api-20210707/llms.txt Use this function to recognize Chinese business license documents. It extracts key information such as company name, registration number, and address. Ensure the client is initialized before calling. ```go func recognizeBusinessLicense(client *ocr.Client) { req := &ocr.RecognizeBusinessLicenseRequest{ Url: tea.String("https://example.com/business-license.jpg"), } resp, err := client.RecognizeBusinessLicense(req) if err != nil { fmt.Println("Error:", err) return } fmt.Println("Data:", tea.StringValue(resp.Body.Data)) // Data JSON example: // {"companyName":"某有限公司","registrationNumber":"91110108XXXXXXXX", // "legalPerson":"李四","registeredCapital":"100万元人民币",...} } ``` -------------------------------- ### VerifyBusinessLicense Source: https://context7.com/alibabacloud-go/ocr-api-20210707/llms.txt Verifies a Chinese business license by cross-referencing company name, unified social credit code, and legal person against the official registry. ```APIDOC ## VerifyBusinessLicense Verifies a Chinese business license by cross-checking company name, unified social credit code, and legal person against the official registry. ### Parameters #### Request Body - **CompanyName** (string) - Required - The name of the company. - **CreditCode** (string) - Required - The unified social credit code of the company. - **LegalPerson** (string) - Required - The legal person's name. ### Request Example ```go req := &ocr.VerifyBusinessLicenseRequest{ CompanyName: tea.String("某有限公司"), CreditCode: tea.String("91110108XXXXXXXXXX"), LegalPerson: tea.String("李四"), } resp, err := client.VerifyBusinessLicense(req) ``` ### Response Example ```json { "RequestId": "some-request-id", "Body": { "Data": "{\"isConsistent\": true}" } } ``` ``` -------------------------------- ### Verify Chinese Business License Source: https://context7.com/alibabacloud-go/ocr-api-20210707/llms.txt Verify a Chinese business license by comparing company name, credit code, and legal person against official records. This function is useful for validating company information. ```go func verifyBusinessLicense(client *ocr.Client) { req := &ocr.VerifyBusinessLicenseRequest{ CompanyName: tea.String("某有限公司"), CreditCode: tea.String("91110108XXXXXXXXXX"), LegalPerson: tea.String("李四"), } resp, err := client.VerifyBusinessLicense(req) if err != nil { fmt.Println("Error:", err) return } fmt.Println("RequestId:", tea.StringValue(resp.Body.RequestId)) fmt.Println("Data:", tea.StringValue(resp.Body.Data)) // Data JSON: {"isConsistent": true} or {"isConsistent": false, "reason": "..."} } ``` -------------------------------- ### Recognize Multi-Language Text Source: https://context7.com/alibabacloud-go/ocr-api-20210707/llms.txt This function recognizes text in multiple languages within a single image. It supports language-specific configuration via `MultiLanConfig`. Ensure the client is initialized and the image URL is valid. ```go func recognizeMultiLanguage(client *ocr.Client) { req := &ocr.RecognizeMultiLanguageRequest{ Url: tea.String("https://example.com/multilang-doc.jpg"), // MultiLanConfig can specify target languages } resp, err := client.RecognizeMultiLanguage(req) if err != nil { fmt.Println("Error:", err) return } fmt.Println("Data:", tea.StringValue(resp.Body.Data)) } ``` -------------------------------- ### Recognize Invoice with OCR API Source: https://context7.com/alibabacloud-go/ocr-api-20210707/llms.txt Recognizes Chinese VAT invoices, extracting key details like invoice number, code, date, and financial amounts. Supports multi-page PDFs by specifying 'PageNo'. ```go func recognizeInvoice(client *ocr.Client) { req := &ocr.RecognizeInvoiceRequest{ Url: tea.String("https://img.alicdn.com/tfs/TB1qIIfXAPoK1RjSZKbXXX1IXXa-808-523.jpg"), PageNo: tea.Int32(1), // for multi-page PDFs } resp, err := client.RecognizeInvoice(req) if err != nil { fmt.Println("Error:", err) return } fmt.Println("Code:", tea.StringValue(resp.Body.Code)) fmt.Println("RequestId:", tea.StringValue(resp.Body.RequestId)) fmt.Println("Data:", tea.StringValue(resp.Body.Data)) // Data JSON example: // {"invoiceNum":"12345678","invoiceCode":"044001900211","invoiceDate":"20230601", // "buyerName":"某公司","sellerName":"某供应商","totalAmount":"1000.00",...} } ``` -------------------------------- ### RecognizeAllText Source: https://context7.com/alibabacloud-go/ocr-api-20210707/llms.txt Unified API that routes to the appropriate specialized recognizer based on a `Type` parameter (e.g., `"Advanced"`, `"General"`, `"IdCard"`, `"MultiLanguage"`). Supports advanced configuration structs for ID cards, multi-language, and table settings. ```APIDOC ## RecognizeAllText Unified API that routes to the appropriate specialized recognizer based on a `Type` parameter (e.g., `"Advanced"`, `"General"`, `"IdCard"`, `"MultiLanguage"`). Supports advanced configuration structs for ID cards, multi-language, and table settings. ### Request Example ```go req := &ocr.RecognizeAllTextRequest{ Type: tea.String("Advanced"), Url: tea.String("https://example.png"), OutputBarCode: tea.Bool(true), OutputQrcode: tea.Bool(true), OutputStamp: tea.Bool(true), OutputFigure: tea.Bool(false), OutputKVExcel: tea.Bool(false), OutputOricoord: tea.Bool(false), PageNo: tea.Int32(1), // Optional: configure ID card LLM recognition IdCardConfig: &ocr.RecognizeAllTextRequestIdCardConfig{}, // Optional: configure multi-language settings MultiLanConfig: &ocr.RecognizeAllTextRequestMultiLanConfig{}, } ``` ### Response Example ```go // Assuming 'resp' is the response object from client.RecognizeAllText(req) fmt.Println("RequestId:", tea.StringValue(resp.Body.RequestId)) fmt.Println("Data:", tea.StringValue(resp.Body.Data)) ``` ``` -------------------------------- ### Recognize General OCR via URL Source: https://context7.com/alibabacloud-go/ocr-api-20210707/llms.txt Perform general OCR on an image provided via a public URL. The response includes a RequestId and the extracted text data in JSON format. ```go package main import ( "fmt" "os" ocr "github.com/alibabacloud-go/ocr-api-20210707/v3/client" "github.com/alibabacloud-go/tea/tea" ) func recognizeGeneral(client *ocr.Client) { // --- Option A: via URL --- reqURL := &ocr.RecognizeGeneralRequest{ Url: tea.String("https://img.alicdn.com/tfs/TB1Wo7eXAvoK1RjSZFDXXXY3pXa-2512-3509.jpg"), } respURL, err := client.RecognizeGeneral(reqURL) if err != nil { fmt.Println("Error:", err) return } fmt.Println("RequestId:", tea.StringValue(respURL.Body.RequestId)) fmt.Println("Data:", tea.StringValue(respURL.Body.Data)) ``` -------------------------------- ### Recognize English, Japanese, Korean, Latin, Russian, Thai Documents Source: https://context7.com/alibabacloud-go/ocr-api-20210707/llms.txt Use language-specific OCR functions to process documents in English, Japanese, Korean, Latin-script, Russian, and Thai. Set parameters like URL, rotation detection, character info, and paragraph extraction. ```go func recognizeLanguageSpecific(client *ocr.Client) { engReq := &ocr.RecognizeEnglishRequest{ Url: tea.String("https://example.com/english-doc.jpg"), NeedRotate: tea.Bool(true), OutputCharInfo: tea.Bool(false), Paragraph: tea.Bool(true), } engResp, err := client.RecognizeEnglish(engReq) if err != nil { fmt.Println("Error:", err) return } fmt.Println("English OCR Data:", tea.StringValue(engResp.Body.Data)) jpReq := &ocr.RecognizeJanpaneseRequest{ Url: tea.String("https://example.com/japanese-doc.jpg"), } jpResp, err := client.RecognizeJanpanese(jpReq) if err != nil { fmt.Println("Error:", err) return } fmt.Println("Japanese OCR Data:", tea.StringValue(jpResp.Body.Data)) } ``` -------------------------------- ### VerifyVATInvoice Source: https://context7.com/alibabacloud-go/ocr-api-20210707/llms.txt Verifies the authenticity of a Chinese VAT invoice by submitting invoice details like code, number, date, amount, and an optional verification code to the tax authority. ```APIDOC ## VerifyVATInvoice Verifies a Chinese VAT invoice's authenticity by submitting invoice code, number, date, amount, and optional verification code to the tax authority. ### Parameters #### Request Body - **InvoiceCode** (string) - Required - The invoice code. - **InvoiceNo** (string) - Required - The invoice number. - **InvoiceDate** (string) - Required - The invoice date in YYYYMMDD format. - **InvoiceSum** (string) - Required - The total amount of the invoice. - **InvoiceKind** (string) - Optional - The type of invoice, either "special" or "normal". - **VerifyCode** (string) - Optional - A 6-digit verification code. ### Request Example ```go req := &ocr.VerifyVATInvoiceRequest{ InvoiceCode: tea.String("044001900211"), InvoiceNo: tea.String("12345678"), InvoiceDate: tea.String("20230601"), InvoiceSum: tea.String("1000.00"), InvoiceKind: tea.String("special"), VerifyCode: tea.String("123456"), } resp, err := client.VerifyVATInvoice(req) ``` ### Response Example ```json { "RequestId": "some-request-id", "Body": { "Data": "{\"valid\": true, \"buyerName\": \"...\", \"sellerName\": \"...\"}" } } ``` ``` -------------------------------- ### RecognizeMultiLanguage Source: https://context7.com/alibabacloud-go/ocr-api-20210707/llms.txt Recognizes text in multiple languages within a single image. Supports language-specific configuration via `MultiLanConfig`. ```APIDOC ## RecognizeMultiLanguage ### Description Recognizes text in multiple languages within a single image. Supports language-specific configuration via `MultiLanConfig`. ### Method POST (Assumed based on typical API patterns for recognition) ### Endpoint /recognizeMultiLanguage ### Parameters #### Request Body - **Url** (string) - Required - The URL of the image containing multi-language text. - **MultiLanConfig** (object) - Optional - Configuration for multi-language recognition, specifying target languages. ### Request Example ```json { "Url": "https://example.com/multilang-doc.jpg" } ``` ### Response #### Success Response (200) - **Data** (object) - Contains the extracted text from the image, potentially with language identification. ### Response Example ```json { "Data": { "text": "Extracted text from the image..." } } ``` ``` -------------------------------- ### Verify Chinese VAT Invoice Source: https://context7.com/alibabacloud-go/ocr-api-20210707/llms.txt Verify the authenticity of a Chinese VAT invoice by submitting its code, number, date, amount, and an optional verification code. This helps prevent fraudulent invoices. ```go func verifyVATInvoice(client *ocr.Client) { req := &ocr.VerifyVATInvoiceRequest{ InvoiceCode: tea.String("044001900211"), InvoiceNo: tea.String("12345678"), InvoiceDate: tea.String("20230601"), InvoiceSum: tea.String("1000.00"), InvoiceKind: tea.String("special"), // "special" or "normal" VerifyCode: tea.String("123456"), // optional 6-digit code } resp, err := client.VerifyVATInvoice(req) if err != nil { fmt.Println("Error:", err) return } fmt.Println("RequestId:", tea.StringValue(resp.Body.RequestId)) fmt.Println("Data:", tea.StringValue(resp.Body.Data)) // Data JSON: {"valid": true, "buyerName": "...", "sellerName": "...", ...} } ``` -------------------------------- ### RecognizeGeneral Source: https://context7.com/alibabacloud-go/ocr-api-20210707/llms.txt Performs general-purpose OCR on any image, returning all detected text without domain-specific parsing. Accepts either a URL or a binary stream. ```APIDOC ## RecognizeGeneral Performs general-purpose OCR on any image, returning all detected text without domain-specific parsing. Accepts either a URL or a binary stream. ```go package main import ( "fmt" "os" ocr "github.com/alibabacloud-go/ocr-api-20210707/v3/client" "github.com/alibabacloud-go/tea/tea" ) func recognizeGeneral(client *ocr.Client) { // --- Option A: via URL --- reqURL := &ocr.RecognizeGeneralRequest{ Url: tea.String("https://img.alicdn.com/tfs/TB1Wo7eXAvoK1RjSZFDXXXY3pXa-2512-3509.jpg"), } respURL, err := client.RecognizeGeneral(reqURL) if err != nil { fmt.Println("Error:", err) return } fmt.Println("RequestId:", tea.StringValue(respURL.Body.RequestId)) fmt.Println("Data:", tea.StringValue(respURL.Body.Data)) // --- Option B: via local file stream --- f, err := os.Open("/path/to/image.jpg") if err != nil { panic(err) } defer f.Close() reqStream := &ocr.RecognizeGeneralRequest{Body: f} respStream, err := client.RecognizeGeneral(reqStream) if err != nil { fmt.Println("Error:", err) return } // Body.Data contains a JSON string with detected text blocks fmt.Println("Data:", tea.StringValue(respStream.Body.Data)) // Expected output (Data field is JSON): // {"content":"Hello World\nLine two","prism_wordsInfo":[{"word":"Hello World","x":10,"y":20,...},...]} } ``` ``` -------------------------------- ### RecognizeDocumentStructure / RecognizeGeneralStructure Source: https://context7.com/alibabacloud-go/ocr-api-20210707/llms.txt Analyzes document layout to extract structured key-value pairs and regions. RecognizeGeneralStructure supports image streams with JSON-serialized advanced configuration. ```APIDOC ## RecognizeDocumentStructure / RecognizeGeneralStructure Analyzes document layout and extracts structured key-value pairs and regions. `RecognizeGeneralStructure` supports image streams with JSON-serialized advanced config. ### Request Example (RecognizeDocumentStructure) ```go docReq := &ocr.RecognizeDocumentStructureRequest{ Url: tea.String("https://example.com/structured-form.jpg"), NeedRotate: tea.Bool(true), NoStamp: tea.Bool(false), OutputFigure: tea.Bool(true), OutputTable: tea.Bool(true), Paragraph: tea.Bool(true), } resp, err := client.RecognizeDocumentStructure(docReq) ``` ### Request Example (RecognizeGeneralStructure) ```go genReq := &ocr.RecognizeGeneralStructureRequest{ Url: tea.String("https://example.com/form.jpg"), } resp, err := client.RecognizeGeneralStructure(genReq) ``` ### Response Example (Common) ```json { "RequestId": "some-request-id", "Body": { "Data": "{\"tables\": [...], \"key_value_pairs\": {...}}" } } ``` ``` -------------------------------- ### RecognizeEnglish / RecognizeJanpanese / RecognizeKorean / RecognizeLatin / RecognizeRussian / RecognizeThai Source: https://context7.com/alibabacloud-go/ocr-api-20210707/llms.txt Performs language-specific OCR for documents in English, Japanese, Korean, Latin script, Russian, and Thai. Supports options like URL, rotation detection, character info output, and paragraph detection. ```APIDOC ## RecognizeEnglish / RecognizeJanpanese / RecognizeKorean / RecognizeLatin / RecognizeRussian / RecognizeThai Language-specific OCR for English, Japanese, Korean, Latin-script, Russian, and Thai documents. ### Request Example (RecognizeEnglish) ```go engReq := &ocr.RecognizeEnglishRequest{ Url: tea.String("https://example.com/english-doc.jpg"), NeedRotate: tea.Bool(true), OutputCharInfo: tea.Bool(false), Paragraph: tea.Bool(true), } resp, err := client.RecognizeEnglish(engReq) ``` ### Request Example (RecognizeJanpanese) ```go jpReq := &ocr.RecognizeJanpaneseRequest{ Url: tea.String("https://example.com/japanese-doc.jpg"), } resp, err := client.RecognizeJanpanese(jpReq) ``` ### Response Example (Common) ```json { "RequestId": "some-request-id", "Body": { "Data": "{\"text\": \"...\"}" } } ``` ``` -------------------------------- ### RecognizeAdvanced Source: https://context7.com/alibabacloud-go/ocr-api-20210707/llms.txt High-precision full-document OCR with support for table extraction, figure detection, paragraph grouping, stamp removal, and multi-page PDF sorting. ```APIDOC ## RecognizeAdvanced High-precision full-document OCR with support for table extraction, figure detection, paragraph grouping, stamp removal, and multi-page PDF sorting. ```go func recognizeAdvanced(client *ocr.Client) { req := &ocr.RecognizeAdvancedRequest{ Url: tea.String("https://img.alicdn.com/tfs/TB1Wo7eXAvoK1RjSZFDXXXY3pXa-2512-3509.jpg"), NeedRotate: tea.Bool(true), // auto-rotate skewed images NeedSortPage: tea.Bool(true), // sort multi-page PDFs OutputTable: tea.Bool(true), // include table structure in output OutputFigure: tea.Bool(true), // include figure regions OutputCharInfo: tea.Bool(false), // skip per-character bounding boxes NoStamp: tea.Bool(false), // do not remove stamps Paragraph: tea.Bool(true), // group lines into paragraphs Row: tea.Bool(false), } resp, err := client.RecognizeAdvanced(req) if err != nil { fmt.Println("Error:", err) return } fmt.Println("Code:", tea.StringValue(resp.Body.Code)) fmt.Println("Data:", tea.StringValue(resp.Body.Data)) // Data JSON includes "content", "prism_wordsInfo", "prism_tablesInfo", "prism_figuresInfo" } ``` ``` -------------------------------- ### RecognizeDrivingLicense / RecognizeVehicleLicense Source: https://context7.com/alibabacloud-go/ocr-api-20210707/llms.txt Recognizes Chinese driver's licenses and vehicle licenses, extracting details such as name, license number, vehicle type, validity period, and registration information. ```APIDOC ## RecognizeDrivingLicense / RecognizeVehicleLicense ### Description Recognizes Chinese driver's licenses and vehicle licenses, extracting name, license number, vehicle type, validity, and registration details. ### Method POST (Assumed based on typical API patterns for recognition) ### Endpoint /recognizeDrivingLicense /recognizeVehicleLicense ### Parameters #### Request Body - **Url** (string) - Required - The URL of the license image. ### Request Example ```json { "Url": "https://example.com/driving-license.jpg" } ``` ### Response #### Success Response (200) - **Data** (object) - Contains the extracted information from the license. - **name** (string) - The name of the license holder. - **licenseNumber** (string) - The license number. - **vehicleType** (string) - The type of vehicle (for vehicle license). - **validity** (string) - The validity period of the license. - **registrationDetails** (object) - Registration details (for vehicle license). ### Response Example ```json { "Data": { "name": "...", "licenseNumber": "...", "vehicleType": "...", "validity": "...", "registrationDetails": { "registrationNumber": "...", "issueDate": "..." } } } ``` ``` -------------------------------- ### RecognizeAirItinerary / RecognizeTrainInvoice Source: https://context7.com/alibabacloud-go/ocr-api-20210707/llms.txt Recognizes travel-related documents including air itinerary tickets and train tickets, extracting passenger information, flight/train details, origin, destination, date, seat, and fare. ```APIDOC ## RecognizeAirItinerary / RecognizeTrainInvoice ### Description Recognizes travel receipts: air itinerary tickets and train tickets. Extracts passenger name, flight/train number, origin, destination, date, seat, and fare. ### Method POST (Assumed based on typical API patterns for recognition) ### Endpoint /recognizeAirItinerary /recognizeTrainInvoice ### Parameters #### Request Body - **Url** (string) - Required - The URL of the travel receipt image. ### Request Example ```json { "Url": "https://example.com/air-itinerary.jpg" } ``` ### Response #### Success Response (200) - **Data** (object) - Contains the extracted information from the travel receipt. - **passengerName** (string) - The name of the passenger. - **flightNumber** (string) / **trainNumber** (string) - The flight or train number. - **origin** (string) - The departure location. - **destination** (string) - The arrival location. - **date** (string) - The date of travel. - **seatNumber** (string) - The seat number. - **fare** (string) - The fare amount. ### Response Example ```json { "Data": { "trainNumber": "G123", "departureStation": "北京南", "arrivalStation": "上海虹桥", "departureDate": "2024-06-01", "seatNumber": "3A", "fare": "553.0" } } ``` ``` -------------------------------- ### Recognize Table OCR with OCR API Source: https://context7.com/alibabacloud-go/ocr-api-20210707/llms.txt Extracts structured table data from images, including cell text and positions. Supports lineless tables, handwriting, and rotation. Set 'LineLess' to true for borderless tables. ```go func recognizeTableOcr(client *ocr.Client) { req := &ocr.RecognizeTableOcrRequest{ Url: tea.String("https://img.alicdn.com/tfs/TB1Wo7eXAvoK1RjSZFDXXXY3pXa-2512-3509.jpg"), NeedRotate: tea.Bool(true), LineLess: tea.Bool(false), // set true for borderless tables IsHandWriting: tea.String("false"), SkipDetection: tea.Bool(false), } resp, err := client.RecognizeTableOcr(req) if err != nil { fmt.Println("Error:", err) return } fmt.Println("Data:", tea.StringValue(resp.Body.Data)) // Data JSON contains table cells with row/column indices and bounding boxes } ``` -------------------------------- ### RecognizeHandwriting Source: https://context7.com/alibabacloud-go/ocr-api-20210707/llms.txt Recognizes handwritten Chinese text from images or PDFs with optional table detection, rotation correction, and paragraph grouping. ```APIDOC ## RecognizeHandwriting Recognizes handwritten Chinese text from images or PDFs with optional table detection, rotation correction, and paragraph grouping. ### Request Example ```go req := &ocr.RecognizeHandwritingRequest{ Url: tea.String("https://img.alicdn.com/tfs/TB1Wo7eXAvoK1RjSZFDXXXY3pXa-2512-3509.jpg"), NeedRotate: tea.Bool(true), NeedSortPage: tea.Bool(false), OutputTable: tea.Bool(true), OutputCharInfo: tea.Bool(false), Paragraph: tea.Bool(true), } ``` ### Response Example ```go // Assuming 'resp' is the response object from client.RecognizeHandwriting(req) fmt.Println("Data:", tea.StringValue(resp.Body.Data)) ``` ``` -------------------------------- ### RecognizeIdcard Source: https://context7.com/alibabacloud-go/ocr-api-20210707/llms.txt Recognizes Chinese national ID cards (both front and back), extracting fields such as name, ID number, address, and birth date. Supports LLM-enhanced recognition and quality assessment. ```APIDOC ## RecognizeIdcard Recognizes Chinese national ID cards (both front and back), extracting fields such as name, ID number, address, and birth date. Supports LLM-enhanced recognition and quality assessment. ### Request Example ```go req := &ocr.RecognizeIdcardRequest{ Url: tea.String("https://img.alicdn.com/tfs/TB1q5IeXAvoK1RjSZFNXXcxMVXa-483-307.jpg"), OutputFigure: tea.Bool(false), // set true to include face image crop OutputQualityInfo: tea.Bool(true), // return image quality score LlmRec: tea.Bool(true), // use LLM-enhanced recognition (v3.1.3+) } ``` ### Response Example ```go // Assuming 'resp' is the response object from client.RecognizeIdcard(req) fmt.Println("Code:", tea.StringValue(resp.Body.Code)) // Data is a JSON string; unmarshal for field-level access fmt.Println("Data:", tea.StringValue(resp.Body.Data)) // Example Data JSON: // {"front":{"name":"张三","nationality":"汉","address":"北京市...","idNumber":"110101...","birthDate":"19900101",...}} ``` ``` -------------------------------- ### Recognize ID Card with OCR API Source: https://context7.com/alibabacloud-go/ocr-api-20210707/llms.txt Recognize Chinese national ID cards, extracting key fields. Supports LLM-enhanced recognition and image quality assessment. Ensure the 'LlmRec' parameter is set to true for LLM features (v3.1.3+). ```go func recognizeIdcard(client *ocr.Client) { req := &ocr.RecognizeIdcardRequest{ Url: tea.String("https://img.alicdn.com/tfs/TB1q5IeXAvoK1RjSZFNXXcxMVXa-483-307.jpg"), OutputFigure: tea.Bool(false), // set true to include face image crop OutputQualityInfo: tea.Bool(true), // return image quality score LlmRec: tea.Bool(true), // use LLM-enhanced recognition (v3.1.3+) } resp, err := client.RecognizeIdcard(req) if err != nil { fmt.Println("Error:", err) return } fmt.Println("Code:", tea.StringValue(resp.Body.Code)) // Data is a JSON string; unmarshal for field-level access fmt.Println("Data:", tea.StringValue(resp.Body.Data)) // Example Data JSON: // {"front":{"name":"张三","nationality":"汉","address":"北京市...","idNumber":"110101...","birthDate":"19900101",...}} } ``` -------------------------------- ### Recognize Air Itinerary and Train Invoice Source: https://context7.com/alibabacloud-go/ocr-api-20210707/llms.txt This function recognizes travel-related documents, specifically air itinerary tickets and train tickets. It extracts passenger details, flight/train numbers, dates, and fare information. Ensure the client is properly configured. ```go func recognizeTravel(client *ocr.Client) { // Air itinerary airReq := &ocr.RecognizeAirItineraryRequest{ Url: tea.String("https://example.com/air-itinerary.jpg"), } airResp, err := client.RecognizeAirItinerary(airReq) if err != nil { fmt.Println("Error:", err) return } fmt.Println("Air Itinerary:", tea.StringValue(airResp.Body.Data)) // Train invoice trainReq := &ocr.RecognizeTrainInvoiceRequest{ Url: tea.String("https://example.com/train-ticket.jpg"), } trainResp, err := client.RecognizeTrainInvoice(trainReq) if err != nil { fmt.Println("Error:", err) return } fmt.Println("Train Invoice:", tea.StringValue(trainResp.Body.Data)) // Data JSON example: // {"trainNumber":"G123","departureStation":"北京南","arrivalStation":"上海虹桥", // "departureDate":"2024-06-01","seatNumber":"3A","fare":"553.0",...} } ``` -------------------------------- ### Recognize Driver's and Vehicle Licenses Source: https://context7.com/alibabacloud-go/ocr-api-20210707/llms.txt This function recognizes Chinese driver's licenses and vehicle licenses. It extracts details like name, license number, vehicle type, and registration information. Separate requests are made for each document type. ```go func recognizeVehicleDocs(client *ocr.Client) { // Driver's license dlReq := &ocr.RecognizeDrivingLicenseRequest{ Url: tea.String("https://example.com/driving-license.jpg"), } dlResp, err := client.RecognizeDrivingLicense(dlReq) if err != nil { fmt.Println("Error:", err) return } fmt.Println("Driving License Data:", tea.StringValue(dlResp.Body.Data)) // Vehicle license vlReq := &ocr.RecognizeVehicleLicenseRequest{ Url: tea.String("https://example.com/vehicle-license.jpg"), } vlResp, err := client.RecognizeVehicleLicense(vlReq) if err != nil { fmt.Println("Error:", err) return } fmt.Println("Vehicle License Data:", tea.StringValue(vlResp.Body.Data)) } ``` -------------------------------- ### RecognizeTableOcr Source: https://context7.com/alibabacloud-go/ocr-api-20210707/llms.txt Extracts structured table data from images, returning cell text and positional information. Supports lineless tables, handwriting, rotation, and skipping pre-detection. ```APIDOC ## RecognizeTableOcr Extracts structured table data from images, returning cell text and positional information. Supports lineless tables, handwriting, rotation, and skipping pre-detection. ### Request Example ```go req := &ocr.RecognizeTableOcrRequest{ Url: tea.String("https://img.alicdn.com/tfs/TB1Wo7eXAvoK1RjSZFDXXXY3pXa-2512-3509.jpg"), NeedRotate: tea.Bool(true), LineLess: tea.Bool(false), // set true for borderless tables IsHandWriting: tea.String("false"), SkipDetection: tea.Bool(false), } ``` ### Response Example ```go // Assuming 'resp' is the response object from client.RecognizeTableOcr(req) fmt.Println("Data:", tea.StringValue(resp.Body.Data)) // Data JSON contains table cells with row/column indices and bounding boxes ``` ``` -------------------------------- ### Recognize Handwriting with OCR API Source: https://context7.com/alibabacloud-go/ocr-api-20210707/llms.txt Extracts handwritten Chinese text from images or PDFs. Options include table detection, rotation correction, and paragraph grouping. Set 'Paragraph' to true for grouped text. ```go func recognizeHandwriting(client *ocr.Client) { req := &ocr.RecognizeHandwritingRequest{ Url: tea.String("https://img.alicdn.com/tfs/TB1Wo7eXAvoK1RjSZFDXXXY3pXa-2512-3509.jpg"), NeedRotate: tea.Bool(true), NeedSortPage: tea.Bool(false), OutputTable: tea.Bool(true), OutputCharInfo: tea.Bool(false), Paragraph: tea.Bool(true), } resp, err := client.RecognizeHandwriting(req) if err != nil { fmt.Println("Error:", err) return } fmt.Println("Data:", tea.StringValue(resp.Body.Data)) } ``` -------------------------------- ### Recognize Passports (International and Chinese) Source: https://context7.com/alibabacloud-go/ocr-api-20210707/llms.txt This function handles recognition for both international and Chinese passports. It extracts MRZ data, name, nationality, and expiry dates. Two separate request types are used for each passport type. ```go func recognizePassport(client *ocr.Client) { // International passport reqIntl := &ocr.RecognizePassportRequest{ Url: tea.String("https://example.com/passport.jpg"), } respIntl, err := client.RecognizePassport(reqIntl) if err != nil { fmt.Println("Error:", err) return } fmt.Println("Data:", tea.StringValue(respIntl.Body.Data)) // Chinese passport reqCN := &ocr.RecognizeChinesePassportRequest{ Url: tea.String("https://example.com/cn-passport.jpg"), } respCN, err := client.RecognizeChinesePassport(reqCN) if err != nil { fmt.Println("Error:", err) return } fmt.Println("Data:", tea.StringValue(respCN.Body.Data)) // Data JSON example: // {"passportNumber":"E12345678","name":"ZHANG SAN","nationality":"CHN", // "dateOfBirth":"19900101","dateOfExpiry":"20300101","mrz":"P