华为云API文字识别 OCR的高效性—AI中名副其实的电子眼
欧界传媒
2023-10-12 04:07:13
0

原标题:华为云API文字识别 OCR的高效性—AI中名副其实的电子眼

云服务、API、SDK,调试,查看,我都行

阅读短文您可以学习到:人工智能AI自言语言的情感分析、文本分词、文本翻译

1IntelliJ IDEAAPI插件介绍

API插件支持 VS Code IDE、IntelliJ IDEA等平台、以及华为云自 CodeArts IDE,基于华为云服务提供的能力,帮助开发者更高效、便捷的搭建应用。API插件关联华为云服务下的 API Explorer、DevStar、CodeLabs、SDK 中心和 CLI 中心产品,致力于为开发者提供更稳定、快速、安全的编程体验。

在本插件中,我们提供了但不局限于如下的功能:

对接华为云API开放平台,支持用户检索API、查看API文档、调试API、以及提供SDK示例代码供用户学习如何使用API。

提供华为云SDK代码片段补全功能,SDK依赖包自动引入,加速用户集成华为云API。

对接华为云开发体验馆Codelabs,提供500+云服务代码示例,向导式教程帮助用户快速学习。

说明:

在IntelliJ IDEA等系列平台和VS Code IDE,华为云API插件的名称是Huawei Cloud API。而在CodeArts IDE,API插件是IDE原生内置的,名称是华为云API开发套件。

API插件在IntelliJ IDEA等系列平台和VS Code IDE的使用依赖底座插件,请提前安装底座插件。

2API插件安装--IntelliJ IDEA

2.1IntelliJ IDEA等平台

安装准备下载并安装JDK1.8或更高版本。下载并安装IntelliJ IDEA 2020.2或更高版本。

须知:IntellIj平台同时支撑包括GolandPycharm等在内的IDE,若在其它相关IDE上开发,请下载配置好对应语言的编译器或者解释器。这里以IDEA为例介绍IntelliJ平台插件的安装流程,其他IntelliJ系列的IDE请参考IDEA

开始安装

您可以在直接在IDE插件市场或者直接在JetBrains插件市场下载离线包安装。

IDE安装

1.IntelliJ IDEA顶部菜单栏中选择File > Settings,在Settings对话框的左侧导航栏中单击Plugins

2.Plugins区域单击Marketplace,在搜索栏中输入Huawei Cloud API

3.Search Results区域会出现Huawei Cloud API,单击Install,完成后重启IDE

离线包安装

1.进入插件市场搜索Huawei Cloud API,进入插件详情页,在Versions页签下选择想要版本的API插件,点击Download下载离线的插件压缩包保存到本地。。

2.IntelliJ IDEA顶部菜单栏中选择File > Settings,在Settings对话框的左侧导航栏中单击Plugins

3.Plugins区域单击,再单击Install Plugin from Disk...

4.Choose Plugin File对话框中选择离线安装包(不用解压),并按照IntelliJ IDEA安装页面的提示,完成后续安装步骤。

说明:若当前您想要安装插件的IntelliJ IDE已经在桌面打开,则进入插件市场搜索Huawei Cloud API,进入插件详情页,在右上角会识别到本地已经打开的IDE,点击相应按钮,在弹出的IDE窗口中点击ok,则IDE后台会开始安装相应版本的API插件。

安装验证IntelliJ系列平台上安装插件成功后在左侧的导航栏中可以看到Huawei Cloud Toolkit图标,点击后面板会出现Huawei Cloud API的字样,则说明安装成功。

2.2API列表

左侧展示API列表,可以查询所有API,目前云服务206APIs9213

华为云提供了文字识别服务端SDK,您可以直接集成服务端SDK来调用文字识别服务的相关API,从而实现对文字识别服务的快速操作。

该示例展示了如何通过goSDK实现文字识别。

前期准备:

已注册华为云,并完成实名认证

已订阅文字识别服务。

已具备开发环境,支持go 1.14及其以上版本。

已获取华为云账号对应的Access KeyAK)和Secret Access KeySK)。请在华为云控制台“我的凭证 >访问密钥”页面上创建和查看您AK/SK。具体请参见访问密钥https://support.huaweicloud.com/usermanual-ca/zh-cn_topic_0046606340.html

已获取文字识别服务对应区域的项目ID,请在华为云控制台“我的凭证 > API凭证”页面上查看项目ID。具体请参见 API凭证。https://support.huaweicloud.com/usermanual-ca/ca_01_0002.html

环境配置

// 启用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/signer@v0.1.2

go get github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/provider@v0.1.2

go get github.com/huaweicloud/huaweicloud-sdk-go-v3/core/region@v0.1.2

3AI文字识别服务文字识别示例

3.1go版本

导入依赖模块

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"

)

初始化认证信息以及文字识别服务的客户端

ak := ""

sk := ""

regionName := ""

image := ""

// 初始化认证信息

auth := basic.NewCredentialsBuilder().

WithAk(ak).

WithSk(sk).

Build()

// 获取服务调用client

client := ocr.NewOcrClient(

ocr.OcrClientBuilder().

WithRegion(region.ValueOf(regionName)).

WithCredential(auth).

Build())

相关参数说明如下

ak:华为云账号Access Key

sk:华为云账号Secret Access Key

service region: 服务所在区域名称,例如:

cn-north-1 北京一

cn-north-4 北京四

CN_EAST_3 上海一

CN_SOUTH_1 华南广州

6.SDK demo代码解析

通用文字识别

request := &model.RecognizeGeneralTextRequest{}

quickModeGeneralTextRequestBody := true

detectDirectionGeneralTextRequestBody := true

imageGeneralTextRequestBody := image

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)

}

通用表格识别

request := &model.RecognizeGeneralTableRequest{}

returnExcelGeneralTableRequestBody := true

returnConfidenceGeneralTableRequestBody := true

returnTextLocationGeneralTableRequestBody := true

imageGeneralTableRequestBody := image

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)

}

身份证识别

request := &model.RecognizeIdCardRequest{}

returnVerificationIdCardRequestBody := true

sideIdCardRequestBody := "front"

imageIdCardRequestBody := image

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)

}

银行卡识别

request := &model.RecognizeBankcardRequest{}

imageBankcardRequestBody := image

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 := image

request.Body = &model.AutoClassificationRequestBody{

Image: &imageAutoClassificationRequestBody,

}

response, err := client.RecognizeAutoClassification(request)

if err == nil {

fmt.Printf("%+v\n", response)

} else {

fmt.Println(err)

}

增值税发票识别

request := &model.RecognizeVatInvoiceRequest{}

advancedModeVatInvoiceRequestBody := true

imageVatInvoiceRequestBody := image

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)

}

定额发票识别

request := &model.RecognizeQuotaInvoiceRequest{}

imageQuotaInvoiceRequestBody := image

request.Body = &model.QuotaInvoiceRequestBody{

Image: &imageQuotaInvoiceRequestBody,

}

response, err := client.RecognizeQuotaInvoice(request)

if err == nil {

fmt.Printf("%+v\n", response)

} else {

fmt.Println(err)

}

手写文字识别

request := &model.RecognizeHandwritingRequest{}

detectDirectionHandwritingRequestBody := true

charSetHandwritingRequestBody := "digit"

quickModeHandwritingRequestBody := true

imageHandwritingRequestBody := image

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)

}

行驶证识别

request := &model.RecognizeVehicleLicenseRequest{}

returnIssuingAuthorityVehicleLicenseRequestBody := true

sideVehicleLicenseRequestBody := "front"

imageVehicleLicenseRequestBody := image

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)

}

道路运输证识别

request := &model.RecognizeTransportationLicenseRequest{}

imageTransportationLicenseRequestBody := image

request.Body = &model.TransportationLicenseRequestBody{

Image: &imageTransportationLicenseRequestBody,

}

response, err := client.RecognizeTransportationLicense(request)

if err == nil {

fmt.Printf("%+v\n", response)

} else {

fmt.Println(err)

}

出租车发票识别

request := &model.RecognizeTaxiInvoiceRequest{}

imageTaxiInvoiceRequestBody := image

request.Body = &model.TaxiInvoiceRequestBody{

Image: &imageTaxiInvoiceRequestBody,

}

response, err := client.RecognizeTaxiInvoice(request)

if err == nil {

fmt.Printf("%+v\n", response)

} else {

fmt.Println(err)

}

车辆通行费发票识别

request := &model.RecognizeTollInvoiceRequest{}

imageTollInvoiceRequestBody := image

request.Body = &model.TollInvoiceRequestBody{

Image: &imageTollInvoiceRequestBody,

}

response, err := client.RecognizeTollInvoice(request)

if err == nil {

fmt.Printf("%+v\n", response)

} else {

fmt.Println(err)

}

机动车销售发票识别

request := &model.RecognizeMvsInvoiceRequest{}

imageMvsInvoiceRequestBody := image

request.Body = &model.MvsInvoiceRequestBody{

Image: &imageMvsInvoiceRequestBody,

}

response, err := client.RecognizeMvsInvoice(request)

if err == nil {

fmt.Printf("%+v\n", response)

} else {

fmt.Println(err)

}

车牌识别

request := &model.RecognizeLicensePlateRequest{}

imageLicensePlateRequestBody := image

request.Body = &model.LicensePlateRequestBody{

Image: &imageLicensePlateRequestBody,

}

response, err := client.RecognizeLicensePlate(request)

if err == nil {

fmt.Printf("%+v\n", response)

} else {

fmt.Println(err)

}

飞机行程单识别

request := &model.RecognizeFlightItineraryRequest{}

imageFlightItineraryRequestBody := image

request.Body = &model.FlightItineraryRequestBody{

Image: &imageFlightItineraryRequestBody,

}

response, err := client.RecognizeFlightItinerary(request)

if err == nil {

fmt.Printf("%+v\n", response)

} else {

fmt.Println(err)

}

营业执照识别

request := &model.RecognizeBusinessLicenseRequest{}

imageBusinessLicenseRequestBody := image

request.Body = &model.BusinessLicenseRequestBody{

Image: &imageBusinessLicenseRequestBody,

}

response, err := client.RecognizeBusinessLicense(request)

if err == nil {

fmt.Printf("%+v\n", response)

} else {

fmt.Println(err)

}

网络图片识别

request := &model.RecognizeWebImageRequest{}

var listExtractTypebody = []string{

"contact_info",

"image_size",

}

detectDirectionWebImageRequestBody := true

imageWebImageRequestBody := image

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)

}

驾驶证识别

request := &model.RecognizeDriverLicenseRequest{}

returnIssuingAuthorityDriverLicenseRequestBody := true

sideDriverLicenseRequestBody := "front"

imageDriverLicenseRequestBody := image

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)

}

名片识别

request := &model.RecognizeBusinessCardRequest{}

returnAdjustedImageBusinessCardRequestBody := true

detectDirectionBusinessCardRequestBody := true

imageBusinessCardRequestBody := image

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)

}

火车票识别

request := &model.RecognizeTrainTicketRequest{}

imageTrainTicketRequestBody := image

request.Body = &model.TrainTicketRequestBody{

Image: &imageTrainTicketRequestBody,

}

response, err := client.RecognizeTrainTicket(request)

if err == nil {

fmt.Printf("%+v\n", response)

} else {

fmt.Println(err)

}

VIN码识别

request := &model.RecognizeVinRequest{}

imageVinRequestBody := image

request.Body = &model.VinRequestBody{

Image: &imageVinRequestBody,

}

response, err := client.RecognizeVin(request)

if err == nil {

fmt.Printf("%+v\n", response)

} else {

fmt.Println(err)

}

护照识别

request := &model.RecognizePassportRequest{}

imagePassportRequestBody := image

request.Body = &model.PassportRequestBody{

Image: &imagePassportRequestBody,

}

response, err := client.RecognizePassport(request)

if err == nil {

fmt.Printf("%+v\n", response)

} else {

fmt.Println(err)

}

保险单卡识别

request := &model.RecognizeInsurancePolicyRequest{}

detectDirectionInsurancePolicyRequestBody := true

imageInsurancePolicyRequestBody := image

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)

}

道路运输从业资格证识别

request := &model.RecognizeQualificationCertificateRequest{}

imageQualificationCertificateRequestBody := image

request.Body = &model.QualificationCertificateRequestBody{

Image: &imageQualificationCertificateRequestBody,

}

response, err := client.RecognizeQualificationCertificate(request)

if err == nil {

fmt.Printf("%+v\n", response)

} else {

fmt.Println(err)

}

3.2python版本

开始使用

导入依赖模块

from huaweicloudsdkcore.auth.credentials import BasicCredentials

from huaweicloudsdkocr.v1.region.ocr_region import OcrRegion

from huaweicloudsdkcore.exceptions import exceptions

from huaweicloudsdkocr.v1 import *

初始化认证信息

def get_credential():

return BasicCredentials(ak, sk)

相关参数说明如下所示:

ak:华为云账号Access Key

sk:华为云账号Secret Access Key

初始化文字识别服务的客户端

def get_client():

return OcrClient.new_builder(OcrClient)

.with_credentials(credentials)

.with_region(OcrRegion.CN_NORTH_4)

.build()

相关参数说明如下所示:

service region: 服务所在区域,例如:

CN_NORTH_1 北京一

CN_NORTH_4 北京四

CN_EAST_3 上海一

CN_SOUTH_1 华南广州

SDK demo代码解析

通用文字识别

def recognize_general_text_request():

try:

request = RecognizeGeneralTextRequest()

request.body = GeneralTextRequestBody(

image=image_

)

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)

通用表格识别

def recognize_general_table_request():

try:

request = RecognizeGeneralTableRequest()

request.body = GeneralTableRequestBody(

image=image_

)

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)

身份证识别

def recognize_id_card_request():

try:

request = RecognizeIdCardRequest()

request.body = IdCardRequestBody(

image=image_

)

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)

银行卡识别

def recognize_bankcard_request():

try:

request = RecognizeBankcardRequest()

request.body = BankcardRequestBody(

image=image_

)

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)

智能分类识别

def recognize_auto_classification_request():

try:

request = RecognizeAutoClassificationRequest()

request.body = AutoClassificationRequestBody(

image=image_

)

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)

增值税发票识别

def recognize_vat_invoice_request():

try:

request = RecognizeVatInvoiceRequest()

request.body = VatInvoiceRequestBody(

image=image_

)

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)

定额发票识别

def recognize_quota_invoice_request():

try:

request = RecognizeQuotaInvoiceRequest()

request.body = QuotaInvoiceRequestBody(

image=image_

)

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)

手写文字识别

def recognize_handwriting_request():

try:

request = RecognizeHandwritingRequest

request.body = HandwritingRequestBody(

image=image_

)

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)

行驶证识别

def recognize_vehicle_license_request():

try:

request = RecognizeIdCardRequest()

request.body = VehicleLicenseRequestBody(

image=image_

)

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)

道路运输证识别

def recognize_transportation_license_request():

try:

request = RecognizeTransportationLicenseRequest()

request.body = TransportationLicenseRequestBody(

image=image_

)

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)

出租车发票识别

def recognize_taxi_invoice_request():

try:

request = RecognizeTaxiInvoiceRequest()

request.body = TaxiInvoiceRequestBody(

image=image_

)

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)

车辆通行费发票识别

def recognize_toll_invoice_request():

try:

request = RecognizeTollInvoiceRequest()

request.body = TollInvoiceRequestBody(

image=image_

)

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)

机动车销售发票识别

def recognize_mvs_invoice_request():

try:

request = RecognizeMvsInvoiceRequest()

request.body = MvsInvoiceRequestBody(

image=image_

)

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)

车牌识别

def recognize_license_plate_request():

try:

request = RecognizeLicensePlateRequest()

request.body = LicensePlateRequestBody(

image=image_

)

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)

飞机行程单识别

def recognize_flight_itinerary_request():

try:

request = RecognizeFlightItineraryRequest()

request.body = FlightItineraryRequestBody(

image=image_

)

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)

营业执照识别

def recognize_business_license_request():

try:

request = RecognizeBusinessLicenseRequest()

request.body = BusinessLicenseRequestBody(

image=image_

)

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)

网络图片识别

def recognize_web_image_request():

try:

request = RecognizeWebImageRequest()

request.body = WebImageRequestBody(

image=image_

)

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)

驾驶证识别

def recognize_driver_license_request():

try:

request = RecognizeDriverLicenseRequest()

request.body = DriverLicenseRequestBody(

image=image_

)

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)

名片识别

def recognize_business_card_request():

try:

request = RecognizeBusinessCardRequest()

request.body = BusinessCardRequestBody(

image=image_

)

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)

火车票识别

def recognize_train_ticket_request():

try:

request = RecognizeTrainTicketRequest()

request.body = TrainTicketRequestBody(

image=image_

)

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码识别

def recognize_vin_request():

try:

request = RecognizeVinRequest()

request.body = VinRequestBody(

image=image_

)

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)

护照识别

def recognize_passport_request():

try:

request = RecognizePassportRequest()

request.body = PassportRequestBody(

image=image_

)

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)

保险单识别

def recognize_insurance_policy_request():

try:

request = RecognizeInsurancePolicyRequest()

request.body = InsurancePolicyRequestBody(

image=image_

)

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)

道路运输从业资格证识别

def recognize_transportation_qualification_certificate_request():

try:

request = RecognizeQualificationCertificateRequest()

request.body = QualificationCertificateRequestBody(

image=image_

)

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.3java版本

开始使用

导入依赖模块

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.*;

初始化认证信息

public static ICredential getCredential(String ak, String sk) {

return new BasicCredentials().withAk(ak).withSk(sk);

}

相关参数说明如下所示:

ak:华为云账号Access Key

sk:华为云账号Secret Access Key

初始化文字识别服务的客户端

public static OcrClient getClient(Region region, ICredential auth) {

return OcrClient.newBuilder().withCredential(auth).withRegion(region).build();

}

相关参数说明如下所示:

service region: 服务所在区域,例如:

CN_NORTH_1 北京一

CN_NORTH_4 北京四

CN_EAST_3 上海一

CN_SOUTH_1 华南广州

SDK demo代码解析

通用文字识别

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());

}

}

通用表格识别

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());

}

}

身份证识别

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());

}

}

银行卡识别

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());

}

}

智能分类识别

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());

}

}

增值税发票识别

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());

}

}

定额发票识别

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());

}

}

手写文字识别

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());

}

}

行驶证识别

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());

}

}

道路运输证识别

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());

}

}

出租车发票识别

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());

}

}

车辆通行费发票识别

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());

}

}

机动车销售发票识别

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());

}

}

车牌识别

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());

}

}

飞机行程单识别

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());

}

}

营业执照识别

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());

}

}

网络图片识别

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());

}

}

驾驶证识别

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());

}

}

名片识别

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());

}

}

火车票识别

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码识别

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());

}

}

护照识别

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());

}

}

保险单识别

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());

}

}

从业资格证识别

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体验馆

4.1通用类

4.2票据类

4.3证件类

4.4行业类

体验插件更多插件参考插件超市

相关内容

热门资讯

重大通报正版房卡批发大厅,正规... i不仅影像能力再度突破,还都适配了鸿蒙OS3.1,甚至原本单向的北斗卫星消息如今也升级为了双向,既能...
重大发现斗牛房卡批发价,牛牛房... 0iPhone 14Pro版的两款将会采用全新的“感叹号”打孔设计,处理器为A16仿生,支持120H...
重大来袭牛牛卖房卡多少钱一张,... 9eETDiPhone 14沿袭了iPhone 13设计风格,搭配了一块刘海屏风格的6.1英寸OLE...
一分钟揭秘斗牛房卡多少钱一张,... PRXbhGW因此整个手机看起来非常的好看。在参数方面,据悉该机采用了5000万像素大底主摄+320...
我来告诉你美猴王牛牛房卡哪里买... n不过新机还未确定发布时间,现在想要换手机的用户,可以看看这款OPPO Reno9手机,是一款才发布...
一分钟揭秘牛牛房卡最低价格,正... hoS从核心配置来看,这款OPPO Reno10新机将搭载高通骁龙7+gen2旗舰级处理器,采用了更...
实测分享微信房卡神兽大厅,牛牛... n尤其是高通骁龙7+ Gen2以及IP68等核心硬件和技术的加入,使得该机的综合硬件配置诚意满满。如...
玩家实测牛牛卖房卡多少钱一张,... IySk此次华为旗舰新品发布会不仅有三款华为P60系列旗舰,而且还有华为折叠屏新机华为Mate X3...
科技通报金花房卡在哪买,牛牛房... V0bdz而且有消息称iPhone14系列中的标准版和新增的Max版本都将搭载A15处理器,又或者是...
实测分享牛牛充值房卡,牛牛房卡... n在摄像头方面,这款realme GT3采用了后置三摄的设计,后置三摄布局在手机背部中间靠顶部的唯一...
实测分享牛牛卖房卡多少钱一张,... j.延续了几代的刘海屏也将会被抛弃,采用了全新的“感叹号”屏。以前一直觉得iPhone产品的刘海屏丑...
重大来袭斗牛房卡批发价,牛牛房... m9I8从相机配置来看,这款OPPO Reno10新机采用了后置四摄的设计方案,分别由一英寸大底主摄...
我来教你牛牛房卡卖家联系方式,... B1f在血雨腥风的手机市场,一款产品要想存活下来,就一定要有差异化的产品设计。摩托罗拉手机是一个大家...
我来教你微信怎么开斗牛房间链接... BRZYnR对于预算不算充足或者说对14系列不满意的朋友来说,如今正在打折促销的苹果手机产品都是值得...
重大发现金花房卡购买联系方式,... as而且,iPhone14系列所搭载的处理器也是传出了消息,即使苹果A系列处理器的性能已经和高通骁龙...
实测分享牛牛房卡哪家便宜,牛牛... hoN0RZ苹果手机虽然备受消费者的欢迎,同时也搭载的是自研的iOS系统,但是在很多方面,苹果也借鉴...
推荐一款正规房卡链接在哪购买,... jze尽管目前距离 iPhone 15 系列的亮相还有很长一段时间,但按照以往的惯例,该系列新机势必...
重大发现微信房卡神兽大厅,正规... PGmrX当然,行业在发展,相信在接下来realme手机会再接再厉,为行业带来更有竞争力的产品。网上...
一分钟揭秘牛牛怎么建房间,牛牛... n最核心的处理器,其实真没必要多讲,iPhone13搭载A15芯片,尽管是“阉割版”,但依旧是行业顶...
重大来袭金花房卡批发,金花房卡... IlV苹果已正式确实了秋季新品发布会的日期,将于9月13日正式举办该活动,可信度还是极高的。同时,还...