首页 > 解决方案 > Google Vision API Text Detection with Node.js set Language hint

问题描述

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

标签: node.jsgoogle-cloud-platformvision-api

解决方案


您可以使用 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],
});

推荐阅读