最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

使用Node.js设置语言提示的Google Vision API文本检测

运维笔记admin38浏览0评论

使用Node.js设置语言提示的Google Vision API文本检测

使用Node.js设置语言提示的Google Vision API文本检测

我在Node.js中使用@google-cloud/vision

我使用下面的示例代码

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);
  }
}

这目前正在工作,并返回英文文本和数字。我在图像中使用了Vision API的实验语言。如何将语言提示设置为在node.js 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],
});
发布评论

评论列表(0)

  1. 暂无评论