[英]Azure Cognitive Services - Vision API single call results in 9 transactions
I am using below method to detect text in an image. 我正在使用下面的方法来检测图像中的文本。 But a single execution of this method results in 9 transactions in my Azure dashboard. 但是,一次执行此方法将在我的Azure仪表板中产生9个事务。 Can someone please guide if I am missing something? 如果我缺少什么可以请人指导吗? or is there anything wrong with the code? 还是代码有什么问题?
public async Task<IActionResult> ConvertToText(string url)
{
string subscriptionKey = "jfh3879rhf4389terhkjy86";
ComputerVisionClient computerVision = new ComputerVisionClient(
new ApiKeyServiceClientCredentials(subscriptionKey),
new System.Net.Http.DelegatingHandler[] { });
// Specify the Azure region
computerVision.Endpoint = "https://westcentralus.api.cognitive.microsoft.com";
if (!Uri.IsWellFormedUriString(url, UriKind.Absolute))
{
return null;
}
TextRecognitionMode textRecognitionMode = TextRecognitionMode.Printed;
int numberOfCharsInOperationId = 36;
// Start the async process to recognize the text
RecognizeTextHeaders textHeaders =
await computerVision.RecognizeTextAsync(url, textRecognitionMode);
// Retrieve the URI where the recognized text will be
// stored from the Operation-Location header
string operationId = textHeaders.OperationLocation.Substring(
textHeaders.OperationLocation.Length - numberOfCharsInOperationId);
TextOperationResult result =
await computerVision.GetTextOperationResultAsync(operationId);
// Wait for the operation to complete
int i = 0;
int maxRetries = 10;
while ((result.Status == TextOperationStatusCodes.Running ||
result.Status == TextOperationStatusCodes.NotStarted) && i++ < maxRetries)
{
Console.WriteLine("Server status: {0}, waiting {1} seconds...", result.Status, i);
await Task.Delay(1000);
result = await computerVision.GetTextOperationResultAsync(operationId);
}
// Display the results
var lines = result.RecognitionResult.Lines;
string details = "";
foreach (Line line in lines)
{
details += line.Text + Environment.NewLine;
}
return Content(details);
}
Thank you. 谢谢。
Taken from the Cognitive Services pricing page : 取自“ 认知服务”定价页面 :
What constitutes a transaction for Computer Vision API? 什么是计算机视觉API的交易?
For Recognize Text each POST call counts as a transaction. 对于“识别文本”,每个POST调用都计为一个事务。 All GET calls to see the results of the async service are counted as transactions but are free of charge. 用于查看异步服务结果的所有GET调用均计为事务,但免费。
My guess would be that the 'issue' is in the while
-statement since you're getting the result while the job is (possibly) still running. 我的猜测是“问题”在while
语句中,因为您正在(可能)仍在运行作业时获得结果。 You're probably getting the status a couple of times before the job is done. 在完成工作之前,您可能已经获得了几次状态。 The good thing: those API calls are free. 好消息:这些API调用是免费的。
I see your code is the same as in the Quickstart: Extract text using the Computer Vision SDK and C# , so it should be OK. 我看到您的代码与快速入门中的代码相同:使用Computer Vision SDK和C#提取文本 ,因此应该可以。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.