简体   繁体   English

Azure认知服务-Vision API一次调用导致9笔交易

[英]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.

相关问题 如何调用 Azure 认知服务 API? - How to call Azure Cognitive Services API? Azure 计算机视觉和 Azure 认知服务之间的区别 - Difference between Azure Computer Vision and Azure Cognitive Services Azure认知服务:缺少的自定义视觉效果统计信息在哪里? - Azure Cognitive Services: Where are the missing Custom Vision Performance Statistics? Azure认知服务-计算机视觉有效,图像审核不起作用 - Azure cognitive services - Computer vision working, Image moderation doesn't Azure 认知服务计算机视觉在 QA 中失败,但在开发中完美运行 - Azure Cognitive Services Computer Vision fails in QA but works perfectly in dev Azure Cognitive Services Custom Vision:我可以使用V3.0 API实现find-similar-image功能吗? - Azure Cognitive Services Custom Vision: Can I implement a find-similar-image function using the V3.0 API? Azure 认知服务 - TTS - Azure Cognitive services - TTS Azure 认知服务 OCR 给出不同的结果 - 如何补救? - Azure Cognitive Services OCR giving differing results - how to remedy? Azure/Microsoft 认知服务自定义视觉 - 什么是对象检测模型输出张量规范? - Azure/Microsoft Cognitive Services Custom Vision - What is the Object Detection model output tensor specification? 如何访问Azure认知服务自定义视觉非美国终端节点? - How do I access Azure Cognitive Services Custom Vision non-US endpoints?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM