node.js - 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?
解决方案
您可以使用 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],
});
推荐阅读
- javascript - D3 折线图在鼠标悬停时未返回正确的值
- reactjs - 反应式编程和反应 JS 之间的关系
- spring - 通过 application.properties 文件在 Spring Boot 项目中禁用缓存不起作用
- vue.js - 路由器级别的 Vue 3 动态组件
- python-3.x - 如何在python defaultdict调用中放入变量
- javascript - 关于 JS 和 Class 的问题
- reactjs - Highlight.js 不适用于 react-markdown
- python - 使用 PyQT5 调整窗口大小 - 如何减小小部件的大小以缩小窗口?
- pandas - 对于 Pandas DataFrame,我如何访问在一列中具有特定值的行?
- firebase - firebase 命令不起作用。它总是显示 Pkg: Error reading from file