如何使用 Google Cloud Vision API 为 Node JS 启用文本检测置信度分数

问题描述 投票:0回答:1

我使用 Google Cloud Vision API 进行的文本检测缺少置信度分数。更具体地说,除了语言特征之外,分数始终为 0。我正在使用 Node JS 构建 firebase 云函数。

我的问题类似于https://github.com/googleapis/python-vision/issues/266。提供的解决方案适用于 Python,但我需要与 Node JS 相同的解决方案。

我在 https://cloud.google.com/nodejs/docs/reference/vision/latest/vision/protos.google.cloud.vision.v1p3beta1.textdetectionparams#_google_cloud_vision_protos_google_cloud_vision_v1p3beta1_TextDetectionParams_enableTextDetectionConfidenceScore_member 找到了正确的 Node JS 参考

但我不知道如何实施。这些参考资料让我很困惑。我还没有学会如何使用它们。因此,任何有关如何同时使用这些参考文献的提示将不胜感激。

我尝试即兴创作并得到了这个:

const imageBucket = `gs://${object.bucket}/${object.name}`;

 const options = {
  "requests": [
    {   
      "features": [
        {
          "type": "DOCUMENT_TEXT_DETECTION"
        }
      ]
    }
  ]
}
 
 const client2 = new vision.ImageAnnotatorClient(options);

  const textDetectionParams = vision.TextDetectionParams({enableTextDetectionConfidenceScore: true})
  const imageContext = vision.ImageContext(textDetectionParams);
  
  
  const [textDetections] = await client2.textDetection(imageBucket, imageContext);

但这返回一个错误:TypeError: Vision.TextDetectionParams is not a function.

如有任何帮助,我们将不胜感激。

node.js google-cloud-vision
1个回答
0
投票

有一个简单的解决方案:

 const client = new vision.ImageAnnotatorClient();
  const imageBucket = `gs://${object.bucket}/${object.name}`;
  
  const [textDetections] = await client.documentTextDetection(imageBucket);
  

基本上,将 textDetection 更改为 documentTextDetection。这非常有效,我现在可以看到置信度分数。在这里了解更多信息:https://cloud.google.com/vision/docs/handwriting

© www.soinside.com 2019 - 2024. All rights reserved.