最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

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

IT培训 admin 6浏览 0评论

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

使用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. 暂无评论