问题
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
回答1:
You can use the batchAnnotateImages method. Eg: something like:
const request = {
features: [{type: 'TEXT_DETECTION'}],
imageContext: {
languageHints: ["en-t-i0-handwrit"]
},
<other parts of your request>
};
const [response] = await imageAnnotatorClient.batchAnnotateImages({
requests: [request],
});
回答2:
I use this one to detect my id card in khmer language. imageUri you can use any adress in this case i put url address from google for example. languageHints this is what you want, change it to your languageHints code Here's a link!
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);
the text it's not render correctly when you console the text , just copy it to word or notepad.
来源:https://stackoverflow.com/questions/58138047/google-vision-api-text-detection-with-node-js-set-language-hint