page_type | languages | products | name | urlFragment | description | ||||
---|---|---|---|---|---|---|---|---|---|
sample |
|
|
ReadAPI 3.2 OCR skill for Azure Cognitive Search |
readapi-ocr-customskill |
This custom skill enables the OCR of the Computer Vision API of Azure Cognitive Services to be used with Azure Cognitive Serch. |
このカスタムスキルは、Azure Cognitive Services の Computer Vision API の OCR 機能を、Azure Cognitive Serch で使えるようにするスキルです。
本スキルは、Azure Cognitive Services の Computer Vision API が必要です。また、COMPUTER_VISION_ENDPOINT
と COMPUTER_VISION_KEY
が必要です。Azure Functions にデプロイする際は、「アプリケーション設定」項目に設定する必要があります。
- Azure portal で、 Computer Vision リソースを作成します。
- Computer Vision の API キーとエンドポイントをコピーします。
- このレポジトリを clone します。
- Visual Studio Code でレポジトリのフォルダを開き、Azure Functions にリモートデプロイします。
- Functions にデプロイが完了したら, Azure Portal の Azure Functions の設定→構成から、
COMPUTER_VISION_ENDPOINT
とCOMPUTER_VISION_KEY
環境変数にそれぞれ値を貼り付けます。
Azure Functions へデプロイする場合、以下が必要となります。
この Funcsions は、有効な Computer Vision API キーに設定された COMPUTER_VISION_KEY
の設定と、Computer Vision エンドポイント COMPUTER_VISION_ENDPOINT
を必要とします。
ローカルで実行する場合は、プロジェクトのローカル環境変数で設定することができます。これにより、API キーが誤ってコードに埋め込まれることがなくなります。
Azure Functions で実行する場合、これは「アプリケーションの設定」で設定できます。
カスタムスキルは $type と url、data 項目を Azure Cognitive Search から受け取ります。data 項目には Base64 エンコードされた画像データが格納されているので、デコードして Python の バイナリストリームにロードします。
{
"values": [
{
"recordId": "record1",
"data": {
"image": {
"$type": "file",
"url": "https://xxx.jpg",
"data": "/9j/4AAQS..."
}
}
}
]
}
{
"values": [
{
"recordId": "record1",
"ocrtext": "吾輩は猫である。名前はまだ無い。",
"errors": {}
}
]
}
このスキルを Azure Cognitive Search パイプラインで使用するには、スキル定義をスキルセットに追加する必要があります。この例のスキル定義の例を次に示します(特定のシナリオとスキルセット環境を反映するように入力と出力を更新する必要があります)。
{
"@odata.type": "#Microsoft.Skills.Custom.WebApiSkill",
"name": "ReadApiSkill",
"description": "Reads characters from a document using the Read API 3.2.",
"uri": "[AzureFunctionEndpointUrl]/api/AnalyzeForm?code=[AzureFunctionDefaultHostKey]",
"context": "/document/normalized_images/*",
"inputs": [
{
"name": "image",
"source": "/document/normalized_images/*"
}
],
"outputs": [
{
"name": "ocrtext",
"targetName": "ocrtext"
}
]
}