智能证件分类
功能介绍
支持9类证件的分类和告警检测,以JSON格式返回结果。支持的证件类型有秘鲁身份证、柬文身份证、香港身份证、澳门身份证、缅文身份证、缅文驾驶证、泰文身份证、护照和中华人民共和国居民身份证。
调用方法
请参见如何调用API。
URI
POST /v2/{project_id}/ocr/auto-id-doc-classification
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
project_id |
是 |
String |
项目ID,您可以从获取项目ID中获取。 |
请求参数
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
X-Auth-Token |
是 |
String |
用户Token。 用于获取操作API的权限。获取Token接口响应消息头中X-Subject-Token的值即为Token。 |
Enterprise-Project-Id |
否 |
String |
企业项目ID。OCR支持通过企业项目管理(EPS)对不同用户组和用户的资源使用,进行分账。 获取方法:进入“企业项目管理”页面,单击企业项目名称,在企业项目详情页获取Enterprise-Project-Id(企业项目ID)。 企业项目创建步骤请参见用户指南。
说明:
说明: 创建企业项目后,在传参时,有以下三类场景。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
data |
否 |
String |
该参数与url二选一。 图片的Base64编码,单个图片其对应的Base64编码不超过10MB。文件在Base64编码后会大于文件原本大小,请注意做好边界判断,建议图片大小不超过7MB。 图片尺寸不小于15px,最长边不超过8192px,支持JPEG/JPG/PNG/BMP/TIFF格式。 图片Base64编码示例如/9j/4AAQSkZJRgABAg...,带有多余前缀会产生The image format is not supported报错。 |
url |
否 |
String |
与data二选一。 单个图片其对应的Base64编码不超过10MB。文件在Base64编码后会大于文件原本大小,请注意做好边界判断,建议文件大小不超过7MB。 图片尺寸不小于15px,最长边不超过8192px,支持JPEG/JPG/PNG/BMP/TIFF格式。 图片的URL路径,目前支持:
|
alarm |
否 |
Boolean |
证件告警检测功能的开关,默认false,取值范围如下: |
响应参数
状态码:200
参数 |
参数类型 |
描述 |
---|---|---|
result |
调用成功时表示调用结果。 调用失败时无此字段。 |
参数 |
参数类型 |
描述 |
---|---|---|
type |
String |
证件的类型,支持的证件类型如下:
|
location |
Array<Array<Integer>> |
证件的位置。 |
confidence |
Float |
证件位置的置信度。 |
alarm_result |
Object |
图像告警检测结果。 仅在输入参数alarm为true时,返回该字段,包含如下字段,各字段解释请参见表6。 detect_blur_result、detect_glare_result、detect_blocking_within_border_result、detect_insufficient_lighting_result、detect_copy_result、detect_border_integrity_result、detect_reproduce_result |
alarm_confidence |
Object |
图像告警检测结果分数。 仅在输入参数alarm为true时,返回该字段,包含字段如下,各字段解释请参见表7。 :blur_score、glare_score、blocking_within_border_score、insufficient_lighting_score、copy_score、border_integrity_score、reproduce_score,以上字段取值范围为[0, 99]。 |
参数 |
参数类型 |
描述 |
---|---|---|
detect_blur_result |
Boolean |
证件图像模糊告警结果。 |
detect_glare_result |
Boolean |
证件图像反光告警结果。 |
detect_blocking_within_border_result |
Boolean |
证件图像框内遮挡告警结果。 |
detect_insufficient_lighting_result |
Boolean |
证件图像过暗告警结果。 |
detect_copy_result |
Boolean |
证件图像是否黑白复印件告警结果。 |
detect_border_integrity_result |
Boolean |
证件图像边框完整性告警结果。 |
detect_reproduce_result |
Boolean |
证件图像是否翻拍告警结果。 |
参数 |
参数类型 |
描述 |
---|---|---|
blur_score |
Integer |
证件图像模糊告警分数,分数越高,证件图像模糊的可能性越高。 |
glare_score |
Integer |
证件图像反光告警分数,分数越高,证件图像反光的可能性越高。 |
blocking_within_border_score |
Integer |
证件图像框内遮挡告警分数,分数越高,证件图像框内遮挡的可能性越高。 |
insufficient_lighting_score |
Integer |
证件图像过暗告警分数,分数越高,证件图像过暗的可能性越高。 |
copy_score |
Integer |
证件图像复印件告警分数,分数越高,证件图像是复印件的可能性越高。 |
border_integrity_score |
Integer |
证件图像边框完整性告警分数,分数越高,证件图像边框不完整的可能性越高。 |
reproduce_score |
Integer |
证件图像翻拍告警分数,分数越高,证件图像经过翻拍的可能性越高。 |
状态码:400
参数 |
参数类型 |
描述 |
---|---|---|
error_code |
String |
调用失败时的错误码,具体请参见错误码。 调用成功时无此字段。 |
error_msg |
String |
调用失败时的错误信息。 调用成功时无此字段。 |
请求示例
-
POST https://{endpoint}/v2/{project_id}/ocr/auto-id-doc-classification { "data" : "/9j/4AAQSkZJRgABAgEASABIAAD/4RFZRXhpZgAATU0AKgAAAA...", "alarm" : true }
-
POST https://{endpoint}/v2/{project_id}/ocr/auto-id-doc-classification { "url" : "https://BucketName.obs.myhuaweicloud.com/ObjectName", "alarm" : true }
响应示例
状态码:200
成功响应示例
{ "result" : { "type" : "id_card", "location" : [ [ 275, 125 ], [ 860, 165 ], [ 916, 634 ], [ 255, 633 ] ], "confidence" : 0.979, "alarm_result" : { "detect_blur_result" : true, "detect_glare_result" : false, "detect_blocking_within_border_result" : false, "detect_insufficient_lighting_result" : false, "detect_copy_result" : false, "detect_border_integrity_result" : false, "detect_reproduce_result" : false }, "alarm_confidence" : { "blur_score" : 98, "glare_score" : 0, "blocking_within_border_score" : 0, "insufficient_lighting_score" : 0, "copy_score" : 0, "border_integrity_score" : 0, "reproduce_score" : 0 } } }
状态码:400
失败响应示例
{ "error_code" : "AIS.0103", "error_msg" : "The image size does not meet the requirements." }
SDK代码示例
SDK代码示例如下。
-
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 49 50 51
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 RecognizeAutoIdDocClassificationSolution { 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"); String projectId = "{project_id}"; ICredential auth = new BasicCredentials() .withProjectId(projectId) .withAk(ak) .withSk(sk); OcrClient client = OcrClient.newBuilder() .withCredential(auth) .withRegion(OcrRegion.valueOf("<YOUR REGION>")) .build(); RecognizeAutoIdDocClassificationRequest request = new RecognizeAutoIdDocClassificationRequest(); AutoIdDocClassificationRequestBody body = new AutoIdDocClassificationRequestBody(); body.withAlarm(true); body.withData("/9j/4AAQSkZJRgABAgEASABIAAD/4RFZRXhpZgAATU0AKgAAAA..."); request.withBody(body); try { RecognizeAutoIdDocClassificationResponse response = client.recognizeAutoIdDocClassification(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()); } } }
-
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 49 50 51
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 RecognizeAutoIdDocClassificationSolution { 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"); String projectId = "{project_id}"; ICredential auth = new BasicCredentials() .withProjectId(projectId) .withAk(ak) .withSk(sk); OcrClient client = OcrClient.newBuilder() .withCredential(auth) .withRegion(OcrRegion.valueOf("<YOUR REGION>")) .build(); RecognizeAutoIdDocClassificationRequest request = new RecognizeAutoIdDocClassificationRequest(); AutoIdDocClassificationRequestBody body = new AutoIdDocClassificationRequestBody(); body.withAlarm(true); body.withUrl("https://BucketName.obs.myhuaweicloud.com/ObjectName"); request.withBody(body); try { RecognizeAutoIdDocClassificationResponse response = client.recognizeAutoIdDocClassification(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()); } } }
-
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
# coding: utf-8 import os 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.environ["CLOUD_SDK_AK"] sk = os.environ["CLOUD_SDK_SK"] projectId = "{project_id}" credentials = BasicCredentials(ak, sk, projectId) client = OcrClient.new_builder() \ .with_credentials(credentials) \ .with_region(OcrRegion.value_of("<YOUR REGION>")) \ .build() try: request = RecognizeAutoIdDocClassificationRequest() request.body = AutoIdDocClassificationRequestBody( alarm=True, data="/9j/4AAQSkZJRgABAgEASABIAAD/4RFZRXhpZgAATU0AKgAAAA..." ) response = client.recognize_auto_id_doc_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)
-
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
# coding: utf-8 import os 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.environ["CLOUD_SDK_AK"] sk = os.environ["CLOUD_SDK_SK"] projectId = "{project_id}" credentials = BasicCredentials(ak, sk, projectId) client = OcrClient.new_builder() \ .with_credentials(credentials) \ .with_region(OcrRegion.value_of("<YOUR REGION>")) \ .build() try: request = RecognizeAutoIdDocClassificationRequest() request.body = AutoIdDocClassificationRequestBody( alarm=True, url="https://BucketName.obs.myhuaweicloud.com/ObjectName" ) response = client.recognize_auto_id_doc_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)
-
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
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") projectId := "{project_id}" auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). WithProjectId(projectId). Build() client := ocr.NewOcrClient( ocr.OcrClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.RecognizeAutoIdDocClassificationRequest{} alarmAutoIdDocClassificationRequestBody:= true dataAutoIdDocClassificationRequestBody:= "/9j/4AAQSkZJRgABAgEASABIAAD/4RFZRXhpZgAATU0AKgAAAA..." request.Body = &model.AutoIdDocClassificationRequestBody{ Alarm: &alarmAutoIdDocClassificationRequestBody, Data: &dataAutoIdDocClassificationRequestBody, } response, err := client.RecognizeAutoIdDocClassification(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } }
-
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
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") projectId := "{project_id}" auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). WithProjectId(projectId). Build() client := ocr.NewOcrClient( ocr.OcrClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.RecognizeAutoIdDocClassificationRequest{} alarmAutoIdDocClassificationRequestBody:= true urlAutoIdDocClassificationRequestBody:= "https://BucketName.obs.myhuaweicloud.com/ObjectName" request.Body = &model.AutoIdDocClassificationRequestBody{ Alarm: &alarmAutoIdDocClassificationRequestBody, Url: &urlAutoIdDocClassificationRequestBody, } response, err := client.RecognizeAutoIdDocClassification(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } }
更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。
错误码
错误码请参见错误码。