The efficiency of Huawei Cloud API text recognition OCR—a veritable electronic eye in AI

Cloud services, APIs, SDKs, debugging, viewing, I can do it all

By reading the short article, you can learn: artificial intelligence, emotional analysis of self-talk language, text segmentation, and text translation.

1 Introduction to the API plug-in of IntelliJ IDEA

The API plug-in supports VS Code IDE, IntelliJ IDEA and other platforms, as well as Huawei Cloud's self-developed CodeArts IDE. Based on the capabilities provided by Huawei Cloud services, it helps developers build applications more efficiently and conveniently. The API plug-in is associated with API Explorer, DevStar, CodeLabs, SDK Center, and CLI Center products under Huawei Cloud Services, and is committed to providing developers with a more stable, faster, and safer programming experience.

In this plug-in, we provide but are not limited to the following functions:

Connected to the Huawei Cloud API open platform, it supports users to retrieve APIs, view API documents, debug APIs, and provide SDK sample codes for users to learn how to use APIs.

Provides Huawei Cloud SDK code snippet completion function, and SDK dependency packages are automatically introduced to accelerate users' integration of Huawei Cloud APIs.

Connected to Huawei Cloud Development Experience Center Codelabs, it provides 500+ cloud service code examples and guided tutorials to help users learn quickly.

illustrate:

On a series of platforms such as IntelliJ IDEA and VS Code IDE, the name of the Huawei Cloud API plug-in is Huawei Cloud API. In CodeArts IDE, the API plug-in is natively built into the IDE, and its name is Huawei Cloud API Development Kit.

The use of API plug-ins on series platforms such as IntelliJ IDEA and VS Code IDE depends on the base plug-in. Please install the base plug-in in advance.

2 API plug-in installation--IntelliJ IDEA

2.1 IntelliJ IDEA and other platforms

Installation preparation: Download and install JDK1.8 or higher. Download and install IntelliJ IDEA 2020.2 or higher.

Note: The IntellIj platform also supports IDEs including Goland, Pycharm, etc. If you develop on other related IDEs, please download and configure the compiler or interpreter of the corresponding language. Here we take IDEA as an example to introduce the installation process of the IntelliJ platform plug-in. For other IntelliJ series IDEs, please refer to IDEA.

start installation:

You can download and install the offline package directly from the IDE plug-in market or directly from the JetBrains plug-in market.

IDE installation

  1. Select File > Settings in the top menu bar of IntelliJ IDEA, and click Plugins in the left navigation bar of the Settings dialog box.
  2. Click Marketplace in the Plugins area and enter Huawei Cloud API in the search bar.
  3. Huawei Cloud API will appear in the Search Results area, click Install, and restart the IDE after completion.

Offline package installation:

  1. Enter the plug-in market and search for Huawei Cloud API, enter the plug-in details page, select the desired version of the API plug-in under the Versions tab, and click Download to download the offline plug-in compressed package and save it locally. .
  2. Select File > Settings in the top menu bar of IntelliJ IDEA, and click Plugins in the left navigation bar of the Settings dialog box.
  3. Click in the Plugins area, and then click Install Plugin from Disk....
  4. Select the offline installation package (no need to decompress it) in the Choose Plugin File dialog box, and follow the prompts on the IntelliJ IDEA installation page to complete the subsequent installation steps.

Note: If the IntelliJ IDE you want to install the plug-in for is already open on the desktop, enter the plug-in market and search for Huawei Cloud API. Enter the plug-in details page. In the upper right corner, the locally opened IDE will be identified. Click the corresponding button. In the pop-up Click OK in the IDE window, and the IDE background will start to install the corresponding version of the API plug-in.

Installation verification: After successfully installing the plug-in on the IntelliJ series platform, you can see the Huawei Cloud Toolkit icon in the left navigation bar. Click on the back panel and the words Huawei Cloud API will appear, indicating that the installation is successful.

2.2 API list

The API list is displayed on the left, and all APIs can be queried. Currently, there are 206 cloud services and APIs 9213.

Huawei Cloud provides a text recognition server SDK. You can directly integrate the server SDK to call the relevant APIs of the text recognition service, thereby enabling quick operation of the text recognition service.

This example shows how to implement text recognition through the go version SDK.

Preliminary preparation:

Registered with Huawei Cloud and completed real-name authentication.

Subscribed to text recognition service.

Already have a development environment that supports go 1.14 and above.

The Access Key (AK) and Secret Access Key (SK) corresponding to the Huawei Cloud account have been obtained. Please create and view your AK/SK on the "My Credentials > Access Key" page of the Huawei Cloud Console. For details, see Access Keys. https://support.huaweicloud.com/usermanual-ca/zh-cn_topic_0046606340.html

The project ID for the corresponding area of ​​the text recognition service has been obtained. Please check the project ID on the "My Credentials > API Credentials" page of the Huawei Cloud Console. Please see API credentials for details. API Credentials_My Credentials_User Guide_Huawei Cloud .

Environment configuration:

// 启用go module
export GO111MODULE=on
export GONOSUMDB=*
//若下载不了sdk,则需要设置源
export GOPROXY=https://repo.huaweicloud.com/repository/goproxy/,direct
安装SDK及代码依赖:
// 安装华为云Go库
go get -u github.com/huaweicloud/huaweicloud-sdk-go-v3
// 安装依赖
go get github.com/json-iterator/go
go get github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/[email protected]
go get github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/[email protected]
go get github.com/huaweicloud/huaweicloud-sdk-go-v3/core/[email protected]

3 AI text recognition service text recognition example

3.1 go version

Import dependent modules

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
	ocr "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/ocr/v1"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/ocr/v1/model"
	region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/ocr/v1/region"
)

Initialize authentication information and text recognition service client

ak := "<YOUR AK>"
sk := "<YOUR SK>"
regionName := "<YOUR REGION NAME>"
imageBase64 := "<YOUR IMAGE BASE64>"
// 初始化认证信息
auth := basic.NewCredentialsBuilder().
    WithAk(ak).
    WithSk(sk).
    Build()
// 获取服务调用client
client := ocr.NewOcrClient(
    ocr.OcrClientBuilder().
        WithRegion(region.ValueOf(regionName)).
        WithCredential(auth).
        Build())

The relevant parameters are explained as follows

ak: Huawei Cloud account Access Key.

sk: Huawei Cloud account Secret Access Key.

service region: the name of the region where the service is located, for example:

cn-north-1 Beijing 1

cn-north-4 Beijing Four

CN_EAST_3 Shanghai 1

CN_SOUTH_1 Guangzhou, South China

6.SDK demo code analysis

Universal text recognition

request := &model.RecognizeGeneralTextRequest{}
quickModeGeneralTextRequestBody := true
detectDirectionGeneralTextRequestBody := true
imageGeneralTextRequestBody := imageBase64
request.Body = &model.GeneralTextRequestBody{
    QuickMode:       &quickModeGeneralTextRequestBody,
    DetectDirection: &detectDirectionGeneralTextRequestBody,
    Image:           &imageGeneralTextRequestBody,
}
response, err := client.RecognizeGeneralText(request)
if err == nil {
    fmt.Printf("%+v\n", response)
} else {
    fmt.Println(err)
}

Common table recognition:

request := &model.RecognizeGeneralTableRequest{}
returnExcelGeneralTableRequestBody := true
returnConfidenceGeneralTableRequestBody := true
returnTextLocationGeneralTableRequestBody := true
imageGeneralTableRequestBody := imageBase64
request.Body = &model.GeneralTableRequestBody{
    ReturnExcel:        &returnExcelGeneralTableRequestBody,
    ReturnConfidence:   &returnConfidenceGeneralTableRequestBody,
    ReturnTextLocation: &returnTextLocationGeneralTableRequestBody,
    Image:              &imageGeneralTableRequestBody,
}
response, err := client.RecognizeGeneralTable(request)
if err == nil {
    fmt.Printf("%+v\n", response)
} else {
    fmt.Println(err)
}

ID card recognition

request := &model.RecognizeIdCardRequest{}
returnVerificationIdCardRequestBody := true
sideIdCardRequestBody := "front"
imageIdCardRequestBody := imageBase64
request.Body = &model.IdCardRequestBody{
    ReturnVerification: &returnVerificationIdCardRequestBody,
    Side:               &sideIdCardRequestBody,
    Image:              &imageIdCardRequestBody,
}
response, err := client.RecognizeIdCard(request)
if err == nil {
    fmt.Printf("%+v\n", response)
} else {
    fmt.Println(err)
}

Bank card identification

request := &model.RecognizeBankcardRequest{}
imageBankcardRequestBody := imageBase64
request.Body = &model.BankcardRequestBody{
    Image: &imageBankcardRequestBody,
}
response, err := client.RecognizeBankcard(request)
if err == nil {
    fmt.Printf("%+v\n", response)
} else {
    fmt.Println(err)
}

智能分类识别
request := &model.RecognizeAutoClassificationRequest{}
imageAutoClassificationRequestBody := imageBase64
request.Body = &model.AutoClassificationRequestBody{
    Image: &imageAutoClassificationRequestBody,
}
response, err := client.RecognizeAutoClassification(request)
if err == nil {
    fmt.Printf("%+v\n", response)
} else {
    fmt.Println(err)
}

VAT invoice identification

request := &model.RecognizeVatInvoiceRequest{}
advancedModeVatInvoiceRequestBody := true
imageVatInvoiceRequestBody := imageBase64
request.Body = &model.VatInvoiceRequestBody{
    AdvancedMode: &advancedModeVatInvoiceRequestBody,
    Image:        &imageVatInvoiceRequestBody,
}
response, err := client.RecognizeVatInvoice(request)
if err == nil {
    fmt.Printf("%+v\n", response)
} else {
    fmt.Println(err)
}

Fixed amount invoice identification

request := &model.RecognizeQuotaInvoiceRequest{}
imageQuotaInvoiceRequestBody := imageBase64
request.Body = &model.QuotaInvoiceRequestBody{
    Image: &imageQuotaInvoiceRequestBody,
}
response, err := client.RecognizeQuotaInvoice(request)
if err == nil {
    fmt.Printf("%+v\n", response)
} else {
    fmt.Println(err)
}

Handwritten text recognition

request := &model.RecognizeHandwritingRequest{}
detectDirectionHandwritingRequestBody := true
charSetHandwritingRequestBody := "digit"
quickModeHandwritingRequestBody := true
imageHandwritingRequestBody := imageBase64
request.Body = &model.HandwritingRequestBody{
    DetectDirection: &detectDirectionHandwritingRequestBody,
    CharSet:         &charSetHandwritingRequestBody,
    QuickMode:       &quickModeHandwritingRequestBody,
    Image:           &imageHandwritingRequestBody,
}
response, err := client.RecognizeHandwriting(request)
if err == nil {
    fmt.Printf("%+v\n", response)
} else {
    fmt.Println(err)
}

Driving license identification

request := &model.RecognizeVehicleLicenseRequest{}
returnIssuingAuthorityVehicleLicenseRequestBody := true
sideVehicleLicenseRequestBody := "front"
imageVehicleLicenseRequestBody := imageBase64
request.Body = &model.VehicleLicenseRequestBody{
    ReturnIssuingAuthority: &returnIssuingAuthorityVehicleLicenseRequestBody,
    Side:                   &sideVehicleLicenseRequestBody,
    Image:                  &imageVehicleLicenseRequestBody,
}
response, err := client.RecognizeVehicleLicense(request)
if err == nil {
    fmt.Printf("%+v\n", response)
} else {
    fmt.Println(err)
}

Road transport license identification

request := &model.RecognizeTransportationLicenseRequest{}
imageTransportationLicenseRequestBody := imageBase64
request.Body = &model.TransportationLicenseRequestBody{
    Image: &imageTransportationLicenseRequestBody,
}
response, err := client.RecognizeTransportationLicense(request)
if err == nil {
    fmt.Printf("%+v\n", response)
} else {
    fmt.Println(err)
}

Taxi invoice identification

request := &model.RecognizeTaxiInvoiceRequest{}
imageTaxiInvoiceRequestBody := imageBase64
request.Body = &model.TaxiInvoiceRequestBody{
    Image: &imageTaxiInvoiceRequestBody,
}
response, err := client.RecognizeTaxiInvoice(request)
if err == nil {
    fmt.Printf("%+v\n", response)
} else {
    fmt.Println(err)
}

Vehicle toll invoice identification

request := &model.RecognizeTollInvoiceRequest{}
imageTollInvoiceRequestBody := imageBase64
request.Body = &model.TollInvoiceRequestBody{
    Image: &imageTollInvoiceRequestBody,
}
response, err := client.RecognizeTollInvoice(request)
if err == nil {
    fmt.Printf("%+v\n", response)
} else {
    fmt.Println(err)
}

Motor vehicle sales invoice identification

request := &model.RecognizeMvsInvoiceRequest{}
imageMvsInvoiceRequestBody := imageBase64
request.Body = &model.MvsInvoiceRequestBody{
    Image: &imageMvsInvoiceRequestBody,
}
response, err := client.RecognizeMvsInvoice(request)
if err == nil {
    fmt.Printf("%+v\n", response)
} else {
    fmt.Println(err)
}

License Plate Recognition

request := &model.RecognizeLicensePlateRequest{}
imageLicensePlateRequestBody := imageBase64
request.Body = &model.LicensePlateRequestBody{
    Image: &imageLicensePlateRequestBody,
}
response, err := client.RecognizeLicensePlate(request)
if err == nil {
    fmt.Printf("%+v\n", response)
} else {
    fmt.Println(err)
}

Aircraft itinerary identification

request := &model.RecognizeFlightItineraryRequest{}
imageFlightItineraryRequestBody := imageBase64
request.Body = &model.FlightItineraryRequestBody{
    Image: &imageFlightItineraryRequestBody,
}
response, err := client.RecognizeFlightItinerary(request)
if err == nil {
    fmt.Printf("%+v\n", response)
} else {
    fmt.Println(err)
}

Business license identification

request := &model.RecognizeBusinessLicenseRequest{}
imageBusinessLicenseRequestBody := imageBase64
request.Body = &model.BusinessLicenseRequestBody{
    Image: &imageBusinessLicenseRequestBody,
}
response, err := client.RecognizeBusinessLicense(request)
if err == nil {
    fmt.Printf("%+v\n", response)
} else {
    fmt.Println(err)
}

Internet picture recognition

request := &model.RecognizeWebImageRequest{}
var listExtractTypebody = []string{
    "contact_info",
    "image_size",
}
detectDirectionWebImageRequestBody := true
imageWebImageRequestBody := imageBase64
request.Body = &model.WebImageRequestBody{
    ExtractType:     &listExtractTypebody,
    DetectDirection: &detectDirectionWebImageRequestBody,
    Image:           &imageWebImageRequestBody,
}
response, err := client.RecognizeWebImage(request)
if err == nil {
    fmt.Printf("%+v\n", response)
} else {
    fmt.Println(err)
}

Driver's license recognition

request := &model.RecognizeDriverLicenseRequest{}
returnIssuingAuthorityDriverLicenseRequestBody := true
sideDriverLicenseRequestBody := "front"
imageDriverLicenseRequestBody := imageBase64
request.Body = &model.DriverLicenseRequestBody{
    ReturnIssuingAuthority: &returnIssuingAuthorityDriverLicenseRequestBody,
    Side:                   &sideDriverLicenseRequestBody,
    Image:                  &imageDriverLicenseRequestBody,
}
response, err := client.RecognizeDriverLicense(request)
if err == nil {
    fmt.Printf("%+v\n", response)
} else {
    fmt.Println(err)
}

Business card recognition

request := &model.RecognizeBusinessCardRequest{}
returnAdjustedImageBusinessCardRequestBody := true
detectDirectionBusinessCardRequestBody := true
imageBusinessCardRequestBody := imageBase64
request.Body = &model.BusinessCardRequestBody{
    ReturnAdjustedImage: &returnAdjustedImageBusinessCardRequestBody,
    DetectDirection:     &detectDirectionBusinessCardRequestBody,
    Image:               &imageBusinessCardRequestBody,
}
response, err := client.RecognizeBusinessCard(request)
if err == nil {
    fmt.Printf("%+v\n", response)
} else {
    fmt.Println(err)
}

Train ticket identification

request := &model.RecognizeTrainTicketRequest{}
imageTrainTicketRequestBody := imageBase64
request.Body = &model.TrainTicketRequestBody{
    Image: &imageTrainTicketRequestBody,
}
response, err := client.RecognizeTrainTicket(request)
if err == nil {
    fmt.Printf("%+v\n", response)
} else {
    fmt.Println(err)
}

VIN code identification

request := &model.RecognizeVinRequest{}
imageVinRequestBody := imageBase64
request.Body = &model.VinRequestBody{
    Image: &imageVinRequestBody,
}
response, err := client.RecognizeVin(request)
if err == nil {
    fmt.Printf("%+v\n", response)
} else {
    fmt.Println(err)
}

Passport identification

request := &model.RecognizePassportRequest{}
imagePassportRequestBody := imageBase64
request.Body = &model.PassportRequestBody{
    Image: &imagePassportRequestBody,
}
response, err := client.RecognizePassport(request)
if err == nil {
    fmt.Printf("%+v\n", response)
} else {
    fmt.Println(err)
}

Insurance policy card identification

request := &model.RecognizeInsurancePolicyRequest{}
detectDirectionInsurancePolicyRequestBody := true
imageInsurancePolicyRequestBody := imageBase64
request.Body = &model.InsurancePolicyRequestBody{
    DetectDirection: &detectDirectionInsurancePolicyRequestBody,
    Image:           &imageInsurancePolicyRequestBody,
}
response, err := client.RecognizeInsurancePolicy(request)
if err == nil {
    fmt.Printf("%+v\n", response)
} else {
    fmt.Println(err)
}

Road transport qualification certificate identification

request := &model.RecognizeQualificationCertificateRequest{}
imageQualificationCertificateRequestBody := imageBase64
request.Body = &model.QualificationCertificateRequestBody{
    Image: &imageQualificationCertificateRequestBody,
}
response, err := client.RecognizeQualificationCertificate(request)
if err == nil {
    fmt.Printf("%+v\n", response)
} else {
    fmt.Println(err)
}

3.2 python version

start using

Import dependent modules

from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkocr.v1.region.ocr_region import OcrRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkocr.v1 import *

Initialize authentication information

def get_credential():
    return BasicCredentials(ak, sk)

The relevant parameter descriptions are as follows:

ak: Huawei Cloud account Access Key.

sk: Huawei Cloud account Secret Access Key.

Initialize the client of the text recognition service

def get_client():
    return OcrClient.new_builder(OcrClient)
        .with_credentials(credentials)
        .with_region(OcrRegion.CN_NORTH_4)
        .build()

The relevant parameter descriptions are as follows:

service region: The region where the service is located, for example:

CN_NORTH_1 Beijing 1

CN_NORTH_4 Beijing Four

CN_EAST_3 Shanghai 1

CN_SOUTH_1 Guangzhou, South China

SDK demo code analysis

Universal text recognition

def recognize_general_text_request():
    try:
        request = RecognizeGeneralTextRequest()
        request.body = GeneralTextRequestBody(
            image=image_base64
        )
        response = client.recognize_general_text(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

Universal table recognition

def recognize_general_table_request():
    try:
        request = RecognizeGeneralTableRequest()
        request.body = GeneralTableRequestBody(
            image=image_base64
        )
        response = client.recognize_general_table(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

ID card recognition

def recognize_id_card_request():
    try:
        request = RecognizeIdCardRequest()
        request.body = IdCardRequestBody(
            image=image_base64
        )
        response = client.recognize_id_card(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

Bank card identification

def recognize_bankcard_request():
    try:
        request = RecognizeBankcardRequest()
        request.body = BankcardRequestBody(
            image=image_base64
        )
        response = client.recognize_bankcard(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

Intelligent classification and recognition

def recognize_auto_classification_request():
    try:
        request = RecognizeAutoClassificationRequest()
        request.body = AutoClassificationRequestBody(
            image=image_base64
        )
        response = client.recognize_auto_classification(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

VAT invoice identification

def recognize_vat_invoice_request():
    try:
        request = RecognizeVatInvoiceRequest()
        request.body = VatInvoiceRequestBody(
            image=image_base64
        )
        response = client.recognize_vat_invoice(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

Fixed amount invoice identification

def recognize_quota_invoice_request():
    try:
        request = RecognizeQuotaInvoiceRequest()
        request.body = QuotaInvoiceRequestBody(
            image=image_base64
        )
        response = client.recognize_quota_invoice(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

Handwritten text recognition

def recognize_handwriting_request():
    try:
        request = RecognizeHandwritingRequest
        request.body = HandwritingRequestBody(
            image=image_base64
        )
        response = client.recognize_handwriting(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

Driving license identification

def recognize_vehicle_license_request():
    try:
        request = RecognizeIdCardRequest()
        request.body = VehicleLicenseRequestBody(
            image=image_base64
        )
        response = client.recognize_vehicle_license(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

Road transport license identification

def recognize_transportation_license_request():
    try:
        request = RecognizeTransportationLicenseRequest()
        request.body = TransportationLicenseRequestBody(
            image=image_base64
        )
        response = client.recognize_transportation_license(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

Taxi invoice identification

def recognize_taxi_invoice_request():
    try:
        request = RecognizeTaxiInvoiceRequest()
        request.body = TaxiInvoiceRequestBody(
            image=image_base64
        )
        response = client.recognize_taxi_invoice(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

Vehicle toll invoice identification

def recognize_toll_invoice_request():
    try:
        request = RecognizeTollInvoiceRequest()
        request.body = TollInvoiceRequestBody(
            image=image_base64
        )
        response = client.recognize_toll_invoice(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

Motor vehicle sales invoice identification

def recognize_mvs_invoice_request():
    try:
        request = RecognizeMvsInvoiceRequest()
        request.body = MvsInvoiceRequestBody(
            image=image_base64
        )
        response = client.recognize_mvs_invoice(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

License Plate Recognition

def recognize_license_plate_request():
    try:
        request = RecognizeLicensePlateRequest()
        request.body = LicensePlateRequestBody(
            image=image_base64
        )
        response = client.recognize_license_plate(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

Aircraft itinerary identification

def recognize_flight_itinerary_request():
    try:
        request = RecognizeFlightItineraryRequest()
        request.body = FlightItineraryRequestBody(
            image=image_base64
        )
        response = client.recognize_flight_itinerary(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

Business license identification

def recognize_business_license_request():
    try:
        request = RecognizeBusinessLicenseRequest()
        request.body = BusinessLicenseRequestBody(
            image=image_base64
        )
        response = client.recognize_business_license(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

Internet picture recognition

def recognize_web_image_request():
    try:
        request = RecognizeWebImageRequest()
        request.body = WebImageRequestBody(
            image=image_base64
        )
        response = client.recognize_web_image(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

Driver's license recognition

def recognize_driver_license_request():
    try:
        request = RecognizeDriverLicenseRequest()
        request.body = DriverLicenseRequestBody(
            image=image_base64
        )
        response = client.recognize_driver_license(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

Business card recognition

def recognize_business_card_request():
    try:
        request = RecognizeBusinessCardRequest()
        request.body = BusinessCardRequestBody(
            image=image_base64
        )
        response = client.recognize_business_card(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

Train ticket identification

def recognize_train_ticket_request():
    try:
        request = RecognizeTrainTicketRequest()
        request.body = TrainTicketRequestBody(
            image=image_base64
        )
        response = client.recognize_train_ticket(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

VIN code identification

def recognize_vin_request():
    try:
        request = RecognizeVinRequest()
        request.body = VinRequestBody(
            image=image_base64
        )
        response = client.recognize_vin(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

Passport identification

def recognize_passport_request():
    try:
        request = RecognizePassportRequest()
        request.body = PassportRequestBody(
            image=image_base64
        )
        response = client.recognize_passport(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

insurance policy identification

def recognize_insurance_policy_request():
    try:
        request = RecognizeInsurancePolicyRequest()
        request.body = InsurancePolicyRequestBody(
            image=image_base64
        )
        response = client.recognize_insurance_policy(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

Road transport qualification certificate identification

def recognize_transportation_qualification_certificate_request():
    try:
        request = RecognizeQualificationCertificateRequest()
        request.body = QualificationCertificateRequestBody(
            image=image_base64
        )
        response = client.recognize_transportation_qualification_certificate(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

3.3 java version

start using

Import dependent modules

import com.huaweicloud.sdk.core.auth.ICredential;
import com.huaweicloud.sdk.core.auth.BasicCredentials;
import com.huaweicloud.sdk.core.exception.ConnectionException;
import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
import com.huaweicloud.sdk.core.exception.ServiceResponseException;

import com.huaweicloud.sdk.ocr.v1.region.OcrRegion;
import com.huaweicloud.sdk.ocr.v1.*;
import com.huaweicloud.sdk.ocr.v1.model.*;

Initialize authentication information

public static ICredential getCredential(String ak, String sk) {
    return new BasicCredentials().withAk(ak).withSk(sk);
}

The relevant parameter descriptions are as follows:

ak: Huawei Cloud account Access Key.

sk: Huawei Cloud account Secret Access Key.

Initialize the client of the text recognition service

public static OcrClient getClient(Region region, ICredential auth) {
    return OcrClient.newBuilder().withCredential(auth).withRegion(region).build();
}

The relevant parameter descriptions are as follows:

service region: The region where the service is located, for example:

CN_NORTH_1 Beijing 1

CN_NORTH_4 Beijing Four

CN_EAST_3 Shanghai 1

CN_SOUTH_1 Guangzhou, South China

SDK demo code analysis

Universal text recognition

private static void generalText(OcrClient ocrClient, String image) {
    RecognizeGeneralTextRequest recognizeGeneralTextRequest = new RecognizeGeneralTextRequest();
    GeneralTextRequestBody requestBody = new GeneralTextRequestBody();
    requestBody.setImage(image);
    recognizeGeneralTextRequest.setBody(requestBody);
    try {
        RecognizeGeneralTextResponse textResponse = ocrClient.recognizeGeneralText(recognizeGeneralTextRequest);
        System.out.println(textResponse.getResult());
    } catch (ConnectionException | RequestTimeoutException e) {
        LOGGER.error(e.toString());
    } catch (ServiceResponseException e) {
        LOGGER.error(String.valueOf(e.getHttpStatusCode()));
        LOGGER.error(e.getErrorCode());
        LOGGER.error(e.getErrorMsg());
    }
}

Universal table recognition

private static void generalTable(OcrClient ocrClient, String image) {
    RecognizeGeneralTableRequest request = new RecognizeGeneralTableRequest();
    GeneralTableRequestBody requestBody = new GeneralTableRequestBody();
    requestBody.withImage(image);
    request.withBody(requestBody);
    try {
        RecognizeGeneralTableResponse response = ocrClient.recognizeGeneralTable(request);
        System.out.println(response.toString());
    } catch (ConnectionException | RequestTimeoutException e) {
        LOGGER.error(e.toString());
    } catch (ServiceResponseException e) {
        LOGGER.error(String.valueOf(e.getHttpStatusCode()));
        LOGGER.error(e.getErrorCode());
        LOGGER.error(e.getErrorMsg());
    }
}

ID card recognition

private static void idCard(OcrClient ocrClient, String image) {
    RecognizeIdCardRequest request = new RecognizeIdCardRequest();
    IdCardRequestBody body = new IdCardRequestBody();
    body.withReturnVerification(true);
    body.withSide("front");
    body.withImage(image);
    request.withBody(body);
    try {
        RecognizeIdCardResponse response = ocrClient.recognizeIdCard(request);
        System.out.println(response.toString());
    } catch (ConnectionException | RequestTimeoutException e) {
        LOGGER.error(e.toString());
    } catch (ServiceResponseException e) {
        LOGGER.error(String.valueOf(e.getHttpStatusCode()));
        LOGGER.error(e.getErrorCode());
        LOGGER.error(e.getErrorMsg());
    }
}

Bank card identification

private static void bankcard(OcrClient ocrClient, String image) {
    RecognizeBankcardRequest recognizeBankcardRequest = new RecognizeBankcardRequest();
    BankcardRequestBody bankcardRequestBody = new BankcardRequestBody();
    bankcardRequestBody.setImage(image);
    recognizeBankcardRequest.setBody(bankcardRequestBody);
    try {
        RecognizeBankcardResponse response = ocrClient.recognizeBankcard(recognizeBankcardRequest);
        System.out.println(response);
    } catch (ConnectionException | RequestTimeoutException e) {
        LOGGER.error(e.toString());
    } catch (ServiceResponseException e) {
        LOGGER.error(String.valueOf(e.getHttpStatusCode()));
        LOGGER.error(e.getErrorCode());
        LOGGER.error(e.getErrorMsg());
    }
}

Intelligent classification and recognition

private static void autoClassification(OcrClient ocrClient, String image) {
    RecognizeAutoClassificationRequest request = new RecognizeAutoClassificationRequest();
    AutoClassificationRequestBody requestBody = new AutoClassificationRequestBody();
    requestBody.withImage(image);
    request.setBody(requestBody);
    try {
        RecognizeAutoClassificationResponse response = ocrClient.recognizeAutoClassification(request);
        System.out.println(response);
    } catch (ConnectionException | RequestTimeoutException e) {
        LOGGER.error(e.toString());
    } catch (ServiceResponseException e) {
        LOGGER.error(String.valueOf(e.getHttpStatusCode()));
        LOGGER.error(e.getErrorCode());
        LOGGER.error(e.getErrorMsg());
    }
}

VAT invoice identification

private static void vatInvoice(OcrClient ocrClient, String image) {
    RecognizeVatInvoiceRequest request = new RecognizeVatInvoiceRequest();
    VatInvoiceRequestBody body = new VatInvoiceRequestBody();
    body.withImage(image);
    request.withBody(body);
    try {
        RecognizeVatInvoiceResponse response = ocrClient.recognizeVatInvoice(request);
        System.out.println(response.toString());
    } catch (ConnectionException | RequestTimeoutException e) {
        LOGGER.error(e.toString());
    } catch (ServiceResponseException e) {
        LOGGER.error(String.valueOf(e.getHttpStatusCode()));
        LOGGER.error(e.getErrorCode());
        LOGGER.error(e.getErrorMsg());
    }
}

Fixed amount invoice identification

private static void quotaInvoice(OcrClient ocrClient, String image) {
    RecognizeQuotaInvoiceRequest request = new RecognizeQuotaInvoiceRequest();
    QuotaInvoiceRequestBody body = new QuotaInvoiceRequestBody();
    body.withImage(image);
    request.withBody(body);
    try {
        RecognizeQuotaInvoiceResponse response = ocrClient.recognizeQuotaInvoice(request);
        System.out.println(response.toString());
    } catch (ConnectionException | RequestTimeoutException e) {
        LOGGER.error(e.toString());
    } catch (ServiceResponseException e) {
        LOGGER.error(String.valueOf(e.getHttpStatusCode()));
        LOGGER.error(e.getErrorCode());
        LOGGER.error(e.getErrorMsg());
    }
}

Handwritten text recognition

private static void handwriting(OcrClient ocrClient, String image) {
    RecognizeHandwritingRequest request = new RecognizeHandwritingRequest();
    HandwritingRequestBody body = new HandwritingRequestBody();
    body.withDetectDirection(true);
    body.withQuickMode(true);
    body.withImage(image);
    request.withBody(body);
    try {
        RecognizeHandwritingResponse response = ocrClient.recognizeHandwriting(request);
        System.out.println(response.toString());
    } catch (ConnectionException | RequestTimeoutException e) {
        LOGGER.error(e.toString());
    } catch (ServiceResponseException e) {
        LOGGER.error(String.valueOf(e.getHttpStatusCode()));
        LOGGER.error(e.getErrorCode());
        LOGGER.error(e.getErrorMsg());
    }
}

Driving license identification

private static void vehicleLicense(OcrClient ocrClient, String image) {
    RecognizeVehicleLicenseRequest request = new RecognizeVehicleLicenseRequest();
    VehicleLicenseRequestBody body = new VehicleLicenseRequestBody();
    body.withReturnIssuingAuthority(true);
    body.withImage(image);
    request.withBody(body);
    try {
        RecognizeVehicleLicenseResponse response = ocrClient.recognizeVehicleLicense(request);
        System.out.println(response.toString());
    } catch (ConnectionException | RequestTimeoutException e) {
        LOGGER.error(e.toString());
    } catch (ServiceResponseException e) {
        LOGGER.error(String.valueOf(e.getHttpStatusCode()));
        LOGGER.error(e.getErrorCode());
        LOGGER.error(e.getErrorMsg());
    }
}

Road transport license identification

private static void transportationLicense(OcrClient ocrClient, String image) {
    RecognizeTransportationLicenseRequest request = new RecognizeTransportationLicenseRequest();
    TransportationLicenseRequestBody body = new TransportationLicenseRequestBody();
    body.withImage(image);
    request.withBody(body);
    try {
        RecognizeTransportationLicenseResponse response = ocrClient.recognizeTransportationLicense(request);
        System.out.println(response.toString());
    } catch (ConnectionException | RequestTimeoutException e) {
        LOGGER.error(e.toString());
    } catch (ServiceResponseException e) {
        LOGGER.error(String.valueOf(e.getHttpStatusCode()));
        LOGGER.error(e.getErrorCode());
        LOGGER.error(e.getErrorMsg());
    }
}

Taxi invoice identification

private static void taxiInvoice(OcrClient ocrClient, String image) {
    RecognizeTaxiInvoiceRequest request = new RecognizeTaxiInvoiceRequest();
    TaxiInvoiceRequestBody body = new TaxiInvoiceRequestBody();
    body.withImage(image);
    request.withBody(body);
    try {
        RecognizeTaxiInvoiceResponse response = ocrClient.recognizeTaxiInvoice(request);
        System.out.println(response.toString());
    } catch (ConnectionException | RequestTimeoutException e) {
        LOGGER.error(e.toString());
    } catch (ServiceResponseException e) {
        LOGGER.error(String.valueOf(e.getHttpStatusCode()));
        LOGGER.error(e.getErrorCode());
        LOGGER.error(e.getErrorMsg());
    }
}

Vehicle toll invoice identification

private static void tollInvoice(OcrClient ocrClient, String image) {
    RecognizeTollInvoiceRequest request = new RecognizeTollInvoiceRequest();
    TollInvoiceRequestBody body = new TollInvoiceRequestBody();
    body.withImage(image);
    request.withBody(body);
    try {
        RecognizeTollInvoiceResponse response = ocrClient.recognizeTollInvoice(request);
        System.out.println(response.toString());
    } catch (ConnectionException | RequestTimeoutException e) {
        LOGGER.error(e.toString());
    } catch (ServiceResponseException e) {
        LOGGER.error(String.valueOf(e.getHttpStatusCode()));
        LOGGER.error(e.getErrorCode());
        LOGGER.error(e.getErrorMsg());
    }
}

Motor vehicle sales invoice identification

private static void mvsInvoice(OcrClient ocrClient, String image) {
    RecognizeMvsInvoiceRequest request = new RecognizeMvsInvoiceRequest();
    MvsInvoiceRequestBody body = new MvsInvoiceRequestBody();
    body.withImage(image);
    request.withBody(body);
    try {
        RecognizeMvsInvoiceResponse response = ocrClient.recognizeMvsInvoice(request);
        System.out.println(response.toString());
    } catch (ConnectionException | RequestTimeoutException e) {
        LOGGER.error(e.toString());
    } catch (ServiceResponseException e) {
        LOGGER.error(String.valueOf(e.getHttpStatusCode()));
        LOGGER.error(e.getErrorCode());
        LOGGER.error(e.getErrorMsg());
    }
}

License Plate Recognition

private static void licensePlate(OcrClient ocrClient, String image) {
    RecognizeLicensePlateRequest request = new RecognizeLicensePlateRequest();
    LicensePlateRequestBody body = new LicensePlateRequestBody();
    body.withImage(image);
    request.withBody(body);
    try {
        RecognizeLicensePlateResponse response = ocrClient.recognizeLicensePlate(request);
        System.out.println(response.toString());
    } catch (ConnectionException | RequestTimeoutException e) {
        LOGGER.error(e.toString());
    } catch (ServiceResponseException e) {
        LOGGER.error(String.valueOf(e.getHttpStatusCode()));
        LOGGER.error(e.getErrorCode());
        LOGGER.error(e.getErrorMsg());
    }
}

Aircraft itinerary identification

private static void flightItinerary(OcrClient ocrClient, String image) {
    RecognizeFlightItineraryRequest request = new RecognizeFlightItineraryRequest();
    FlightItineraryRequestBody body = new FlightItineraryRequestBody();
    body.withImage(image);
    request.withBody(body);
    try {
        RecognizeFlightItineraryResponse response = ocrClient.recognizeFlightItinerary(request);
        System.out.println(response.toString());
    } catch (ConnectionException | RequestTimeoutException e) {
        LOGGER.error(e.toString());
    } catch (ServiceResponseException e) {
        LOGGER.error(String.valueOf(e.getHttpStatusCode()));
        LOGGER.error(e.getErrorCode());
        LOGGER.error(e.getErrorMsg());
    }
}

Business license identification

private static void businessLicense(OcrClient ocrClient, String image) {
    RecognizeBusinessLicenseRequest request = new RecognizeBusinessLicenseRequest();
    BusinessLicenseRequestBody body = new BusinessLicenseRequestBody();
    body.withImage(image);
    request.withBody(body);
    try {
        RecognizeBusinessLicenseResponse response = ocrClient.recognizeBusinessLicense(request);
        System.out.println(response.toString());
    } catch (ConnectionException | RequestTimeoutException e) {
        LOGGER.error(e.toString());
    } catch (ServiceResponseException e) {
        LOGGER.error(String.valueOf(e.getHttpStatusCode()));
        LOGGER.error(e.getErrorCode());
        LOGGER.error(e.getErrorMsg());
    }
}

Internet picture recognition

private static void webImage(OcrClient ocrClient, String image) {
    RecognizeWebImageRequest request = new RecognizeWebImageRequest();
    WebImageRequestBody body = new WebImageRequestBody();
    body.withImage(image);
    request.withBody(body);
    try {
        RecognizeWebImageResponse response = ocrClient.recognizeWebImage(request);
        System.out.println(response.toString());
    } catch (ConnectionException | RequestTimeoutException e) {
        LOGGER.error(e.toString());
    } catch (ServiceResponseException e) {
        LOGGER.error(String.valueOf(e.getHttpStatusCode()));
        LOGGER.error(e.getErrorCode());
        LOGGER.error(e.getErrorMsg());
    }
}

Driver's license recognition

private static void driverLicense(OcrClient ocrClient, String image) {
    RecognizeDriverLicenseRequest request = new RecognizeDriverLicenseRequest();
    DriverLicenseRequestBody body = new DriverLicenseRequestBody();
    body.withReturnIssuingAuthority(true);
    body.withSide("front");
    body.withImage(image);
    request.withBody(body);
    try {
        RecognizeDriverLicenseResponse response = ocrClient.recognizeDriverLicense(request);
        System.out.println(response.toString());
    } catch (ConnectionException | RequestTimeoutException e) {
        LOGGER.error(e.toString());
    } catch (ServiceResponseException e) {
        LOGGER.error(String.valueOf(e.getHttpStatusCode()));
        LOGGER.error(e.getErrorCode());
        LOGGER.error(e.getErrorMsg());
    }
}

Business card recognition

private static void businessCard(OcrClient ocrClient, String image) {
    RecognizeBusinessCardRequest request = new RecognizeBusinessCardRequest();
    BusinessCardRequestBody body = new BusinessCardRequestBody();
    body.withDetectDirection(true);
    body.withImage(image);
    request.withBody(body);
    try {
        RecognizeBusinessCardResponse response = ocrClient.recognizeBusinessCard(request);
        System.out.println(response.toString());
    } catch (ConnectionException | RequestTimeoutException e) {
        LOGGER.error(e.toString());
    } catch (ServiceResponseException e) {
        LOGGER.error(String.valueOf(e.getHttpStatusCode()));
        LOGGER.error(e.getErrorCode());
        LOGGER.error(e.getErrorMsg());
    }
}

Train ticket identification

private static void trainTicket(OcrClient ocrClient, String image) {
    RecognizeTrainTicketRequest request = new RecognizeTrainTicketRequest();
    TrainTicketRequestBody body = new TrainTicketRequestBody();
    body.withImage(image);
    request.withBody(body);
    try {
        RecognizeTrainTicketResponse response = ocrClient.recognizeTrainTicket(request);
        System.out.println(response.toString());
    } catch (ConnectionException | RequestTimeoutException e) {
        LOGGER.error(e.toString());
    } catch (ServiceResponseException e) {
        LOGGER.error(String.valueOf(e.getHttpStatusCode()));
        LOGGER.error(e.getErrorCode());
        LOGGER.error(e.getErrorMsg());
    }
}

VIN code identification

private static void vin(OcrClient ocrClient, String image) {
    RecognizeVinRequest request = new RecognizeVinRequest();
    VinRequestBody body = new VinRequestBody();
    body.withImage(image);
    request.withBody(body);
    try {
        RecognizeVinResponse response = ocrClient.recognizeVin(request);
        System.out.println(response.toString());
    } catch (ConnectionException | RequestTimeoutException e) {
        LOGGER.error(e.toString());
    } catch (ServiceResponseException e) {
        LOGGER.error(String.valueOf(e.getHttpStatusCode()));
        LOGGER.error(e.getErrorCode());
        LOGGER.error(e.getErrorMsg());
    }
}

Passport identification

private static void passport(OcrClient ocrClient, String image) {
    RecognizePassportRequest request = new RecognizePassportRequest();
    PassportRequestBody body = new PassportRequestBody();
    body.withImage(image);
    request.withBody(body);
    try {
        RecognizePassportResponse response = ocrClient.recognizePassport(request);
        System.out.println(response.toString());
    } catch (ConnectionException | RequestTimeoutException e) {
        LOGGER.error(e.toString());
    } catch (ServiceResponseException e) {
        LOGGER.error(String.valueOf(e.getHttpStatusCode()));
        LOGGER.error(e.getErrorCode());
        LOGGER.error(e.getErrorMsg());
    }
}

insurance policy identification

private static void insurancePolicy(OcrClient ocrClient, String image) {
    RecognizeInsurancePolicyRequest request = new RecognizeInsurancePolicyRequest();
    InsurancePolicyRequestBody body = new InsurancePolicyRequestBody();
    body.withDetectDirection(true);
    body.withImage(image);
    request.withBody(body);
    try {
        RecognizeInsurancePolicyResponse response = ocrClient.recognizeInsurancePolicy(request);
        System.out.println(response.toString());
    } catch (ConnectionException | RequestTimeoutException e) {
        LOGGER.error(e.toString());
    } catch (ServiceResponseException e) {
        LOGGER.error(String.valueOf(e.getHttpStatusCode()));
        LOGGER.error(e.getErrorCode());
        LOGGER.error(e.getErrorMsg());
    }
}

Identification of professional qualification certificate

private static void qualificationCertificate(OcrClient ocrClient, String image) {
    RecognizeQualificationCertificateRequest request = new RecognizeQualificationCertificateRequest();
    QualificationCertificateRequestBody body = new QualificationCertificateRequestBody();
    body.withImage(image);
    request.withBody(body);
    try {
        RecognizeQualificationCertificateResponse response = ocrClient.recognizeQualificationCertificate(request);
        System.out.println(response.toString());
    } catch (ConnectionException | RequestTimeoutException e) {
        LOGGER.error(e.toString());
    } catch (ServiceResponseException e) {
       LOGGER.error(String.valueOf(e.getHttpStatusCode()));
       LOGGER.error(e.getErrorCode());
       LOGGER.error(e.getErrorMsg());
    }
}

4 Experience Hall

4.1 General class

4.2 Bills

4.3 Documents

4.4 Industry categories

5 Experience the charm of plug-ins

Huawei Cloud devkit is now online: Toolkit-Huawei Cloud

Guess you like

Origin blog.csdn.net/hwxiaozhi/article/details/133386008