- 印刷する
- PDF
CLOVA OCR Document API
- 印刷する
- PDF
version
Version | Date | Changes |
---|---|---|
v1.0.0 | 2021-03-04 | 最初の作成 |
v1.0.2 | 2021-07-22 | foundValuesSum -> foundValueSum 身分証明書に maskingPolysを追加 |
v1.0.3 | 2021-09-16 | 身分証明証に外国人登録証を追加 |
v1.0.4 | 2022-04-21 | 身分証明証の範囲位置表記 外国人登録証 alienRegNumEtcを追加 クレジットカードに名前を追加 |
v1.0.5 | 2023-05-25 | パスポート MRZ API |
v1.0.6 | 2023-11-23 | 領収書に税金および割引金額を追加 |
リクエスト
Method | Request URI |
---|---|
POST | CLOVA OCRビルダーから生成された API Gatewayの InvokeURLで呼び出します。 ドメインごとに固有の呼び出し URLが作成されます。 |
Requesting document OCR recognition
区分 | 説明 | Path |
---|---|---|
Document | 領収証 | /document/receipt |
Document | クレジットカード | /document/credit-card |
Document | 名刺 | /document/name-card |
Document | 事業者登録証 | /document/biz-license |
Document | 身分証明書(住民登録証、運転免許証、パスポート) | /document/id-card |
Document | パスポート(Global) | /document/passport |
リクエストヘッダ
ヘッダ名 | 説明 |
---|---|
X-OCR-SECRET | ドメインで API Gatewayと連携時作成した X-OCR-SECRET:{Client Secret} |
Content-Type | application/json : リクエストに JSON本文使用。Base64でエンコードされた image.dataサポート - multipart/form-data : リクエストにマルチパート本文を使用。ストリーミングで送信された画像ファイルのサポート |
リクエストボディ
Content-Type : application/json
- 画像認識リクエスト
区分 | Json Model |
---|---|
画像認識リクエスト | { "version": "string", "requestId": "string", "timestamp": 0, "images": [{ "format": "string", "data": "string", "name": "string"}] } |
画像認識リクエストフィールドの詳細説明
フィールド名 | 要否 | タイプ | 説明 | 制約事項 |
---|---|---|---|---|
version | Yes | string | 「V2」に固定 | |
requestId | Yes | string | API呼び出し UUIDです | |
timestamp | Yes | 0 | API呼び出し Timestamp値です | |
images | Yes | string | JSON arrayで入力され、現在は1つの画像のみ入力できます。(韓国語/日本語) | |
images.format | Yes | string | 画像フォーマットを設定します | 「.jpg」、「.jpeg」、「.png」画像、「.pdf」、「.tiff」の単一ページ形式をサポートします |
image.data | Yes | string | image.dataは、base64エンコード画像バイトです | |
image.name | Yes | string | 画像名を入力します。画像を識別するために使用され、レスポンス結果の確認に使用されます |
CURL example:
curl --request POST 'your apigw invoke url' \
--header 'X-OCR-SECRET: your secret key' \
--data-raw '{"images":[{"format":"jpg","name":"demo","data":"your image base64 bytes"}],"requestId":"guide-json-demo","version":"V2","timestamp":1584062336793}'
Content-Type : multipart/form-data
- 画像認識リクエスト
KEY | Required | VALUE |
---|---|---|
message | Y | {"version": "string","requestId": "string","timestamp": 0,"images": [{ "format": "string", "name": "string" }]} |
file | Y | image file steam data |
Form Data Message Value Description
Field name | Required | Type | Description | Constraints |
---|---|---|---|---|
version | Yes | string | 「V2」に固定 | |
requestId | Yes | string | API呼び出し UUIDです | |
timestamp | Yes | integer | API呼び出し Timestamp値です | |
images | Yes | string | JSON arrayで入力され、現在は1つの画像のみ入力できる | |
images.format | Yes | string | 画像フォーマットを設定します | 「.jpg」、「.jpeg」、「.png」画像、「.pdf」、「.tiff」の単一ページ形式をサポートします |
image.name | Yes | string | 画像名を入力します。画像を識別するために使用され、レスポンス結果の確認に使用されます |
CURL example:
curl --request POST 'your apigw invoke url' \
--header 'X-OCR-SECRET: your secret key' \
--form 'message={"images":[{"format":"png","name":"demo"}],"requestId":"guide-demo","version":"V2","timestamp":1584062336793}' \
--form 'file=@image.png'
レスポンス
レスポンスボディ
- Image recognition results
Classification | Json Model |
---|---|
Image recognition results | { "uid": "string", "name": "string", "inferResult": "string", "message": "string", "receipt": {}, "creditCard": {}, "bizLicense": {}, "idCard": {}, "nameCard": {}, "passport": {}, "validationResult": { "result": "string", "message": "string"} } |
Detailed description of the Image recognition results field
Field Name | Data Type | Description |
---|---|---|
uid | string | APIの有効性をチェックするために提供される固有 IDで、有効性チェックリクエストを追跡するのに使用 |
name | string | リクエストされた画像名 |
inferResult | string | 画像類推結果。 「SUCCESS」: 画像認識成功。「FAILURE」: 画像認識失敗。「ERROR」画像認識例外事項 |
message | string | 画像認識が成功した場合「SUCCESS」 画像認識失敗の場合、エラーメッセージが表示される。 エラーメッセージは下記に詳細が表示される |
receipt | json object | receiptオブジェクトを参照 |
creditCard | json object | creditCardオブジェクトを参照 |
bizLicense | json object | bizLicenseオブジェクトを参照 |
idCard | json object | idCardオブジェクトを参照 |
nameCard | json object | nameCardオブジェクトを参照 |
passport | json object | passportオブジェクトを参照 |
validationResult | json object | 有効性チェックの結果 |
validationResult.result | string | 結果コード 「NO_REQUESTED」: 有効性チェックの作業が実行されない。 「UNCHECKED」: 動作レスポンスが確認されていないか、受け入れられていない。 「ERROR」: 有効性チェック実行エラー。 「VALID」: 認証結果が有効。 「INVALID」: 認証結果が有効ではない。 「UNCHECHED」、「ERROR」および「INVALID」などは有効性チェックの失敗と表示される。 |
validationResult.message | string | 有効性チェックの詳細メッセージで常に返還される値ではない。 |
convertedImageInfo | json object | 画像形式が PDF/TIFFである場合のみレスポンス。 リクエスト形式が PDF/TIFFである場合、座標は返還された画像を基準とする。 |
convertedImageInfo.width | integer | 基本画像の幅。 |
convertedImageInfo.height | integer | 基本画像の高さ。 |
convertedImageInfo.pageIndex | integer | PDF/TIFFのページ索引 |
- receipt object
Classification | Json Model |
---|---|
receipt Field | { "meta": {}, "result": {}, } |
Receipt Object Field Details
Field Name | Data Type | Description |
---|---|---|
meta | json object | メタ情報 |
meta.estimatedLanguage | string | OCRで推定した言語(en: 英語、ja: 日本語、ko: 韓国語) | OCR認識言語 |
result | json object | 認識結果 |
result.storeInfo | json object | 店舗情報 |
result.storeInfo.poiInfo | PoiObject[] | POIグラウンディングの結果 |
result.storeInfo.name | StringObject | 商号 |
result.storeInfo.subName | StringObject | 支店名 |
result.storeInfo.bizNum | StringObject | 事業者番号 |
result.storeInfo.movieName | StringObject | 映画のタイトル(映画チケット関連項目) |
result.storeInfo.addresses | StringObject[] | 店舗の住所 |
result.storeInfo.tel | TelObject[] | Telephone number of the store |
result.paymentInfo | json object | 決済情報 |
result.paymentInfo.date | DateObject | 決済日 |
result.paymentInfo.time | TimeObject | 決済時間 |
result.paymentInfo.cardInfo | json object | Transaction card information |
result.paymentInfo.cardInfo.company | StringObject | カード会社名 |
result.paymentInfo.cardInfo.number | StringObject | カード番号 |
result.paymentInfo.confirmNum | BaseObject | 決済番号 |
result.subResults | json array | 項目グループ情報 |
result.subResults.items | json array | 認識された項目情報(メニューなど) |
result.subResults.items.name | StringObject | 項目名 |
result.subResults.items.code | StringObject | 項目コード |
result.subResults.items.count | FloatObject | 項目数 |
result.subResults.items.price | json object | 価格情報 |
result.subResults.items.price.price | FloatObject | 価格 |
result.subResults.items.price.unitPrice | FloatObject | 単価 |
result.totalPrice | json object | 総額情報 |
result.totalPrice.price | FloatObject | 総額 |
result.subtotal | FloatObject | 総計情報 |
result.subtotal.taxprice | FloatObject | 税金 |
result.subtotal.discountprice | FloatObject | 割引金額 |
- creditCard object
Classification | Json Model |
---|---|
creditCard Field | { "meta": {}, "result": {}, } |
creditCard Object Field Details
Field Name | Data Type | Description |
---|---|---|
meta | json object | メタ情報 |
meta.estimatedLanguage | string | OCRで推定した言語(en: 英語、ja: 日本語、ko: 韓国語) |
result | json object | 認識結果 |
result.number | Field object | Fieldオブジェクトを参照 |
result.validThru | Field object | Fieldオブジェクトを参照 |
result.name | Field object | カードの所有者名 Fieldオブジェクトを参照 |
- bizLicense object
Classification | Json Model |
---|---|
bizLicense Field | { "meta": {}, "result": {}, } |
bizLicense Object Field Details
Field Name | Data Type | Description |
---|---|---|
meta | json object | メタ情報 |
meta.estimatedLanguage | string | OCRで推定した言語(en: 英語、ja: 日本語、ko: 韓国語) |
result | json object | 認識結果 |
result.birth | BaseObject[] | 生年月日 |
result.bisAddress | BaseObject[] | 事業者住所 |
result.bisArea | BaseObject[] | 事業場の所在地 |
result.bisItem | BaseObject[] | 事業項目 |
result.registerNumber | BaseObject[] | 事業者登録番号 |
result.bisType | BaseObject[] | 業種 |
result.companyName | BaseObject[] | 商号 |
result.coRepName | BaseObject[] | 共同代表者名 |
result.corpName | BaseObject[] | 法人(グループ)名 |
result.corpRegisterNum | BaseObject[] | 事業者登録番号 |
result.coRepSocialNum | BaseObject[] | 共同代表者の住民登録番号 |
result.documentType | StringObject[] | 文書タイプ |
result.headAddress | BaseObject[] | 本社住所 |
result.issuanceDate | BaseObject[] | 発行日 |
result.issuanceReason | BaseObject[] | 発行理由 |
result.openDate | BaseObject[] | 事業開始日 |
result.repName | BaseObject[] | 代表者名 |
result.socialNumber | BaseObject[] | 住民登録番号 |
result.taxType | BaseObject[] | 課税タイプ |
- idCard object
Classification | Json Model |
---|---|
idcard Field | { "meta": {}, "result": {}, } |
idCard Object Field Details
Field Name | Data Type | Description |
---|---|---|
meta | json object | メタ情報 |
meta.estimatedLanguage | string | OCRで推定した言語(en: 英語、ja: 日本語、ko: 韓国語) |
result | json object | 認識結果 |
result.isConfident | boolean | 信頼性資格リクエストを反映する指標 各 IDタイプに必要な詳細情報がある場合 Trueで出力され、そうではない場合 Falseで出力される。 |
result.IDType | string | 身分証明書タイプ 返還値は「身分証明書」、「運転免許証」、「パスポート」、「不明」のいずれかである。 |
result.rois | BoundingPoly[] | オブジェクト範囲の位置情報 |
result.ic | json object | 住民登録証情報 |
result.ic.name | StringObject[] | 名前(韓国語) |
result.ic.personalNum | StringObject[] | 住民登録番号 |
result.ic.address | StringObject[] | 住所 |
result.ic.issueDate | DateObject[] | 発行日 |
result.ic.authority | StringObject[] | 発給機関 |
result.dl | json object | 運転免許証情報 |
result.dl.type | BaseObject[] | 免許の種類 |
result.dl.num | StringObject[] | 免許番号 |
result.dl.name | StringObject[] | 名前(韓国語) |
result.dl.personalNum | StringObject[] | 住民登録番号 |
result.dl.address | StringObject[] | Address |
result.dl.renewStartDate | DateObject[] | 更新期間開始日 |
result.dl.renewEndDate | DateObject[] | 更新期間終了日 |
result.dl.condition | StringObject[] | 免許条件 |
result.dl.code | StringObject[] | 免許コード |
result.dl.organDonation | BaseObject[] | 臓器および組織提供登録 |
result.dl.issueDate | DateObject[] | 発行日 |
result.dl.authority | StringObject[] | 発給機関 |
result.pp | json object | パスポートの情報 |
result.pp.type | StringObject[] | パスポートのタイプ |
result.pp.issueCountry | BaseObject[] | 発行国 |
result.pp.num | StringObject[] | パスポート番号 |
result.pp.surName | StringObject[] | 姓 |
result.pp.givenName | StringObject[] | 氏名 |
result.pp.nationality | StringObject[] | 国籍 |
result.pp.birthDate | DateObject[] | 生年月日 |
result.pp.personalNum | StringObject[] | 住民登録番号 |
result.pp.sex | StringObject[] | 性別 |
result.pp.issueDate | DateObject[] | 発行日 |
result.pp.expireDate | DateObject[] | 終了日 |
result.pp.authority | BaseObject[] | 発行機関 |
result.pp.fullNameKor | StringObject[] | 名前(韓国語) |
result.pp.MRZ1 | StringObject[] | Machine Readable Zone (MRZ) 1 |
result.pp.MRZ2 | StringObject[] | Machine Readable Zone (MRZ) 2 |
result.ac | json object | 外国人登録証情報 |
result.ac.alienRegNum | StringObject[] | 外国人登録番号 |
result.ac.sex | StringObject[] | 性別 |
result.ac.name | StringObject[] | 氏名 |
result.ac.nationality | StringObject[] | 国籍 |
result.ac.visaType | StringObject[] | ビザタイプ |
result.ac.issueDate | DateObject[] | 発行日 |
result.ac.authority | StringObject[] | 発給機関 |
result.ac.authorityEng | StringObject[] | 発行機関(英語) |
result.ac.alienRegNumEtc | StringObject[] | 外国人登録番号など |
- nameCard object
Classification | Json Model |
---|---|
nameCard Field | { "meta": {}, "result": {}, } |
nameCard Object Field Details
Field Name | Data Type | Description |
---|---|---|
meta | json object | メタ情報 |
meta.estimatedLanguage | string | OCRで推定した言語(en: 英語、ja: 日本語、ko: 韓国語) |
result | json object | 認識結果 |
result.name | StringObject[] | 名前情報 |
result.nameFurigana | StringObject[] | フリガナ名前の情報(言語が jaのときのみ回答) |
result.company | StringObject[] | 会社情報 |
result.department | StringObject[] | 部署情報 |
result.address | StringObject[] | 住所情報 |
result.position | StringObject[] | 役職情報 |
result.mobile | TelObject[] | 携帯電話情報 |
result.tel | TelObject[] | 電話情報 |
result.fax | TelObject[] | ファックス情報 |
result.email | StringObject[] | メールアドレス情報 |
result.homepage | StringObject[] | ホームページ情報 |
- passport object
Classification | Json Model |
---|---|
passport Field | { " passportResult": {}, } |
passport Object Field Details
Field Name | Data Type | Description |
---|---|---|
passportResult | json object | 認識結果 |
passportResult.documentClassCode | MrzString | 文章コード。「パスポート」 |
passportResult.issuingStateCode | MrzString | 発行国 |
passportResult.firstName | MrzString | 氏名 |
passportResult.lastName1 | MrzString | ひとつ目の名字 |
passportResult.lastName2 | MrzString | ふたつ目の名字 |
passportResult.documentNumber | MrzString | パスポート番号 |
passportResult.checkDigitForDocumentNumber | MrzString | 文書番号に関する確認の数字 |
passportResult.nationality | MrzString | 国籍 |
passportResult.dateOfBirth | MrzString | 生年月日 |
passportResult.age | MrzInt | 年齢 |
passportResult.checkDigitForDateOfBirth | MrzString | 生年月日に関する確認の数字 |
passportResult.gender | MrzString | 性別 |
passportResult.dateOfExpiry | MrzString | 満了日 |
passportResult.checkDigitForDateOfExpiry | MrzString | 満了日に関する確認の数字 |
passportResult.personalNumber | MrzString | 住民登録番号 |
passportResult.checkDigitForPersonalNumber | MrzString | 住民登録番号に関する確認の数字 |
passportResult.finalCheckDigit | MrzString | 最終確認の数字 |
passportResult.mrzType | MrzString | MRZタイプ |
passportResult.mrzLines | MrzString | MRZテキスト |
passportResult.isExpired | Mrzbool | 満了 |
- field object
Classification | Json Model |
---|---|
field Field | { "text": "", "confidence": 0.0, "boundingPoly": {}, "subBoundingPolys": [] } |
field Object Field Details
Field Name | Data Type | Description |
---|---|---|
text | string | 認識結果テキスト |
confidence | float | 推論結果の信頼度。 0 ~ 1の値が大きいほど正確度が高い。 |
boundingPoly | BoundingPoly object | boundingPolyオブジェクトを参照 |
subBoundingPolys | BoundingPoly[] | boundingPolyオブジェクトを参照 |
- boundingPoly object
Classification | Json Model |
---|---|
boundingPoly | { "vertices":[{}] } |
boundingPoly Object Field Details
Field Name | Data Type | Description |
---|---|---|
vertices | vertices object | verticesオブジェクトを参照 |
- vertices object
Classification | Json Model |
---|---|
vertices | { "x": 0.0, "y": 0.0 } |
vertices Object Field Details
Field Name | Data Type | Description |
---|---|---|
x | float | X座標 |
y | float | Y座標 |
- baseObject
Classification | Json Model |
---|---|
baseObject | { "text": "", "boundingPolys": [], "keyText":"", "confidenceScore":0.0 } |
baseObject Field Details
Field Name | Data Type | Description |
---|---|---|
text | string | パースされたテキスト |
boundingPolys | BoundingPoly[] | boundingPolyオブジェクトを参照 |
keyText | string | パースされたテキスト関連キーの値 |
confidenceScore | float | 推論結果の信頼度。0 ~ 1の値が大きいほど正確度が高い。 |
- dateObject
Classification | Json Model |
---|---|
dateObject | { "text": "", "formatted": {}, "boundingPolys": [], "maskingPolys":[], "keyText":"", "confidenceScore":0.0 } |
dateObject Field Details
Field Name | Data Type | Description |
---|---|---|
text | string | パースされたテキスト |
formatted | json object | パースされたテキストについての追加情報 |
formatted.year | string | 年。四桁の数字の年度を示す。空文字列である可能性があることを除けば ISO 8601標準形式に従う。 |
formatted.month | string | 月。二桁の数字の月を示す。空文字列である可能性があることを除けば ISO 8601標準形式に従う。 |
formatted.day | string | 日付。二桁の数字の日付を示す。空文字列である可能性があることを除けば ISO 8601標準形式に従う。 |
boundingPolys | BoundingPoly[] | boundingPolyオブジェクトを参照 |
maskingPolys | BoundingPoly[] | 個人情報のマスキング |
keyText | string | パースされたテキスト関連キーの値 |
confidenceScore | float | 推論結果の信頼度。0 ~ 1の値が大きいほど正確度が高い。 |
- timeObject
Classification | Json Model |
---|---|
timeObject | { "text": "", "formatted": {}, "boundingPolys": [], "keyText":"", "confidenceScore":0.0 } |
timeObject Field Details
Field Name | Data Type | Description |
---|---|---|
text | string | パースされたテキスト |
formatted | json object | パースされたテキストについての追加情報 |
formatted.hour | string | 時。二桁の数字の時を示す。空文字列である可能性があることを除けば ISO 8601標準形式に従う |
formatted.minute | string | 分。二桁の数字の分を示す。空文字列である可能性があることを除けば ISO 8601標準形式に従う |
formatted.second | string | 秒。二桁の数字の秒を示す。空文字列である可能性があることを除けば ISO 8601標準形式に従う |
boundingPolys | BoundingPoly[] | boundingPolyオブジェクトを参照 |
maskingPolys | BoundingPoly[] | 個人情報のマスキング |
keyText | string | パースされたテキスト関連キーの値 |
confidenceScore | float | 推論結果の信頼度。0 ~ 1の値が大きいほど正確度が高い。 |
- TelObject
Classification | Json Model |
---|---|
TelObject | { "text": "", "formatted": {}, "boundingPolys": [], "keyText":"", "confidenceScore":0.0 } |
TelObject Field Details
Field Name | Data Type | Description |
---|---|---|
text | string | パースされたテキスト |
formatted | json object | パースされたテキストについての追加情報 |
formatted.value | string | 電話番号タイプを示す書式付きテキスト。主に数字文字列形態であるが、電話識別子(+)を含めることができる。認識細分化に失敗した場合、空文字列の可能性がある。 |
boundingPolys | BoundingPoly[] | boundingPolyオブジェクトを参照 |
keyText | string | パースされたテキスト関連キーの値 |
confidenceScore | float | 推論結果の信頼度。0 ~ 1の値が大きいほど正確度が高い。 |
- FloatObject
Classification | Json Model |
---|---|
FloatObject | { "text": "", "formatted": {}, "boundingPolys": [], "keyText":"", "confidenceScore":0.0 } |
FloatObject Field Details
Field Name | Data Type | Description |
---|---|---|
text | string | パースされたテキスト |
formatted | json object | パースされたテキストについての追加情報 |
formatted.value | string | 失敗タイプを示す書式付きテキスト。失敗文字列タイプ。品目の数と価格を説明するのに有用である。認識細分化に失敗した場合、空文字列の可能性がある。 |
boundingPolys | BoundingPoly[] | boundingPolyオブジェクトを参照 |
keyText | string | パースされたテキスト関連キーの値 |
confidenceScore | float | 推論結果の信頼度。0 ~ 1の値が大きいほど正確度が高い。 |
- StringObject
Classification | Json Model |
---|---|
StringObject | { "text": "", "formatted": {}, "boundingPolys": [], "maskingPolys": [], "keyText":"", "confidenceScore":0.0 } |
StringObject Field Details
Field Name | Data Type | Description |
---|---|---|
text | string | パースされたテキスト |
formatted | json object | パースされたテキストについての追加情報 |
formatted.value | string | 精製されたテキスト。精製過程は各身分証明書の分類により異なる。空文字列の可能性がある。 |
boundingPolys | BoundingPoly[] | boundingPolyオブジェクトを参照 |
maskingPolys | BoundingPoly[] | 個人情報 |
keyText | string | パースされたテキスト関連キーの値 |
confidenceScore | float | 推論結果の信頼度。0 ~ 1の値が大きいほど正確度が高い。 |
- PoiObject
Classification | Json Model |
---|---|
PoiObject | { "gid": "", "title": "", "phone": "", "address": "", "roadAddress": "", "biznum": "", "confidence": "" } |
PoiObject Field Details
Field Name | Data Type | Description |
---|---|---|
gid | string | 共有 ID |
title | string | 商号 |
phone | string | 電話番号 |
address | string | 住所 |
roadAddress | string | 道路名住所 |
biznum | string | 事業者番号(まだ正式にサポートされていないため nullもあり得るが、今後追加される可能性あり) |
confidence | string | 信頼度(高いほど正確度が高い) |
18.Checksum object
Classification | Json Model |
---|---|
checksum Field | { "found": "", "foundValueIds": [], "foundValueSum": "", "foundTotalIds": [], "foundTotalSum": "", "foundTotalSum": "" } |
Checksum Object Field Details
Field Name | Data Type | Description |
---|---|---|
found | json object | チェックサムフィールドが発見されたかどうかを示すフラグ |
foundValueIds | int[] | 発見された値セルの ID一覧 |
foundValueSum | float | 発見された値の合計 |
foundTotalIds | int[] | 発見された全体セルの ID一覧 |
foundTotalSum | float | 発見された全体値の合計 |
difference | float | 値と全体セルの差 |
19.KeyCell object
Classification | Json Model |
---|---|
KeyCell Field | { "boundingPoly": {}, "depth": "", "formatted": "", "group": "", "value": "" } |
KeyCell Object Field Details
Field Name | Data Type | Description |
---|---|---|
boundingPoly | BoundingPoly | セル範囲のボックス座標 |
depth | string | 発見されたキーセルの深さ |
formatted | string | キーセルのグラウンディングテキスト |
group | string | 列/行別キーを区切るための識別子 |
value | string | キーセルのグラウンディングされていないテキスト |
20.ValueCell object
Classification | Json Model |
---|---|
ValueCell Field | { "boundingPoly": {}, "confidence": "", "value": "" } |
ValueCell Object Field Details
Field Name | Data Type | Description |
---|---|---|
boundingPoly | BoundingPoly | セル範囲のボックス座標 |
confidence | float | 値セルの信頼度 |
value | string | 値セルのテキスト |
21.MrzString object
Classification | Json Model |
---|---|
MrzString Field | { "rawText": "", "refinedText ": "", "postprocessed": [0] } |
MrzString Object Field Details
Field Name | Data Type | Description |
---|---|---|
rawText | string | 原本テキスト |
refinedText | string | 精製されたテキスト |
postprocessed | int32 | 精製方式 |
22.Mrzbool object
Classification | Json Model |
---|---|
Mrzbool Field | { "rawText": "", "refinedText ": "", "postprocessed": [0] } |
Mrzbool Object Field Details
Field Name | Data Type | Description |
---|---|---|
rawText | string | 原本テキスト |
refinedText | bool | 精製されたテキスト |
postprocessed | int32 | 精製方式 |
23.MrzInt object
Classification | Json Model |
---|---|
MrzInt Field | { "rawText": "", "refinedText ": 0, "postprocessed": [0] } |
MrzInt Object Field Details
Field Name | Data Type | Description |
---|---|---|
rawText | string | 原本テキスト |
refinedText | int | 精製されたテキスト |
postprocessed | int32 | 精製方式 |
例
DOCUMENT OCRのリクエスト例
{
"version": "V2",
"requestId": "string",
"timestamp": 0,
"images": [
{
"format": "jpg",
"name": "test 1",
"data": "data"
}
]
}
Credit Cardのレスポンス例
{
"version": "V2",
"requestId": "string",
"timestamp": 1613984515468,
"images": [
{
"creditCard": {
"result": {
"number": {
"text": "5307123456749012",
"confidence": 0.96435016,
"boundingPoly": {
"vertices": [
{
"x": 64.0,
"y": 218.0
},
{
"x": 582.0,
"y": 222.0
},
{
"x": 582.0,
"y": 265.0
},
{
"x": 64.0,
"y": 261.0
}
]
},
"subBoundingPolys": [
{
"vertices": [
{
"x": 65.0,
"y": 222.0
},
{
"x": 175.0,
"y": 225.0
},
{
"x": 174.0,
"y": 260.0
},
{
"x": 64.0,
"y": 257.0
}
]
},
{
"vertices": [
{
"x": 202.0,
"y": 225.0
},
{
"x": 312.0,
"y": 225.0
},
{
"x": 312.0,
"y": 262.0
},
{
"x": 202.0,
"y": 262.0
}
]
},
{
"vertices": [
{
"x": 340.0,
"y": 225.0
},
{
"x": 445.0,
"y": 225.0
},
{
"x": 445.0,
"y": 260.0
},
{
"x": 340.0,
"y": 260.0
}
]
},
{
"vertices": [
{
"x": 470.0,
"y": 222.0
},
{
"x": 582.0,
"y": 222.0
},
{
"x": 582.0,
"y": 260.0
},
{
"x": 470.0,
"y": 260.0
}
]
}
]
}
}
},
"uid": "5f824ebe5b9744bb81bd3e1ef7f42e4e",
"name": "testV2Demo",
"inferResult": "SUCCESS",
"message": "SUCCESS",
"validationResult": {
"result": "NO_REQUESTED"
}
}
]
}
Receiptのレスポンス例
{
"version": "V2",
"requestId": "string",
"timestamp": 1613984672273,
"images": [{
"receipt": {
"meta": {
"estimatedLanguage": "ko"
},
"result": {
"storeInfo": {
"name": {
"text": "emart everyday",
"formatted": {
"value": "emart everyday"
},
"boundingPolys": [{
"vertices": [{
"x": 263.0,
"y": 96.0
},
{
"x": 390.0,
"y": 100.0
},
{
"x": 389.0,
"y": 141.0
},
{
"x": 262.0,
"y": 137.0
}
]
}]
},
"subName": {
"text": "盆唐亭子2号店",
"formatted": {
"value": "盆唐亭子2号店"
},
"boundingPolys": [{
"vertices": [{
"x": 530.0,
"y": 102.0
},
{
"x": 611.0,
"y": 102.0
},
{
"x": 611.0,
"y": 122.0
},
{
"x": 530.0,
"y": 122.0
}
]
}]
},
"bizNum": {
"text": "212-81-25544",
"formatted": {
"value": "212-81-25544"
},
"boundingPolys": [{
"vertices": [{
"x": 402.0,
"y": 125.0
},
{
"x": 515.0,
"y": 124.0
},
{
"x": 515.0,
"y": 141.0
},
{
"x": 402.0,
"y": 142.0
}
]
}]
},
"addresses": [{
"text": "京畿道城南市盆唐区亭子一路120",
"formatted": {
"value": "京畿道城南市盆唐区亭子一路120"
},
"boundingPolys": [{
"vertices": [{
"x": 401.0,
"y": 144.0
},
{
"x": 432.0,
"y": 144.0
},
{
"x": 432.0,
"y": 165.0
},
{
"x": 401.0,
"y": 165.0
}
]
}]
}],
"tel": [{
"text": "(031)786-1171",
"formatted": {
"value": "0317861171"
},
"boundingPolys": [{
"vertices": [{
"x": 569.0,
"y": 122.0
},
{
"x": 716.0,
"y": 118.0
},
{
"x": 716.0,
"y": 140.0
},
{
"x": 570.0,
"y": 144.0
}
]
}]
}]
},
"paymentInfo": {
"date": {
"text": "2020-04-16",
"formatted": {
"year": "2020",
"month": "04",
"day": "16"
},
"boundingPolys": [{
"vertices": [{
"x": 261.0,
"y": 256.0
},
{
"x": 432.0,
"y": 260.0
},
{
"x": 431.0,
"y": 284.0
},
{
"x": 260.0,
"y": 280.0
}
]
}]
},
"time": {
"text": "20: 11",
"formatted": {
"hour": "20",
"minute": "11",
"second": "00"
},
"boundingPolys": [{
"vertices": [{
"x": 437.0,
"y": 261.0
},
{
"x": 468.0,
"y": 261.0
},
{
"x": 468.0,
"y": 279.0
},
{
"x": 437.0,
"y": 279.0
}
]
}]
},
"cardInfo": {
"company": {
"text": "新韓",
"formatted": {
"value": "新韓"
},
"boundingPolys": [{
"vertices": [{
"x": 309.0,
"y": 585.0
},
{
"x": 334.0,
"y": 585.0
},
{
"x": 334.0,
"y": 610.0
},
{
"x": 309.0,
"y": 610.0
}
]
}]
},
"number": {
"text": "4221**8666",
"formatted": {
"value": "4221**8666"
},
"boundingPolys": [{
"vertices": [{
"x": 522.0,
"y": 586.0
},
{
"x": 716.0,
"y": 592.0
},
{
"x": 716.0,
"y": 612.0
},
{
"x": 522.0,
"y": 606.0
}
]
}]
}
},
"confirmNum": {
"text": "28672931",
"boundingPolys": [{
"vertices": [{
"x": 522.0,
"y": 586.0
},
{
"x": 716.0,
"y": 592.0
},
{
"x": 716.0,
"y": 612.0
},
{
"x": 522.0,
"y": 606.0
}
]
}]
}
},
"subResults": [{
"items": [{
"name": {
"text": "シーグラムレモン350ml",
"formatted": {
"value": "シーグラムレモン350ml"
},
"boundingPolys": [{
"vertices": [{
"x": 310.0,
"y": 345.0
},
{
"x": 372.0,
"y": 345.0
},
{
"x": 372.0,
"y": 369.0
},
{
"x": 310.0,
"y": 369.0
}
]
}]
},
"count": {
"text": "2",
"formatted": {
"value": "2"
},
"boundingPolys": [{
"vertices": [{
"x": 601.0,
"y": 348.0
},
{
"x": 615.0,
"y": 348.0
},
{
"x": 615.0,
"y": 365.0
},
{
"x": 601.0,
"y": 365.0
}
]
}]
},
"price": {
"price": {
"text": "1,600",
"formatted": {
"value": "1600"
},
"boundingPolys": [{
"vertices": [{
"x": 662.0,
"y": 347.0
},
{
"x": 716.0,
"y": 347.0
},
{
"x": 716.0,
"y": 367.0
},
{
"x": 662.0,
"y": 367.0
}
]
}]
},
"unitPrice": {
"text": "800",
"formatted": {
"value": "800"
},
"boundingPolys": [{
"vertices": [{
"x": 541.0,
"y": 347.0
},
{
"x": 577.0,
"y": 347.0
},
{
"x": 577.0,
"y": 368.0
},
{
"x": 541.0,
"y": 368.0
}
]
}]
}
}
}]
}],
"totalPrice": {
"price": {
"text": "1,600",
"formatted": {
"value": "1600"
},
"boundingPolys": [{
"vertices": [{
"x": 651.0,
"y": 546.0
},
{
"x": 717.0,
"y": 548.0
},
{
"x": 717.0,
"y": 569.0
},
{
"x": 651.0,
"y": 567.0
}
]
}]
}
}
}
},
"uid": "5b9de1f9765448eca574efc1a4231bbe",
"name": "testV2Demo",
"inferResult": "SUCCESS",
"message": "SUCCESS",
"validationResult": {
"result": "NO_REQUESTED"
}
}]
}
biz licenseのレスポンス例
{
"version": "V2",
"requestId": "string",
"timestamp": 1613984821070,
"images": [{
"bizLicense": {
"meta": {
"estimatedLanguage": "ko"
},
"result": {
"birth": [{
"text": "1951年12月03日",
"boundingPolys": [{
"vertices": [{
"x": 396.0,
"y": 254.0
},
{
"x": 421.0,
"y": 254.0
},
{
"x": 421.0,
"y": 265.0
},
{
"x": 396.0,
"y": 265.0
}
]
}]
}],
"bisAddress": [{
"text": "慶尚南道泗川市泗川邑航空路54",
"boundingPolys": [{
"vertices": [{
"x": 193.0,
"y": 288.0
},
{
"x": 235.0,
"y": 288.0
},
{
"x": 235.0,
"y": 300.0
},
{
"x": 193.0,
"y": 300.0
}
]
}]
}],
"bisArea": [],
"bisItem": [{
"text": "非住居用建物賃貸業(店舗、自己所有地)",
"boundingPolys": [{
"vertices": [{
"x": 368.0,
"y": 325.0
},
{
"x": 399.0,
"y": 325.0
},
{
"x": 399.0,
"y": 334.0
},
{
"x": 368.0,
"y": 334.0
}
]
}]
}],
"registerNumber": [{
"text": "611-01-99810",
"boundingPolys": [{
"vertices": [{
"x": 290.0,
"y": 210.0
},
{
"x": 386.0,
"y": 211.0
},
{
"x": 386.0,
"y": 227.0
},
{
"x": 290.0,
"y": 225.0
}
]
}]
}],
"bisType": [{
"text": "不動産業および賃貸業",
"boundingPolys": [{
"vertices": [{
"x": 221.0,
"y": 322.0
},
{
"x": 262.0,
"y": 322.0
},
{
"x": 262.0,
"y": 333.0
},
{
"x": 221.0,
"y": 333.0
}
]
}]
}],
"companyName": [{
"text": "トンソン自動車総合整備",
"boundingPolys": [{
"vertices": [{
"x": 194.0,
"y": 232.0
},
{
"x": 293.0,
"y": 233.0
},
{
"x": 293.0,
"y": 247.0
},
{
"x": 194.0,
"y": 245.0
}
]
}]
}],
"coRepName": [],
"corpName": [],
"corpRegisterNum": [],
"coRepSocialNum": [],
"documentType": [{
"text": "事業者登録証",
"formatted": {
"value": "事業者登録証"
},
"boundingPolys": [{
"vertices": [{
"x": 199.0,
"y": 157.0
},
{
"x": 396.0,
"y": 160.0
},
{
"x": 396.0,
"y": 189.0
},
{
"x": 198.0,
"y": 186.0
}
]
}]
}],
"headAddress": [],
"issuanceDate": [{
"text": "2017年06月29日",
"boundingPolys": [{
"vertices": [{
"x": 225.0,
"y": 623.0
},
{
"x": 259.0,
"y": 623.0
},
{
"x": 259.0,
"y": 637.0
},
{
"x": 225.0,
"y": 637.0
}
]
}]
}],
"issuanceReason": [{
"text": "2017年06月29日",
"boundingPolys": [{
"vertices": [{
"x": 225.0,
"y": 623.0
},
{
"x": 259.0,
"y": 623.0
},
{
"x": 259.0,
"y": 637.0
},
{
"x": 225.0,
"y": 637.0
}
]
}]
}],
"openDate": [{
"text": "2014年06月09日",
"boundingPolys": [{
"vertices": [{
"x": 193.0,
"y": 271.0
},
{
"x": 218.0,
"y": 271.0
},
{
"x": 218.0,
"y": 280.0
},
{
"x": 193.0,
"y": 280.0
}
]
}]
}],
"repName": [{
"text": "キム・ヨンドゥ",
"boundingPolys": [{
"vertices": [{
"x": 193.0,
"y": 251.0
},
{
"x": 228.0,
"y": 251.0
},
{
"x": 228.0,
"y": 264.0
},
{
"x": 193.0,
"y": 264.0
}
]
}]
}],
"socialNumber": [],
"taxType": [{
"text": "一般課税者",
"boundingPolys": [{
"vertices": [{
"x": 238.0,
"y": 185.0
},
{
"x": 357.0,
"y": 187.0
},
{
"x": 357.0,
"y": 209.0
},
{
"x": 238.0,
"y": 207.0
}
]
}]
}]
}
},
"uid": "ecf05843a1f444b6943e9d202475c3eb",
"name": "testV2Demo",
"inferResult": "SUCCESS",
"message": "SUCCESS",
"validationResult": {
"result": "NO_REQUESTED"
}
}]
}
name cardのレスポンス例
{
"version": "V2",
"requestId": "string",
"timestamp": 1613984872349,
"images": [
{
"nameCard": {
"meta": {
"estimatedLanguage": "ko"
},
"result": {
"name": [
{
"text": "ホン・ギルドン",
"boundingPolys": [
{
"vertices": [
{
"x": 286.0,
"y": 194.0
},
{
"x": 348.0,
"y": 194.0
},
{
"x": 348.0,
"y": 266.0
},
{
"x": 286.0,
"y": 266.0
}
]
}
]
}
],
"nameFurigana": [],
"company": [
{
"text": "ウリ銀行",
"boundingPolys": [
{
"vertices": [
{
"x": 317.0,
"y": 274.0
},
{
"x": 356.0,
"y": 274.0
},
{
"x": 356.0,
"y": 316.0
},
{
"x": 317.0,
"y": 316.0
}
]
}
]
}
],
"department": [],
"address": [
{
"text": "(ホン・ギルドン)",
"boundingPolys": [
{
"vertices": [
{
"x": 338.0,
"y": 189.0
},
{
"x": 414.0,
"y": 189.0
},
{
"x": 414.0,
"y": 288.0
},
{
"x": 338.0,
"y": 288.0
}
]
}
]
}
],
"position": [
{
"text": "所蔵",
"boundingPolys": [
{
"vertices": [
{
"x": 286.0,
"y": 194.0
},
{
"x": 348.0,
"y": 194.0
},
{
"x": 348.0,
"y": 266.0
},
{
"x": 286.0,
"y": 266.0
}
]
}
]
}
],
"mobile": [
{
"text": "010-1234-5678",
"boundingPolys": [
{
"vertices": [
{
"x": 297.0,
"y": 183.0
},
{
"x": 396.0,
"y": 183.0
},
{
"x": 396.0,
"y": 305.0
},
{
"x": 297.0,
"y": 305.0
}
]
}
]
}
],
"tel": [
{
"text": "123-4567-8901",
"boundingPolys": [
{
"vertices": [
{
"x": 338.0,
"y": 189.0
},
{
"x": 414.0,
"y": 189.0
},
{
"x": 414.0,
"y": 288.0
},
{
"x": 338.0,
"y": 288.0
}
]
}
]
}
],
"fax": [],
"email": [],
"homepage": []
}
},
"uid": "3277149ad2324de0b412669f7eac474a",
"name": "testV2Demo",
"inferResult": "SUCCESS",
"message": "SUCCESS",
"validationResult": {
"result": "NO_REQUESTED"
}
}
]
}
id cardのレスポンス例
{
"version": "V2",
"requestId": "string",
"timestamp": 1613984543939,
"images": [
{
"idCard": {
"meta": {
"estimatedLanguage": "ko"
},
"result": {
"isConfident": true,
"ic": {
"name": [
{
"text": "ソニック",
"formatted": {
"value": "ソニック"
},
"boundingPolys": [
{
"vertices": [
{
"x": 93.0,
"y": 135.0
},
{
"x": 257.0,
"y": 135.0
},
{
"x": 257.0,
"y": 161.0
},
{
"x": 93.0,
"y": 161.0
}
]
}
]
}
],
"personalNum": [
{
"text": "910623-1062372",
"formatted": {
"value": "910623-1062372"
},
"boundingPolys": [
{
"vertices": [
{
"x": 83.0,
"y": 166.0
},
{
"x": 260.0,
"y": 166.0
},
{
"x": 260.0,
"y": 186.0
},
{
"x": 83.0,
"y": 186.0
}
]
}
]
}
],
"address": [
{
"text": "ソウル特別市鍾路区鍾路1街24ルメイユール鍾路タウン",
"formatted": {
"value": "ソウル特別市鍾路区鍾路1街24ルメイユール鍾路タウン"
},
"boundingPolys": [
{
"vertices": [
{
"x": 43.0,
"y": 232.0
},
{
"x": 148.0,
"y": 232.0
},
{
"x": 148.0,
"y": 255.0
},
{
"x": 43.0,
"y": 255.0
}
]
},
{
"vertices": [
{
"x": 47.0,
"y": 212.0
},
{
"x": 150.0,
"y": 212.0
},
{
"x": 150.0,
"y": 234.0
},
{
"x": 47.0,
"y": 234.0
}
]
},
{
"vertices": [
{
"x": 154.0,
"y": 232.0
},
{
"x": 240.0,
"y": 232.0
},
{
"x": 240.0,
"y": 255.0
},
{
"x": 154.0,
"y": 255.0
}
]
},
{
"vertices": [
{
"x": 156.0,
"y": 212.0
},
{
"x": 219.0,
"y": 212.0
},
{
"x": 219.0,
"y": 234.0
},
{
"x": 156.0,
"y": 234.0
}
]
},
{
"vertices": [
{
"x": 224.0,
"y": 212.0
},
{
"x": 302.0,
"y": 212.0
},
{
"x": 302.0,
"y": 235.0
},
{
"x": 224.0,
"y": 235.0
}
]
},
{
"vertices": [
{
"x": 305.0,
"y": 213.0
},
{
"x": 333.0,
"y": 213.0
},
{
"x": 333.0,
"y": 234.0
},
{
"x": 305.0,
"y": 234.0
}
]
}
]
}
],
"issueDate": [
{
"text": "2011.3. 6.",
"formatted": {
"year": "2011",
"month": "03",
"day": "06"
},
"boundingPolys": [
{
"vertices": [
{
"x": 261.0,
"y": 314.0
},
{
"x": 351.0,
"y": 314.0
},
{
"x": 351.0,
"y": 336.0
},
{
"x": 261.0,
"y": 336.0
}
]
},
{
"vertices": [
{
"x": 354.0,
"y": 314.0
},
{
"x": 376.0,
"y": 314.0
},
{
"x": 376.0,
"y": 334.0
},
{
"x": 354.0,
"y": 334.0
}
]
}
]
}
],
"authority": [
{
"text": "ソニック大統領推進会ソドク会長",
"formatted": {
"value": "ソニック大統領推進会ソドク会長"
},
"boundingPolys": [
{
"vertices": [
{
"x": 172.0,
"y": 338.0
},
{
"x": 346.0,
"y": 338.0
},
{
"x": 346.0,
"y": 366.0
},
{
"x": 172.0,
"y": 366.0
}
]
},
{
"vertices": [
{
"x": 347.0,
"y": 338.0
},
{
"x": 435.0,
"y": 336.0
},
{
"x": 435.0,
"y": 363.0
},
{
"x": 348.0,
"y": 365.0
}
]
}
]
}
]
},
"idtype": "ID Card"
}
},
"uid": "0012374f247f4e70966d35eaa3c41d2a",
"name": "testV2Demo",
"inferResult": "SUCCESS",
"message": "SUCCESS",
"validationResult": {
"result": "NO_REQUESTED"
}
}
]
}
passportのレスポンス例
{
"version": "V2",
"requestId": "string",
"timestamp": 1684203696126,
"images": [
{
"passport": {
"passportResult": {
"documentClassCode": {
"rawText": "P<",
"refinedText": "Passport",
"postprocessed": [
1
]
},
"issuingStateCode": {
"rawText": "KOR",
"refinedText": "Korea (the Republic of)",
"postprocessed": []
},
"firstName": {
"rawText": "HONG",
"refinedText": "HONG",
"postprocessed": []
},
"lastName1": {
"rawText": "GILSOON",
"refinedText": "GILSOON",
"postprocessed": []
},
"lastName2": {
"rawText": "-",
"refinedText": "-",
"postprocessed": []
},
"documentNumber": {
"rawText": "M123A4567",
"refinedText": "M123A4567",
"postprocessed": []
},
"checkDigitForDocumentNumber": {
"rawText": "0",
"refinedText": "0",
"postprocessed": []
},
"nationality": {
"rawText": "KOR",
"refinedText": "Korea (the Republic of)",
"postprocessed": []
},
"dateOfBirth": {
"rawText": "870201",
"refinedText": "1987/02/01",
"postprocessed": []
},
"age": {
"rawText": "",
"refinedText": 36,
"postprocessed": []
},
"checkDigitForDateOfBirth": {
"rawText": "0",
"refinedText": "0",
"postprocessed": []
},
"gender": {
"rawText": "F",
"refinedText": "Female",
"postprocessed": []
},
"dateOfExpiry": {
"rawText": "300815",
"refinedText": "2030/08/15",
"postprocessed": []
},
"checkDigitForDateOfExpiry": {
"rawText": "0",
"refinedText": "0",
"postprocessed": []
},
"personalNumber": {
"rawText": "V2000000000000",
"refinedText": "V2000000000000",
"postprocessed": []
},
"checkDigitForPersonalNumber": {
"rawText": "0",
"refinedText": "0",
"postprocessed": []
},
"finalCheckDigit": {
"rawText": "0",
"refinedText": "0",
"postprocessed": []
},
"mrzType": {
"rawText": "",
"refinedText": "ID-3",
"postprocessed": []
},
"mrzLines": {
"rawText": "PMKORHONG<<GILSOON<<<<<<<<<<<<<<<<<<<<<<<<<<<<\nM123A45670KOR8702010F3008150V20000000000000000",
"refinedText": "PMKORHONG<<GILSOON<<<<<<<<<<<<<<<<<<<<<<<<<<<<\nM123A45670KOR8702010F3008150V20000000000000000",
"postprocessed": [
1
]
},
"isExpired": {
"rawText": "",
"refinedText": false,
"postprocessed": []
}
}
},
"uid": "8f8a04985a6e429e97c3ca4184b3c0e4",
"name": "test 1",
"inferResult": "SUCCESS",
"message": "SUCCESS",
"validationResult": {
"result": "NO_REQUESTED"
}
}
]
}
APIの例
以下は、言語別の CLOVA OCR API実装例です
- Request with multipart/form-data
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.UUID;
import org.json.JSONArray;
import org.json.JSONObject;
public class OCRAPIDemo {
public static void main(String[] args) {
String apiURL = "YOUR_API_URL";
String secretKey = "YOUR_SECRET_KEY";
String imageFile = "YOUR_IMAGE_FILE";
try {
URL url = new URL(apiURL);
HttpURLConnection con = (HttpURLConnection)url.openConnection();
con.setUseCaches(false);
con.setDoInput(true);
con.setDoOutput(true);
con.setReadTimeout(30000);
con.setRequestMethod("POST");
String boundary = "----" + UUID.randomUUID().toString().replaceAll("-", "");
con.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
con.setRequestProperty("X-OCR-SECRET", secretKey);
JSONObject json = new JSONObject();
json.put("version", "V2");
json.put("requestId", UUID.randomUUID().toString());
json.put("timestamp", System.currentTimeMillis());
JSONObject image = new JSONObject();
image.put("format", "jpg");
image.put("name", "demo");
JSONArray images = new JSONArray();
images.put(image);
json.put("images", images);
String postParams = json.toString();
con.connect();
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
long start = System.currentTimeMillis();
File file = new File(imageFile);
writeMultiPart(wr, postParams, file, boundary);
wr.close();
int responseCode = con.getResponseCode();
BufferedReader br;
if (responseCode == 200) {
br = new BufferedReader(new InputStreamReader(con.getInputStream()));
} else {
br = new BufferedReader(new InputStreamReader(con.getErrorStream()));
}
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = br.readLine()) != null) {
response.append(inputLine);
}
br.close();
System.out.println(response);
} catch (Exception e) {
System.out.println(e);
}
}
private static void writeMultiPart(OutputStream out, String jsonMessage, File file, String boundary) throws
IOException {
StringBuilder sb = new StringBuilder();
sb.append("--").append(boundary).append("\r\n");
sb.append("Content-Disposition:form-data; name=\"message\"\r\n\r\n");
sb.append(jsonMessage);
sb.append("\r\n");
out.write(sb.toString().getBytes("UTF-8"));
out.flush();
if (file != null && file.isFile()) {
out.write(("--" + boundary + "\r\n").getBytes("UTF-8"));
StringBuilder fileString = new StringBuilder();
fileString
.append("Content-Disposition:form-data; name=\"file\"; filename=");
fileString.append("\"" + file.getName() + "\"\r\n");
fileString.append("Content-Type: application/octet-stream\r\n\r\n");
out.write(fileString.toString().getBytes("UTF-8"));
out.flush();
try (FileInputStream fis = new FileInputStream(file)) {
byte[] buffer = new byte[8192];
int count;
while ((count = fis.read(buffer)) != -1) {
out.write(buffer, 0, count);
}
out.write("\r\n".getBytes());
}
out.write(("--" + boundary + "--\r\n").getBytes("UTF-8"));
}
out.flush();
}
}
import requests
import uuid
import time
import json
api_url = 'YOUR_API_URL'
secret_key = 'YOUR_SECRET_KEY'
image_file = 'YOUR_IMAGE_FILE'
request_json = {
'images': [
{
'format': 'jpg',
'name': 'demo'
}
],
'requestId': str(uuid.uuid4()),
'version': 'V2',
'timestamp': int(round(time.time() * 1000))
}
payload = {'message': json.dumps(request_json).encode('UTF-8')}
files = [
('file', open(image_file,'rb'))
]
headers = {
'X-OCR-SECRET': secret_key
}
response = requests.request("POST", api_url, headers=headers, data = payload, files = files)
print(response.text.encode('utf8'))
<?php
$client_secret = "YOUR_SECRET_KEY";
$url = "YOUR_API_URL";
$image_file = "YOUR_IMAGE_FILE";
$params->version = "V2";
$params->requestId = uniqid();
$params->timestamp = time();
$image->format = "jpg";
$image->name = "demo";
$images = array($image);
$params->images = $images;
$json = json_encode($params);
$boundary = uniqid();
$is_post = true;
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, $is_post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$post_form = array("message" => $json, "file" => new CURLFILE($image_file));
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_form);
$headers = array();
$headers[] = "X-OCR-SECRET: ".$client_secret;
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$err = curl_error($ch);
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close ($ch);
echo $status_code;
if($status_code == 200) {
echo $response;
} else {
echo "ERROR: ".$response;
}
?>
- Request with application/json
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.UUID;
import org.json.JSONArray;
import org.json.JSONObject;
public class OCRGeneralAPIDemo {
public static void main(String[] args) {
String apiURL = "YOUR_API_URL";
String secretKey = "YOUR_SECRET_KEY";
try {
URL url = new URL(apiURL);
HttpURLConnection con = (HttpURLConnection)url.openConnection();
con.setUseCaches(false);
con.setDoInput(true);
con.setDoOutput(true);
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "application/json; charset=utf-8");
con.setRequestProperty("X-OCR-SECRET", secretKey);
JSONObject json = new JSONObject();
json.put("version", "V2");
json.put("requestId", UUID.randomUUID().toString());
json.put("timestamp", System.currentTimeMillis());
JSONObject image = new JSONObject();
image.put("format", "jpg");
image should be public, otherwise, should use data
FileInputStream inputStream = new FileInputStream("YOUR_IMAGE_FILE");
byte[] buffer = new byte[inputStream.available()];
inputStream.read(buffer);
inputStream.close();
image.put("data", buffer);
image.put("name", "demo");
JSONArray images = new JSONArray();
images.put(image);
json.put("images", images);
String postParams = json.toString();
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
wr.writeBytes(postParams);
wr.flush();
wr.close();
int responseCode = con.getResponseCode();
BufferedReader br;
if (responseCode == 200) {
br = new BufferedReader(new InputStreamReader(con.getInputStream()));
} else {
br = new BufferedReader(new InputStreamReader(con.getErrorStream()));
}
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = br.readLine()) != null) {
response.append(inputLine);
}
br.close();
System.out.println(response);
} catch (Exception e) {
System.out.println(e);
}
}
}
import requests
import uuid
import time
import base64
import json
api_url = 'YOUR_API_URL'
secret_key = 'YOUR_SECRET_KEY'
image_file = 'YOUR_IMAGE_FILE'
with open(image_file,'rb') as f:
file_data = f.read()
request_json = {
'images': [
{
'format': 'jpg',
'name': 'demo',
'data': base64.b64encode(file_data).decode()
}
],
'requestId': str(uuid.uuid4()),
'version': 'V2',
'timestamp': int(round(time.time() * 1000))
}
payload = json.dumps(request_json).encode('UTF-8')
headers = {
'X-OCR-SECRET': secret_key,
'Content-Type': 'application/json'
}
response = requests.request("POST", api_url, headers=headers, data = payload)
print(response.text)
<?php
$client_secret = "YOUR_SECRET_KEY";
$url = "YOUR_API_URL";
$image_file = "YOUR_IMAGE_FILE";
$params->version = "V2";
$params->requestId = "uuid";
$params->timestamp = time();
$image->format = "jpg";
$image->data = base64_encode(file_get_contents($image_file));
$image->name = "demo";
$images = array($image);
$params->images = $images;
$json = json_encode($params);
$is_post = true;
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, $is_post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
$headers = array();
$headers[] = "X-OCR-SECRET: ".$client_secret;
$headers[] = "Content-Type:application/json; charset=utf-8";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$err = curl_error($ch);
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close ($ch);
echo $status_code;
if($status_code == 200) {
echo $response;
} else {
echo "ERROR: ".$response;
}
?>
Error code
HttpStatusCode | Description |
---|---|
400 | リクエストパラメータが無効、または制約に問題がある。 |
401 | 誤った API secret key(X-OCR-API-KEY) |
500 | 内部サーバエラー |
Error Response Body:
{
"code": "Error Code",
"message": "error details message.",
"path": "request API path",
"timestamp": 1570776853475
}
ErrorCode | Description |
---|---|
0001 | 有効ではない URL |
0002 | Secret key有効性のチェックに失敗 |
0011 | 有効でないリクエスト本文 |
0021 | サポートされていないプロトコルバージョン |
0022 | 有効でないリクエストドメイン |
0023 | APIリクエスト回数が上限に達する |
0025 | この APIへの呼び出し料金限度を超過 |
0500 | 不明なサービスエラー |
0501 | OCRサービスのエラー |