更新时间:2024-01-11 gmt 08:00

飞机行程单识别-凯发k8国际娱乐官网入口

功能介绍

识别飞机行程单中的文字信息,并以json格式返回识别的结构化结果。该接口的使用限制请参见约束与限制,详细使用指导请参见ocr服务使用简介章节。

图1 飞机行程单示例图

如果图片中包含多张卡证票据,请调用智能分类识别服务。

约束与限制

  • 支持识别png、jpg、jpeg、bmp、tiff格式的图片。
  • 图像各边的像素大小在15px到8192px之间。
  • 支持图像中行程单任意角度的水平旋转。
  • 能处理反光、暗光等干扰的图片但影响识别精度。

调用方法

请参见。

前提条件

在使用之前,需要您完成服务申请和认证鉴权,具体操作流程请参见开通服务和章节。

用户首次使用需要先。服务只需要开通一次即可,后面使用时无需再次申请。如未开通服务,调用服务时会提示modelarts.4204报错,请在调用服务前先进入控制台开通服务,并注意开通服务区域与调用服务的区域保持一致。

uri

post /v2/{project_id}/ocr/flight-itinerary

表1 路径参数

参数

是否必选

说明

endpoint

终端节点,即调用api的请求地址。

不同服务不同区域的endpoint不同,您可以从中获取。

例如,ocr服务在“华北-北京四”区域的“endpoint”“ocr.cn-north-4.myhuaweicloud.com”

project_id

项目id,您可以从中获取。

请求参数

表2 请求header参数

参数

是否必选

参数类型

描述

x-auth-token

string

用户token。

用于获取操作api的权限。响应消息头中x-subject-token的值即为token。

content-type

string

发送的实体的mime类型,参数值为“application/json”。

enterprise-project-id

string

企业项目id。ocr支持通过企业项目管理(eps)对不同用户组和用户的资源使用,进行分账。

获取方法:进入“”页面,单击企业项目名称,在企业项目详情页获取enterprise-project-id(企业项目id)。

企业项目创建步骤请参见用户指南。

说明:

创建企业项目后,在传参时,有以下三类场景。

  • 携带正确的id,正常使用ocr服务,账单归到企业id对应的企业项目中。
  • 携带错误的id,正常使用ocr服务,账单的企业项目会被分类为“未归集”。
  • 不携带id,正常使用ocr服务,账单的企业项目会被分类为“未归集”。
表3 请求body参数

参数

是否必选

参数类型

说明

image

string

该参数与url二选一。

图片的base64编码,要求base64编码后大小不超过10mb。

图片最短边不小于15px,最长边不超过8192px,支持jpeg、jpg、png、bmp、tiff格式。

图片base64编码示例如/9j/4aaqskzjrgabag...,带有多余前缀会产生the image format is not supported报错。

url

string

该参数与image二选一。图片的url路径,目前支持:

  • 公网http/https url
  • obs提供的url,使用obs数据需要进行授权。包括对服务授权、临时授权、匿名公开授权,详情参见。
说明:
  • 接口响应时间依赖于图片的下载时间,如果图片下载时间过长,会返回接口调用失败。
  • 请保证被检测图片所在的存储服务稳定可靠,推荐使用obs服务存储图片数据。
  • url中不能存在中文字符,若存在,中文需要进行utf8编码。

响应参数

根据识别的结果,可能有不同的http响应状态码(status code)。例如,200表示api调用成功,400表示调用失败,详细的状态码和响应参数说明如下。

状态码: 200

表4 响应body参数

参数

参数类型

描述

result

flightitineraryresult object

识别结果。

调用失败时不返回此字段。

表5 flightitineraryresult

参数

参数类型

描述

serial_number

string

印刷序号。

passenger_name

string

旅客姓名。

id_number

string

有效身份证件号码。

endorsements_restrictions

string

备注。

order_number

string

订单号。

fare

string

票价。

caac_development_fund

string

民航(caac)发展基金。

fuel_surcharge

string

燃油附加费。

other_taxes

string

其他税费。

total

string

合计。

e_ticket_number

string

电子客票号码。

check_code

string

验证码。

reference_information

string

提示信息。

insurance

string

保险费。

agent_code

string

销售单位代号。

issue_organization

string

填开单位。

issue_date

string

填开日期。

itinerary_list

array of itinerarylist objects

机票行程列表。

confidence

object

字段的置信度,取值范围0~1。

置信度越大,本次识别的字段的可靠性越高,在统计意义上,置信度越大,准确率越高。

置信度由算法给出,不直接等价于字段的准确率。

表6 itinerarylist

参数

参数类型

描述

departure_station

string

始发站。

destination_station

string

目的站。

carrier

string

承运人。

flight

string

航班号。

cabin_class

string

座位等级。

date

string

日期。

time

string

时间。

fare_basis

string

客票类别。

effective_date

string

客票生效日期。

expiry_date

string

有效截止日期。

baggage_allowance

string

免费行李。

状态码: 400

表7 响应body参数

参数

参数类型

说明

error_code

string

调用失败时的错误码,具体请参见。

当出现错误码“modelarts.4204”时,请参考为什么调用api时提示“modelarts.4204”?章节。

调用成功时不返回此字段。

error_msg

string

调用失败时返回的错误信息。

调用成功时不返回此字段。

请求示例

  • “endpoint”即调用api的请求地址,不同服务不同区域的“endpoint”不同,具体请参见。

    例如,飞机行程单识别服务部署在“华北-北京四”区域的“endpoint”“ocr.cn-north-4.myhuaweicloud.com”“ocr.cn-north-4.myhuaweicloud.cn”,请求url为“https://ocr.cn-north-4.myhuaweicloud.com/v2/{project_id}/ocr/flight-itinerary”“project_id”为项目id,获取方法请参见

  • 如何获取token请参见。
  • 传入飞机行程单图片的base64编码进行文字识别
    post  https://{endpoint}/v2/{project_id}/ocr/flight-itinerary 
    request header:
    content-type: application/json
    x-auth-token: miinrwyjkozihvcnaqccoiinodccdtqcaqexdtalbglghkgbzqmeagewgguvbgkqhkig...
    request body: 
    {
        "image":"/9j/4aaqskzjrgabageasabiaad/4rfzrxhpzgaatu0akgaaaa..."
    }
  • 传入飞机行程单图片的url进行文字识别
    post  https://{endpoint}/v2/{project_id}/ocr/flight-itinerary 
    request header:
    content-type: application/json
    x-auth-token: miinrwyjkozihvcnaqccoiinodccdtqcaqexdtalbglghkgbzqmeagewgguvbgkqhkig...
    request body: 
    {
        "url":"https://bucketname.obs.xxxx.com/objectname"
    }

响应示例

状态码:200

成功响应示例

{
   "result": {
        "serial_number": "12xxxxxxx22", 
        "passenger_name": "wang/san", 
        "id_number": "gxxxxxx08", 
        "endorsements_restrictions": "q/不得签转/退改收费", 
        "fare": "cny 2340.00", 
        "caac_development_fund": "cn 100.00", 
        "fuel_surcharge": "xxxx", 
        "other_taxes": "", 
        "total": "cny 2440.00", 
        "e_ticket_number": "73xxxxxxxx008", 
        "check_code": "3xxx", 
        "reference_information": "白云机场起飞前45分停办值机", 
        "insurance": "xxx", 
        "agent_code": "sxxxxx 00xxxx66", 
        "issue_organization": "xx航空股份有限公司", 
        "issue_date": "2017-12-27", 
        "itinerary_list": [
            {
                "departure_station": "t2上海虹桥", 
                "destination_station": "广州", 
                "carrier": "x航", 
                "flight": "xxxxxx", 
                "cabin_class": "b", 
                "date": "2017-12-27", 
                "time": "13:00", 
                "fare_basis": "b", 
                "effective_date": "", 
                "expiry_date": "", 
                "baggage_allowance": "20k"
            }, 
            {
                "departure_station": "广州", 
                "destination_station": "上海虹桥", 
                "carrier": "xxxx", 
                "flight": "xxxxxx", 
                "cabin_class": "b", 
                "date": "2017-12-29", 
                "time": "16:30", 
                "fare_basis": "b", 
                "effective_date": "", 
                "expiry_date": "", 
                "baggage_allowance": "20k"
            }
        ], 
        "confidence":{
                "serial_number": 0.9993, 
                "passenger_name": 0.9851, 
                "id_number": 0.9836, 
                "endorsements_restrictions": 0.998, 
                "fare": 0.9882, 
                "caac_development_fund": 0.993, 
                "fuel_surcharge": 0.9968, 
                "other_taxes": 0, 
                "total": 0.9999, 
                "e_ticket_number": 0.9631, 
                "check_code": 0.9985, 
                "reference_information": 0.9982, 
                "insurance": 0.7749, 
                "agent_code": 0.9913, 
                "issue_organization": 0.7142, 
                "issue_date": 0.9936, 
                "itinerary_list": [
                    {
                        "departure_station": 0.9987, 
                        "destination_station": 0.9577, 
                        "carrier": 0.9677, 
                        "flight": 0.9957, 
                        "cabin_class": 0.8744, 
                        "date": 0.9993, 
                        "time": 0.9978, 
                        "fare_basis": 0.4006, 
                        "effective_date": 0, 
                        "expiry_date": 0, 
                        "baggage_allowance": 0.9897
                    }, 
                    {
                        "departure_station": 0.9995, 
                        "destination_station": 0.9844, 
                        "carrier": 0.9763, 
                        "flight": 0.7453, 
                        "cabin_class": 0.4239, 
                        "date": 0.76, 
                        "time": 0.7311, 
                        "fare_basis": 0.4353, 
                        "effective_date": 0, 
                        "expiry_date": 0, 
                        "baggage_allowance": 0.5265
                    }
                ]
        }
    }
}

状态码:400

失败响应示例

{
    "error_code": "ais.0103", 
    "error_msg": "the image size does not meet the requirements." 
}

sdk代码示例

sdk代码示例如下。

  • 传入飞机行程单图片的base64编码进行文字识别
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    package com.huaweicloud.sdk.test;
    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 class recognizeflightitinerarysolution {
        public static void main(string[] args) {
            // the ak and sk used for authentication are hard-coded or stored in plaintext, which has great security risks. it is recommended that the ak and sk be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
            // in this example, ak and sk are stored in environment variables for authentication. before running this example, set environment variables cloud_sdk_ak and cloud_sdk_sk in the local environment
            string ak = system.getenv("cloud_sdk_ak");
            string sk = system.getenv("cloud_sdk_sk");
            icredential auth = new basiccredentials()
                    .withak(ak)
                    .withsk(sk);
            ocrclient client = ocrclient.newbuilder()
                    .withcredential(auth)
                    .withregion(ocrregion.valueof(""))
                    .build();
            recognizeflightitineraryrequest request = new recognizeflightitineraryrequest();
            flightitineraryrequestbody body = new flightitineraryrequestbody();
            body.withimage("/9j/4aaqskzjrgabageasabiaad/4rfzrxhpzgaatu0akgaaaa...");
            request.withbody(body);
            try {
                recognizeflightitineraryresponse response = client.recognizeflightitinerary(request);
                system.out.println(response.tostring());
            } catch (connectionexception e) {
                e.printstacktrace();
            } catch (requesttimeoutexception e) {
                e.printstacktrace();
            } catch (serviceresponseexception e) {
                e.printstacktrace();
                system.out.println(e.gethttpstatuscode());
                system.out.println(e.getrequestid());
                system.out.println(e.geterrorcode());
                system.out.println(e.geterrormsg());
            }
        }
    }
    
  • 传入飞机行程单图片的url进行文字识别
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    package com.huaweicloud.sdk.test;
    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 class recognizeflightitinerarysolution {
        public static void main(string[] args) {
            // the ak and sk used for authentication are hard-coded or stored in plaintext, which has great security risks. it is recommended that the ak and sk be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
            // in this example, ak and sk are stored in environment variables for authentication. before running this example, set environment variables cloud_sdk_ak and cloud_sdk_sk in the local environment
            string ak = system.getenv("cloud_sdk_ak");
            string sk = system.getenv("cloud_sdk_sk");
            icredential auth = new basiccredentials()
                    .withak(ak)
                    .withsk(sk);
            ocrclient client = ocrclient.newbuilder()
                    .withcredential(auth)
                    .withregion(ocrregion.valueof(""))
                    .build();
            recognizeflightitineraryrequest request = new recognizeflightitineraryrequest();
            flightitineraryrequestbody body = new flightitineraryrequestbody();
            body.withurl("https://bucketname.obs.myhuaweicloud.com/objectname");
            request.withbody(body);
            try {
                recognizeflightitineraryresponse response = client.recognizeflightitinerary(request);
                system.out.println(response.tostring());
            } catch (connectionexception e) {
                e.printstacktrace();
            } catch (requesttimeoutexception e) {
                e.printstacktrace();
            } catch (serviceresponseexception e) {
                e.printstacktrace();
                system.out.println(e.gethttpstatuscode());
                system.out.println(e.getrequestid());
                system.out.println(e.geterrorcode());
                system.out.println(e.geterrormsg());
            }
        }
    }
    
  • 传入飞机行程单图片的base64编码进行文字识别
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    # coding: utf-8
    from huaweicloudsdkcore.auth.credentials import basiccredentials
    from huaweicloudsdkocr.v1.region.ocr_region import ocrregion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkocr.v1 import *
    if __name__ == "__main__":
        # the ak and sk used for authentication are hard-coded or stored in plaintext, which has great security risks. it is recommended that the ak and sk be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        # in this example, ak and sk are stored in environment variables for authentication. before running this example, set environment variables cloud_sdk_ak and cloud_sdk_sk in the local environment
        ak = os.getenv("cloud_sdk_ak")
        sk = os.getenv("cloud_sdk_sk")
        credentials = basiccredentials(ak, sk) \
        client = ocrclient.new_builder() \
            .with_credentials(credentials) \
            .with_region(ocrregion.value_of("")) \
            .build()
        try:
            request = recognizeflightitineraryrequest()
            request.body = flightitineraryrequestbody(
                image="/9j/4aaqskzjrgabageasabiaad/4rfzrxhpzgaatu0akgaaaa..."
            )
            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)
    
  • 传入飞机行程单图片的url进行文字识别
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    # coding: utf-8
    from huaweicloudsdkcore.auth.credentials import basiccredentials
    from huaweicloudsdkocr.v1.region.ocr_region import ocrregion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkocr.v1 import *
    if __name__ == "__main__":
        # the ak and sk used for authentication are hard-coded or stored in plaintext, which has great security risks. it is recommended that the ak and sk be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        # in this example, ak and sk are stored in environment variables for authentication. before running this example, set environment variables cloud_sdk_ak and cloud_sdk_sk in the local environment
        ak = os.getenv("cloud_sdk_ak")
        sk = os.getenv("cloud_sdk_sk")
        credentials = basiccredentials(ak, sk) \
        client = ocrclient.new_builder() \
            .with_credentials(credentials) \
            .with_region(ocrregion.value_of("")) \
            .build()
        try:
            request = recognizeflightitineraryrequest()
            request.body = flightitineraryrequestbody(
                url="https://bucketname.obs.myhuaweicloud.com/objectname"
            )
            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)
    
  • 传入飞机行程单图片的base64编码进行文字识别
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    package main
    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"
    )
    func main() {
        // the ak and sk used for authentication are hard-coded or stored in plaintext, which has great security risks. it is recommended that the ak and sk be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // in this example, ak and sk are stored in environment variables for authentication. before running this example, set environment variables cloud_sdk_ak and cloud_sdk_sk in the local environment
        ak := os.getenv("cloud_sdk_ak")
        sk := os.getenv("cloud_sdk_sk")
        auth := basic.newcredentialsbuilder().
            withak(ak).
            withsk(sk).
            build()
        client := ocr.newocrclient(
            ocr.ocrclientbuilder().
                withregion(region.valueof("")).
                withcredential(auth).
                build())
        request := &model.recognizeflightitineraryrequest{}
    	imageflightitineraryrequestbody:= "/9j/4aaqskzjrgabageasabiaad/4rfzrxhpzgaatu0akgaaaa..."
    	request.body = &model.flightitineraryrequestbody{
    		image: &imageflightitineraryrequestbody,
    	}
    	response, err := client.recognizeflightitinerary(request)
    	if err == nil {
            fmt.printf("% v\n", response)
        } else {
            fmt.println(err)
        }
    }
    
  • 传入飞机行程单图片的url进行文字识别
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    package main
    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"
    )
    func main() {
        // the ak and sk used for authentication are hard-coded or stored in plaintext, which has great security risks. it is recommended that the ak and sk be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // in this example, ak and sk are stored in environment variables for authentication. before running this example, set environment variables cloud_sdk_ak and cloud_sdk_sk in the local environment
        ak := os.getenv("cloud_sdk_ak")
        sk := os.getenv("cloud_sdk_sk")
        auth := basic.newcredentialsbuilder().
            withak(ak).
            withsk(sk).
            build()
        client := ocr.newocrclient(
            ocr.ocrclientbuilder().
                withregion(region.valueof("")).
                withcredential(auth).
                build())
        request := &model.recognizeflightitineraryrequest{}
    	urlflightitineraryrequestbody:= "https://bucketname.obs.myhuaweicloud.com/objectname"
    	request.body = &model.flightitineraryrequestbody{
    		url: &urlflightitineraryrequestbody,
    	}
    	response, err := client.recognizeflightitinerary(request)
    	if err == nil {
            fmt.printf("% v\n", response)
        } else {
            fmt.println(err)
        }
    }
    

更多编程语言的sdk代码示例,请参见的代码示例页签,可生成自动对应的sdk代码示例。

状态码

状态码

描述

200

成功响应样例

400

失败响应样例

状态码请参见。

错误码

错误码请参见。

分享:
网站地图