我正在使用下面的方法来检测图像中的文本。但是这个方法的一次执行就会在我的Azure仪表板中产生9个事务。如果我遗漏了什么,有人能帮我引路吗?或者代码有什么问题?
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);
}谢谢。
发布于 2019-01-23 20:38:40
摘自Cognitive Services pricing page
计算机视觉应用编程接口的事务处理是什么?
对于Recognize,每个POST调用都被算作一个事务。所有用于查看异步服务结果的GET调用都被计入事务,但都是免费的。
我的猜测是,“问题”出在while-statement中,因为您是在作业(可能)仍在运行时获得结果的。在工作完成之前,您可能会多次获得该状态。好消息是:这些API调用是免费的。
我看到您的代码与Quickstart: Extract text using the Computer Vision SDK and C#中的代码相同,所以应该没问题。
https://stackoverflow.com/questions/54326433
复制相似问题