1

I'm using @google-cloud/vision with Node.js

I use the sample code as below

async function quickstart() {
  try {
    // Imports the Google Cloud client library
    const vision = require('@google-cloud/vision');

    // Creates a client
    const client = new vision.ImageAnnotatorClient();

    // Performs label detection on the image file
    const [result] = await client.textDetection('./test.jpg');
    const texts = result.textAnnotations;
    console.log('Text:');
    texts.forEach((text: string) => console.log(text));
  } catch (err) {
    console.log(err);
  }
}

This is currently working working and return english texts and numbers. I have texts in image which Vision API's Experimental languages. How can I set the language hint as document specified in node.js API?

https://cloud.google.com/vision/docs/ocr

4

2 回答 2

1

您可以使用 batchAnnotateImages 方法。例如:类似:

const request = {
    features: [{type: 'TEXT_DETECTION'}],
    imageContext: {
        languageHints: ["en-t-i0-handwrit"]
    },
    <other parts of your request>
};
const [response] = await imageAnnotatorClient.batchAnnotateImages({
    requests: [request],
});
于 2019-09-30T22:19:42.813 回答
0

我用这个来检测我的高棉语身份证。 imageUri在这种情况下你可以使用任何地址,例如我输入来自谷歌的 url 地址。 languageHints这就是你想要的,把它改成你的 languageHints 代码 这是一个链接

async function quickstart() {
  const vision = require('@google-cloud/vision');

  const client = new vision.ImageAnnotatorClient();

  const request = {
    "requests": [
      {
        "image": {
          "source": {
            "imageUri": "https://pbs.twimg.com/media/Cm_Jj7hUEAALwRF.jpg"
          }
        },
        "features": [
          {
            "type": "DOCUMENT_TEXT_DETECTION"
          }
        ],
        "imageContext": {
          "languageHints": ["km"]
        }
      }
    ]
  };

  const [result] = await client.batchAnnotateImages(request);
  const detections = result.responses[0].fullTextAnnotation;
  console.log(detections.text);
}

quickstart().catch(console.error);

控制台文本时无法正确呈现的文本,只需将其复制到 word 或记事本即可。

于 2020-04-27T07:24:55.793 回答