你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
OCR(读取)版
重要
选择最符合要求的阅读版本。
| 输入 | 例子 | 读取版本 | 好处 |
|---|---|---|---|
| 图片:常规、野外图像 | 标签、街道标志和海报 | 图像 OCR(版本 4.0) | 针对具有性能增强的同步 API 的常规非文档图像进行了优化,可更轻松地在用户体验方案中嵌入 OCR。 |
| 文档:数字和扫描,包括图像 | 书籍、文章和报表 | 文档智能读取模型 | 使用异步 API 针对文本密集型扫描文档和数字文档进行了优化,有助于大规模自动执行智能文档处理。 |
About Azure Vision v3.2 GA Read
正在查找最新的 Azure 视觉 v3.2 GA 读取? 所有将来的读取 OCR 增强功能都是前面列出的两项服务的一部分。 Azure Vision v3.2 没有进一步更新。 有关详细信息,请参阅 调用 Azure Vision 3.2 GA 读取 API 和 快速入门:Azure Vision v3.2 GA 读取。
在 Foundry 工具中通过读取 REST API 或使用客户端库开始使用 Azure Vision。 读取 API 提供了用于从图像中提取文本并将其作为结构化字符串返回的 AI 算法。 按照以下步骤将包安装到应用程序,并试用基本任务的示例代码。
使用光学字符识别(OCR)客户端库从图像中读取打印文本和手写文本。 OCR 服务可以读取图像中的可见文本并将其转换为字符流。 有关文本识别的详细信息,请参阅 OCR 概述。 本节中的代码使用 Foundry Tools 中的最新 Azure Vision 包。
提示
还可以从本地图像中提取文本。 请参阅 ComputerVisionClient 方法,例如 ReadInStreamAsync。 或者,有关涉及本地映像的方案,请参阅 GitHub 上的示例代码。
参考文档 | 库源代码 | 程序包(NuGet) | 示例
先决条件
- Azure订阅 - 免费创建一个订阅。
- Visual Studio IDE 或当前版本的 .NET Core。
-
Azure视觉资源。 可以使用免费定价层(
F0)试用该服务,稍后升级到生产付费层。 - 从创建的资源获取密钥和终结点,以便将应用程序连接到 Azure 视觉。
- Azure视觉资源部署后,选择“Go to resource。
- 在左窗格中,选择 “密钥和终结点”。
- 复制其中一个密钥和终结点,稍后你将在本快速入门中使用它们。
创建环境变量
在此示例中,将凭据写入运行应用程序的本地计算机上的环境变量。
转到Azure门户。 如果您在先决条件部分创建的资源已成功部署,请在后续步骤下选择转到资源。 可以在人脸资源的“密钥和终结点”页上的资源管理下找到密钥和终结点。 资源密钥与Azure订阅 ID 不同。
若要设置密钥和终结点的环境变量,请打开控制台窗口,并按照操作系统和开发环境的说明进行操作。
- 若要设置
VISION_KEY环境变量,请将<your_key>替换为资源的其中一个密钥。 - 要设置
VISION_ENDPOINT环境变量,请将<your_endpoint>替换为资源的终结点。
重要
我们建议使用 Azure 资源的托管标识进行 Microsoft Entra ID 身份验证,以避免将凭据随云中运行的应用程序一起存储。
请谨慎使用 API 密钥。 不要直接在代码中包括 API 密钥,并且从不公开发布。 如果使用 API 密钥,请安全地将其存储在Azure 密钥保管库中,定期轮换密钥,并使用基于角色的访问控制和网络访问限制来限制对Azure 密钥保管库的访问。 有关在应用中安全地使用 API 密钥的详细信息,请参阅 API 密钥和 Azure 密钥保管库。
有关 AI 服务安全性的详细信息,请参阅 请求 Azure AI 服务的身份验证。
setx VISION_KEY <your_key>
setx VISION_ENDPOINT <your_endpoint>
添加环境变量后,可能需要重启将读取环境变量的任何正在运行的程序,包括控制台窗口。
阅读印刷体文本和手写文本
创建新的 C# 应用程序。
使用 Visual Studio,创建一个 Console App(.NET Framework) 项目,用于 C#、Windows、Console。
创建新项目后,安装客户端库:
- 右键单击 解决方案资源管理器 中的项目解决方案,然后选择“管理解决方案的 NuGet 包”。
- 在打开的包管理器中,选择“ 浏览”。 选择 “包括预发行版”。
- 搜索并选择
Microsoft.Azure.CognitiveServices.Vision.ComputerVision。 - 在详细信息对话框中,选择项目并选择最新的稳定版本。 然后选择“ 安装”。
在项目目录中,在首选编辑器或 IDE 中打开 Program.cs 文件。 将 Program.cs 的内容替换为以下代码。
using System; using System.Collections.Generic; using Microsoft.Azure.CognitiveServices.Vision.ComputerVision; using Microsoft.Azure.CognitiveServices.Vision.ComputerVision.Models; using System.Threading.Tasks; using System.IO; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System.Threading; using System.Linq; namespace ComputerVisionQuickstart { class Program { // Add your Computer Vision key and endpoint static string key = Environment.GetEnvironmentVariable("VISION_KEY"); static string endpoint = Environment.GetEnvironmentVariable("VISION_ENDPOINT"); private const string READ_TEXT_URL_IMAGE = "https://raw.githubusercontent.com/Azure-Samples/cognitive-services-sample-data-files/master/ComputerVision/Images/printed_text.jpg"; static void Main(string[] args) { Console.WriteLine("Azure Cognitive Services Computer Vision - .NET quickstart example"); Console.WriteLine(); ComputerVisionClient client = Authenticate(endpoint, key); // Extract text (OCR) from a URL image using the Read API ReadFileUrl(client, READ_TEXT_URL_IMAGE).Wait(); } public static ComputerVisionClient Authenticate(string endpoint, string key) { ComputerVisionClient client = new ComputerVisionClient(new ApiKeyServiceClientCredentials(key)) { Endpoint = endpoint }; return client; } public static async Task ReadFileUrl(ComputerVisionClient client, string urlFile) { Console.WriteLine("----------------------------------------------------------"); Console.WriteLine("READ FILE FROM URL"); Console.WriteLine(); // Read text from URL var textHeaders = await client.ReadAsync(urlFile); // After the request, get the operation location (operation ID) string operationLocation = textHeaders.OperationLocation; Thread.Sleep(2000); // Retrieve the URI where the extracted text will be stored from the Operation-Location header. // We only need the ID and not the full URL const int numberOfCharsInOperationId = 36; string operationId = operationLocation.Substring(operationLocation.Length - numberOfCharsInOperationId); // Extract the text ReadOperationResult results; Console.WriteLine($"Extracting text from URL file {Path.GetFileName(urlFile)}..."); Console.WriteLine(); do { results = await client.GetReadResultAsync(Guid.Parse(operationId)); } while ((results.Status == OperationStatusCodes.Running || results.Status == OperationStatusCodes.NotStarted)); // Display the found text. Console.WriteLine(); var textUrlFileResults = results.AnalyzeResult.ReadResults; foreach (ReadResult page in textUrlFileResults) { foreach (Line line in page.Lines) { Console.WriteLine(line.Text); } } Console.WriteLine(); } } }作为可选步骤,请参阅 “确定如何处理数据”。 例如,若要显式指定最新的 GA 模型,请按如下所示编辑
ReadAsync调用。 跳过参数,或使用"latest"来应用最新的 GA 模型。// Read text from URL with a specific model version var textHeaders = await client.ReadAsync(urlFile,null,null,"2022-04-30");运行应用程序。
- 从 “调试 ”菜单中选择“ 开始调试”。
输出
Azure Vision - .NET quickstart example
----------------------------------------------------------
READ FILE FROM URL
Extracting text from URL file printed_text.jpg...
Nutrition Facts Amount Per Serving
Serving size: 1 bar (40g)
Serving Per Package: 4
Total Fat 13g
Saturated Fat 1.5g
Amount Per Serving
Trans Fat 0g
Calories 190
Cholesterol 0mg
Calories from Fat 110
Sodium 20mg
nt Daily Values are based on Vitamin A 50%
calorie diet.
清理资源
如果要清理和删除 Foundry Tools 订阅,可以删除资源或资源组。 删除资源组也会删除与之关联的任何其他资源。
- 使用 Azure 门户清理资源
使用 Azure CLI
后续步骤
本快速入门介绍了如何安装 OCR 客户端库并使用读取 API。 接下来,详细了解读取 API 功能。
使用光学字符识别(OCR)客户端库从远程图像读取打印文本和手写文本。 OCR 服务可以读取图像中的可见文本并将其转换为字符流。 有关文本识别的详细信息,请参阅 OCR 概述。
提示
还可以从本地图像读取文本。 请参阅 ComputerVisionClientOperationsMixin 方法,例如 read_in_stream。 或者,有关涉及本地映像的方案,请参阅 GitHub 上的示例代码。
先决条件
- Azure订阅 - 免费创建一个订阅。
- Python 3.x。
- Python安装应包括 pip。 你可以检查是否已安装 pip,可以在命令行上运行
pip --version。 通过安装最新版本的 Python 获取 pip。 -
Foundry Tools 中的 Azure Vision 资源。 可以使用免费定价层(
F0)试用该服务,稍后升级到生产付费层。 - 从创建的资源获取密钥和终结点,以便将应用程序连接到 Azure 视觉。
- Azure视觉资源部署后,选择“Go to resource。
- 在左窗格中,选择 “密钥和终结点”。
- 复制其中一个密钥和终结点,稍后你将在本快速入门中使用它们。
创建环境变量
在此示例中,将凭据写入运行应用程序的本地计算机上的环境变量。
转到Azure门户。 如果您在先决条件部分创建的资源已成功部署,请在后续步骤下选择转到资源。 可以在人脸资源的“密钥和终结点”页上的资源管理下找到密钥和终结点。 资源密钥与Azure订阅 ID 不同。
若要设置密钥和终结点的环境变量,请打开控制台窗口,并按照操作系统和开发环境的说明进行操作。
- 若要设置
VISION_KEY环境变量,请将<your_key>替换为资源的其中一个密钥。 - 要设置
VISION_ENDPOINT环境变量,请将<your_endpoint>替换为资源的终结点。
重要
我们建议使用 Azure 资源的托管标识进行 Microsoft Entra ID 身份验证,以避免将凭据随云中运行的应用程序一起存储。
请谨慎使用 API 密钥。 不要直接在代码中包括 API 密钥,并且从不公开发布。 如果使用 API 密钥,请安全地将其存储在Azure 密钥保管库中,定期轮换密钥,并使用基于角色的访问控制和网络访问限制来限制对Azure 密钥保管库的访问。 有关在应用中安全地使用 API 密钥的详细信息,请参阅 API 密钥和 Azure 密钥保管库。
有关 AI 服务安全性的详细信息,请参阅 请求 Azure AI 服务的身份验证。
setx VISION_KEY <your_key>
setx VISION_ENDPOINT <your_endpoint>
添加环境变量后,可能需要重启将读取环境变量的任何正在运行的程序,包括控制台窗口。
阅读印刷体文本和手写文本
安装客户端库。
在控制台窗口中运行以下命令:
pip install --upgrade azure-cognitiveservices-vision-computervision安装 Pillow 库。
pip install pillow创建新的Python应用程序文件,quickstart-file.py。 然后在首选编辑器或 IDE 中打开它。
将 quickstart-file.py 的内容替换为以下代码。
from azure.cognitiveservices.vision.computervision import ComputerVisionClient from azure.cognitiveservices.vision.computervision.models import OperationStatusCodes from azure.cognitiveservices.vision.computervision.models import VisualFeatureTypes from msrest.authentication import CognitiveServicesCredentials from array import array import os from PIL import Image import sys import time ''' Authenticate Authenticates your credentials and creates a client. ''' subscription_key = os.environ["VISION_KEY"] endpoint = os.environ["VISION_ENDPOINT"] computervision_client = ComputerVisionClient(endpoint, CognitiveServicesCredentials(subscription_key)) ''' END - Authenticate ''' ''' OCR: Read File using the Read API, extract text - remote This example will extract text in an image, then print results, line by line. This API call can also extract handwriting style text (not shown). ''' print("===== Read File - remote =====") # Get an image with text read_image_url = "https://learn.microsoft.com/azure/ai-services/computer-vision/media/quickstarts/presentation.png" # Call API with URL and raw response (allows you to get the operation location) read_response = computervision_client.read(read_image_url, raw=True) # Get the operation location (URL with an ID at the end) from the response read_operation_location = read_response.headers["Operation-Location"] # Grab the ID from the URL operation_id = read_operation_location.split("/")[-1] # Call the "GET" API and wait for it to retrieve the results while True: read_result = computervision_client.get_read_result(operation_id) if read_result.status not in ['notStarted', 'running']: break time.sleep(1) # Print the detected text, line by line if read_result.status == OperationStatusCodes.succeeded: for text_result in read_result.analyze_result.read_results: for line in text_result.lines: print(line.text) print(line.bounding_box) print() ''' END - Read File - remote ''' print("End of Computer Vision quickstart.")作为可选步骤,请参阅 “确定如何处理数据”。 例如,若要显式指定最新的 GA 模型,请按如下所示编辑
read语句。 跳过参数或使用"latest"自动使用最新的 GA 模型。# Call API with URL and raw response (allows you to get the operation location) read_response = computervision_client.read(read_image_url, raw=True, model_version="2022-04-30")使用快速入门文件中的
python命令运行应用程序。python quickstart-file.py
输出
===== Read File - remote =====
The quick brown fox jumps
[38.0, 650.0, 2572.0, 699.0, 2570.0, 854.0, 37.0, 815.0]
Over
[184.0, 1053.0, 508.0, 1044.0, 510.0, 1123.0, 184.0, 1128.0]
the lazy dog!
[639.0, 1011.0, 1976.0, 1026.0, 1974.0, 1158.0, 637.0, 1141.0]
End of Azure Vision quickstart.
清理资源
如果要清理和删除 Foundry Tools 订阅,可以删除资源或资源组。 删除资源组也会删除与之关联的任何其他资源。
- 使用 Azure 门户清理资源
使用 Azure CLI
后续步骤
本快速入门介绍了如何安装 OCR 客户端库并使用读取 API。 接下来,详细了解读取 API 功能。
使用光学字符识别(OCR)客户端库通过读取 API 读取打印文本和手写文本。 OCR 服务可以读取图像中的可见文本并将其转换为字符流。 有关文本识别的详细信息,请参阅 OCR 概述。
提示
还可以从本地图像读取文本。 请参阅 ComputerVisionClient 方法,例如 readInStream。 或者,有关涉及本地映像的方案,请参阅 GitHub 上的示例代码。
先决条件
- Azure订阅 - 免费创建一个订阅。
- Node.js 的当前 版本。
-
Foundry Tools 中的 Azure Vision 资源。 可以使用免费定价层(
F0)试用该服务,稍后升级到生产付费层。 - 从创建的资源获取密钥和终结点,以便将应用程序连接到 Azure 视觉。
- Azure视觉资源部署后,选择“Go to resource。
- 在左窗格中,选择 “密钥和终结点”。
- 复制其中一个密钥和终结点,稍后你将在本快速入门中使用它们。
创建环境变量
在此示例中,将凭据写入运行应用程序的本地计算机上的环境变量。
转到Azure门户。 如果您在先决条件部分创建的资源已成功部署,请在后续步骤下选择转到资源。 可以在人脸资源的“密钥和终结点”页上的资源管理下找到密钥和终结点。 资源密钥与Azure订阅 ID 不同。
若要设置密钥和终结点的环境变量,请打开控制台窗口,并按照操作系统和开发环境的说明进行操作。
- 若要设置
VISION_KEY环境变量,请将<your_key>替换为资源的其中一个密钥。 - 要设置
VISION_ENDPOINT环境变量,请将<your_endpoint>替换为资源的终结点。
重要
我们建议使用 Azure 资源的托管标识进行 Microsoft Entra ID 身份验证,以避免将凭据随云中运行的应用程序一起存储。
请谨慎使用 API 密钥。 不要直接在代码中包括 API 密钥,并且从不公开发布。 如果使用 API 密钥,请安全地将其存储在Azure 密钥保管库中,定期轮换密钥,并使用基于角色的访问控制和网络访问限制来限制对Azure 密钥保管库的访问。 有关在应用中安全地使用 API 密钥的详细信息,请参阅 API 密钥和 Azure 密钥保管库。
有关 AI 服务安全性的详细信息,请参阅 请求 Azure AI 服务的身份验证。
setx VISION_KEY <your_key>
setx VISION_ENDPOINT <your_endpoint>
添加环境变量后,可能需要重启将读取环境变量的任何正在运行的程序,包括控制台窗口。
阅读印刷体文本和手写文本
创建新的 Node.js 应用程序。
在控制台窗口中,为应用创建新目录,并导航到该目录。
mkdir myapp cd myappnpm init运行命令,创建包含package.json文件的节点应用程序。 对于任何提示,请选择 Enter 。npm init若要安装客户端库,请安装
ms-rest-azurenpm@azure/cognitiveservices-computervision包:npm install ms-rest-azure npm install @azure/cognitiveservices-computervision安装异步模块:
npm install async应用
package.json的文件随依赖项一起更新。创建新文件, index.js,并在文本编辑器中将其打开。
将以下代码粘贴到 index.js 文件中。
'use strict'; const async = require('async'); const fs = require('fs'); const https = require('https'); const path = require("path"); const createReadStream = require('fs').createReadStream const sleep = require('util').promisify(setTimeout); const ComputerVisionClient = require('@azure/cognitiveservices-computervision').ComputerVisionClient; const ApiKeyCredentials = require('@azure/ms-rest-js').ApiKeyCredentials; /** * AUTHENTICATE * This single client is used for all examples. */ const key = process.env.VISION_KEY; const endpoint = process.env.VISION_ENDPOINT; const computerVisionClient = new ComputerVisionClient( new ApiKeyCredentials({ inHeader: { 'Ocp-Apim-Subscription-Key': key } }), endpoint); /** * END - Authenticate */ function computerVision() { async.series([ async function () { /** * OCR: READ PRINTED & HANDWRITTEN TEXT WITH THE READ API * Extracts text from images using OCR (optical character recognition). */ console.log('-------------------------------------------------'); console.log('READ PRINTED, HANDWRITTEN TEXT AND PDF'); console.log(); // URL images containing printed and/or handwritten text. // The URL can point to image files (.jpg/.png/.bmp) or multi-page files (.pdf, .tiff). const printedTextSampleURL = 'https://raw.githubusercontent.com/Azure-Samples/cognitive-services-sample-data-files/master/ComputerVision/Images/printed_text.jpg'; // Recognize text in printed image from a URL console.log('Read printed text from URL...', printedTextSampleURL.split('/').pop()); const printedResult = await readTextFromURL(computerVisionClient, printedTextSampleURL); printRecText(printedResult); // Perform read and await the result from URL async function readTextFromURL(client, url) { // To recognize text in a local image, replace client.read() with readTextInStream() as shown: let result = await client.read(url); // Operation ID is last path segment of operationLocation (a URL) let operation = result.operationLocation.split('/').slice(-1)[0]; // Wait for read recognition to complete // result.status is initially undefined, since it's the result of read while (result.status !== "succeeded") { await sleep(1000); result = await client.getReadResult(operation); } return result.analyzeResult.readResults; // Return the first page of result. Replace [0] with the desired page if this is a multi-page file such as .pdf or .tiff. } // Prints all text from Read result function printRecText(readResults) { console.log('Recognized text:'); for (const page in readResults) { if (readResults.length > 1) { console.log(`==== Page: ${page}`); } const result = readResults[page]; if (result.lines.length) { for (const line of result.lines) { console.log(line.words.map(w => w.text).join(' ')); } } else { console.log('No recognized text.'); } } } /** * * Download the specified file in the URL to the current local folder * */ function downloadFilesToLocal(url, localFileName) { return new Promise((resolve, reject) => { console.log('--- Downloading file to local directory from: ' + url); const request = https.request(url, (res) => { if (res.statusCode !== 200) { console.log(`Download sample file failed. Status code: ${res.statusCode}, Message: ${res.statusMessage}`); reject(); } var data = []; res.on('data', (chunk) => { data.push(chunk); }); res.on('end', () => { console.log(' ... Downloaded successfully'); fs.writeFileSync(localFileName, Buffer.concat(data)); resolve(); }); }); request.on('error', function (e) { console.log(e.message); reject(); }); request.end(); }); } /** * END - Recognize Printed & Handwritten Text */ console.log(); console.log('-------------------------------------------------'); console.log('End of quickstart.'); }, function () { return new Promise((resolve) => { resolve(); }) } ], (err) => { throw (err); }); } computerVision();作为可选步骤,请参阅 “确定如何处理数据”。 例如,若要显式指定最新的 GA 模型,请按如下所示编辑
read语句。 跳过参数或使用"latest"自动使用最新的 GA 模型。let result = await client.read(url,{modelVersion:"2022-04-30"});使用快速入门文件中的
node命令运行应用程序。node index.js
输出
-------------------------------------------------
READ PRINTED, HANDWRITTEN TEXT AND PDF
Read printed text from URL... printed_text.jpg
Recognized text:
Nutrition Facts Amount Per Serving
Serving size: 1 bar (40g)
Serving Per Package: 4
Total Fat 13g
Saturated Fat 1.5g
Amount Per Serving
Trans Fat 0g
Calories 190
Cholesterol 0mg
ories from Fat 110
Sodium 20mg
nt Daily Values are based on Vitamin A 50%
calorie diet.
-------------------------------------------------
End of quickstart.
清理资源
如果要清理和删除 Foundry Tools 订阅,可以删除资源或资源组。 删除资源组也会删除与之关联的任何其他资源。
- 使用 Azure 门户清理资源
使用 Azure CLI
后续步骤
本快速入门介绍了如何安装 OCR 客户端库并使用读取 API。 接下来,详细了解读取 API 功能。
使用光学字符识别 (OCR) REST API 读取打印文本和手写文本。
注意
本快速入门使用 cURL 命令调用 REST API。 还可以使用编程语言调用 REST API。 有关 C#、Python、Java 和 JavaScript 中的示例,请参阅GitHub示例。
先决条件
- Azure订阅 - 免费创建一个订阅。
- 已安装 cURL。
-
Foundry Tools 中的 Azure Vision 资源。 可以使用免费定价层(
F0)试用该服务,稍后升级到生产付费层。 - 从创建的资源获取密钥和终结点,以便将应用程序连接到 Azure 视觉。
- Azure视觉资源部署后,选择“Go to resource。
- 在左窗格中,选择 “密钥和终结点”。
- 复制其中一个密钥和终结点,稍后你将在本快速入门中使用它们。
阅读印刷体文本和手写文本
光学字符识别(OCR)服务可以提取图像或文档中的可见文本并将其转换为字符流。 有关文本提取的详细信息,请参阅 OCR 概述。
调用 Read API
若要创建并运行示例,请执行以下步骤:
将以下命令复制到文本编辑器中。
根据需要在命令中进行以下更改:
- 将
<key>的值替换为您的密钥。 - 将请求 URL 的第一部分 (
https://westcentralus.api.cognitive.microsoft.com/) 替换为你自己的终结点 URL 中的文本。注意
2019 年 7 月 1 日之后创建的新资源将使用自定义子域名称。 有关详细信息和区域终结点的完整列表,请参阅 Foundry 工具的自定义子域名称。
- (可选)将请求正文
https://learn.microsoft.com/azure/ai-services/computer-vision/media/quickstarts/presentation.png中的图像 URL 更改为要分析的其他图像的 URL。
- 将
打开命令提示符窗口。
将命令从文本编辑器粘贴到命令提示符窗口中,然后运行该命令。
curl -v -X POST "https://westcentralus.api.cognitive.microsoft.com/vision/v3.2/read/analyze" -H "Content-Type: application/json" -H "Ocp-Apim-Subscription-Key: <subscription key>" --data-ascii "{'url':'https://learn.microsoft.com/azure/ai-services/computer-vision/media/quickstarts/presentation.png'}"
响应包括一个Operation-Location标头,其值为一个唯一的URL。 使用此 URL 查询读取操作的结果。 URL 将在 48 小时内过期。
(可选)指定模型版本
作为可选步骤,请参阅 “确定如何处理数据”。 例如,若要显式指定最新的 GA 模型,请使用 model-version=2022-04-30 参数。 跳过参数或使用 model-version=latest 自动使用最新的 GA 模型。
curl -v -X POST "https://westcentralus.api.cognitive.microsoft.com/vision/v3.2/read/analyze?model-version=2022-04-30" -H "Content-Type: application/json" -H "Ocp-Apim-Subscription-Key: <subscription key>" --data-ascii "{'url':'https://learn.microsoft.com/azure/ai-services/computer-vision/media/quickstarts/presentation.png'}"
获取读取结果
将以下命令复制到文本编辑器中。
将该 URL 替换为在之前过程中复制的
Operation-Location值。将
<key>的值替换为您的密钥。打开控制台窗口。
将文本编辑器中的命令粘贴到控制台窗口中,然后运行该命令。
curl -v -X GET "https://westcentralus.api.cognitive.microsoft.com/vision/v3.2/read/analyzeResults/{operationId}" -H "Ocp-Apim-Subscription-Key: {key}" --data-ascii "{body}"
检查响应
成功响应以 JSON 形式返回。 示例应用程序在控制台窗口中分析和显示成功的响应,类似于以下示例:
{
"status": "succeeded",
"createdDateTime": "2021-04-08T21:56:17.6819115+00:00",
"lastUpdatedDateTime": "2021-04-08T21:56:18.4161316+00:00",
"analyzeResult": {
"version": "3.2",
"readResults": [
{
"page": 1,
"angle": 0,
"width": 338,
"height": 479,
"unit": "pixel",
"lines": [
{
"boundingBox": [
25,
14,
318,
14,
318,
59,
25,
59
],
"text": "NOTHING",
"appearance": {
"style": {
"name": "other",
"confidence": 0.971
}
},
"words": [
{
"boundingBox": [
27,
15,
294,
15,
294,
60,
27,
60
],
"text": "NOTHING",
"confidence": 0.994
}
]
}
]
}
]
}
}
清理资源
如果要清理和删除 Foundry Tools 订阅,可以删除资源或资源组。 删除资源组也会删除与之关联的任何其他资源。
- 使用 Azure 门户清理资源
使用 Azure CLI
后续步骤
本快速入门介绍了如何调用读取 REST API。 接下来,详细了解读取 API 功能。