共用方式為


Recognize Printed Text - Recognize Printed Text

光學字元辨識 (OCR) 偵測影像中的文字,並將辨識的字元擷取到機器可用的字元數據流。 成功時,將會傳回 OCR 結果。 失敗時,將會傳回錯誤碼與錯誤訊息。 錯誤碼可以是 InvalidImageUrl、InvalidImageFormat、InvalidImageSize、NotSupportedImage、NotSupportedLanguage 或 InternalServerError 的其中一個。

POST {Endpoint}/vision/v2.1/ocr?detectOrientation={detectOrientation}
POST {Endpoint}/vision/v2.1/ocr?detectOrientation={detectOrientation}&language={language}

URI 參數

名稱 位於 必要 類型 Description
Endpoint
path True

string

支援的認知服務端點。

detectOrientation
query True

boolean

是否偵測影像中的文字方向。 使用 detectOrientation=true 時,OCR 服務會嘗試偵測影像方向,並在進一步處理 (之前加以更正,例如,如果影像反轉) 。

language
query

OcrLanguages

影像中要偵測到之文字的 BCP-47 語言代碼。 預設值為 『unk』。

要求標頭

名稱 必要 類型 Description
Ocp-Apim-Subscription-Key True

string

要求本文

名稱 必要 類型 Description
url True

string

影像的可公開連線 URL。

回應

名稱 類型 Description
200 OK

OcrResult

OCR 會產生區域/行/字的階層。 結果包括文字、區域、行和字的周框方塊。 相對於最接近水準或垂直方向的偵測到文字的角度,以弧度為單位。 依這個角度順時針旋轉輸入影像之後,辨識的文字線會變成水準或垂直。 與方向屬性結合,它可以用來在原始影像上正確重迭辨識結果,方法是將原始影像旋轉,或以適當的角度繞原始影像中心旋轉辨識結果。 如果無法放心偵測角度,則此屬性不存在。 如果影像包含不同角度的文字,則只會正確辨識部分文字。

Other Status Codes

ComputerVisionError

錯誤回應。

安全性

Ocp-Apim-Subscription-Key

類型: apiKey
位於: header

範例

Successful RecognizePrintedText request

範例要求

POST https://westus.api.cognitive.microsoft.com/vision/v2.1/ocr?detectOrientation=true&language=en


"{url}"

範例回覆

{
  "language": "en",
  "textAngle": -2.0000000000000338,
  "orientation": "Up",
  "regions": [
    {
      "boundingBox": "462,379,497,258",
      "lines": [
        {
          "boundingBox": "462,379,497,74",
          "words": [
            {
              "boundingBox": "462,379,41,73",
              "text": "A"
            },
            {
              "boundingBox": "523,379,153,73",
              "text": "GOAL"
            },
            {
              "boundingBox": "694,379,265,74",
              "text": "WITHOUT"
            }
          ]
        },
        {
          "boundingBox": "565,471,289,74",
          "words": [
            {
              "boundingBox": "565,471,41,73",
              "text": "A"
            },
            {
              "boundingBox": "626,471,150,73",
              "text": "PLAN"
            },
            {
              "boundingBox": "801,472,53,73",
              "text": "IS"
            }
          ]
        },
        {
          "boundingBox": "519,563,375,74",
          "words": [
            {
              "boundingBox": "519,563,149,74",
              "text": "JUST"
            },
            {
              "boundingBox": "683,564,41,72",
              "text": "A"
            },
            {
              "boundingBox": "741,564,153,73",
              "text": "WISH"
            }
          ]
        }
      ]
    }
  ]
}

定義

名稱 Description
ComputerVisionError

API 要求錯誤的詳細數據。

ComputerVisionErrorCodes

錯誤碼。

ImageUrl
OcrLanguages

影像中要偵測到之文字的 BCP-47 語言代碼。 預設值為 『unk』。

OcrLine

描述單一辨識文字行的物件。

OcrRegion

區域包含多行 (,例如多欄檔中的文字列) 。

OcrResult
OcrWord

已辨識字的資訊。

ComputerVisionError

API 要求錯誤的詳細數據。

名稱 類型 Description
code

ComputerVisionErrorCodes

錯誤碼。

message

string

說明服務所報告錯誤的訊息。

requestId

string

唯一要求標識碼。

ComputerVisionErrorCodes

錯誤碼。

名稱 類型 Description
BadArgument

string

CancelledRequest

string

DetectFaceError

string

FailedToProcess

string

InternalServerError

string

InvalidDetails

string

InvalidImageFormat

string

InvalidImageSize

string

InvalidImageUrl

string

InvalidModel

string

InvalidThumbnailSize

string

NotSupportedFeature

string

NotSupportedImage

string

NotSupportedLanguage

string

NotSupportedVisualFeature

string

StorageException

string

Timeout

string

Unspecified

string

UnsupportedMediaType

string

ImageUrl

名稱 類型 Description
url

string

影像的可公開連線 URL。

OcrLanguages

影像中要偵測到之文字的 BCP-47 語言代碼。 預設值為 『unk』。

名稱 類型 Description
ar

string

cs

string

da

string

de

string

el

string

en

string

es

string

fi

string

fr

string

hu

string

it

string

ja

string

ko

string

nb

string

nl

string

pl

string

pt

string

ro

string

ru

string

sk

string

sr-Cyrl

string

sr-Latn

string

sv

string

tr

string

unk

string

zh-Hans

string

zh-Hant

string

OcrLine

描述單一辨識文字行的物件。

名稱 類型 Description
boundingBox

string

已辨識線條的周框方塊。 四個整數代表左邊緣的 X 座標、上邊緣的 Y 座標、寬度和周框方塊的高度,在輸入影像的座標系統中,根據偵測到的文字角度旋轉其中心之後, (看到 textAngle 屬性) ,並在左上角的原點旋轉之後, 和指向向下的 Y 軸。

words

OcrWord[]

對象的陣列,其中每個物件都代表已辨識的字組。

OcrRegion

區域包含多行 (,例如多欄檔中的文字列) 。

名稱 類型 Description
boundingBox

string

已辨識區域的周框方塊。 四個整數代表左邊緣的 X 座標、上邊緣的 Y 座標、寬度和周框方塊的高度,在輸入影像的座標系統中,根據偵測到的文字角度旋轉其中心之後, (看到 textAngle 屬性) ,並在左上角的原點旋轉之後, 和指向向下的 Y 軸。

lines

OcrLine[]

已辨識文字行的陣列。

OcrResult

名稱 類型 Description
language

string

影像中文字的 BCP-47 語言代碼。

orientation

string

如果要求,影像中辨識的文字方向。 值 (向上、向下、左或右) 是指辨識文字頂端正向的方向,在影像根據偵測到的文字角度 (看到 textAngle 屬性) 繞其中心旋轉。 如果未要求偵測方向,或未偵測到任何文字,則值為 『NotDetected』。

regions

OcrRegion[]

對象的陣列,其中每個物件都代表已辨識文字的區域。

textAngle

number

相對於最接近水準或垂直方向的偵測到文字的角度,以弧度為單位。 依這個角度順時針旋轉輸入影像之後,辨識的文字線會變成水準或垂直。 與方向屬性結合,它可以用來在原始影像上正確重迭辨識結果,方法是將原始影像旋轉,或以適當的角度繞原始影像中心旋轉辨識結果。 如果無法放心偵測角度,則此屬性不存在。 如果影像包含不同角度的文字,則只會正確辨識部分文字。

OcrWord

已辨識字的資訊。

名稱 類型 Description
boundingBox

string

已辨識文字的周框方塊。 四個整數代表左邊緣的 X 座標、上邊緣的 Y 座標、寬度和周框方塊的高度,在輸入影像的座標系統中,根據偵測到的文字角度旋轉其中心之後, (看到 textAngle 屬性) ,並在左上角的原點旋轉之後, 和指向向下的 Y 軸。

text

string

辨識文字的字串值。