【问题标题】:Computer vision Read api azure计算机视觉阅读 api azure
【发布时间】:2021-05-13 17:25:54
【问题描述】:

我尝试了 Read api of azure 从图像/pdf (https://eastus.dev.cognitive.microsoft.com/docs/services/computer-vision-v3-2/operations/5d986960601faab4bf452005/console) 读取文本,它工作正常,然后我尝试使用代码

var request = require('request');
var options = {
  'method': 'POST',
  'url': 'https://eastus.api.cognitive.microsoft.com/vision/v3.2/read/analyze?language=en&readingOrder=basic&model-version=latest',
  'headers': {
    'Host': 'eastus.api.cognitive.microsoft.com',
    'Content-Type': 'application/json',
    'Ocp-Apim-Subscription-Key': 'key'
  },
  body: JSON.stringify({"url":"url"})

};
request(options, function (error, response) {
  if (error) throw new Error(error);
  console.log("response",response.body);
});

response.body 没有返回任何值。有人可以帮我解决可能是什么问题吗?

【问题讨论】:

    标签: node.js azure ocr


    【解决方案1】:

    按照the doc 所示设计:

    当您调用 Read 操作时,调用会返回一个响应 标题称为“操作位置”。 “操作位置”标题 包含带有操作 ID 的 URL,将在第二步中使用。在 第二步,使用 Get Read Result 操作来获取 在 JSON 响应中检测到文本行和单词。

    响应体为空,可以在响应头中Operation-Location

    只需尝试以下代码即可获得Operation-Location 和最终结果:

    var request = require('request');
    
    var region = ''
    var key = ''
    var imageUrl = ""
    
    var options = {
      'method': 'POST',
      'url': `https://${region}.api.cognitive.microsoft.com/vision/v3.2/read/analyze?language=en&readingOrder=basic&model-version=latest`,
      'headers': {
        'Content-Type': 'application/json',
        'Ocp-Apim-Subscription-Key': key
      },
      body: JSON.stringify({"url":imageUrl})
    
    };
    
    
    request(options, function (error, response) {
        if (error) throw new Error(error);
    
        resultURL = response.headers['operation-location'];
        //print result URL
        console.log(resultURL)
    
        options.url= resultURL
        options.method='GET'
    
        //wait 5s to allow Azure process the image
        wait(5000).then(function(){
                request.get(options,function(error, result){
                    console.log(result.body)
                });
            })
    });
    
    function wait(ms) {
        return new Promise(resolve => setTimeout(() => resolve(), ms));
    };
    

    结果:

    【讨论】:

      猜你喜欢
      • 2023-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-18
      相关资源
      最近更新 更多