Skip to content

Instantly share code, notes, and snippets.

@yhdesai
Created April 1, 2019 13:40
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yhdesai/7b33e4c00abddafb9eebe1585cd5127e to your computer and use it in GitHub Desktop.
Save yhdesai/7b33e4c00abddafb9eebe1585cd5127e to your computer and use it in GitHub Desktop.
Cloud Vision API NodeJS Sample
async function quickstart() {
const vision = require('@google-cloud/vision');
const client = new vision.ImageAnnotatorClient();
const fileName = 'hindi.png'
// Read a local image as a text document
const [result] = await client.documentTextDetection(fileName);
const fullTextAnnotation = result.fullTextAnnotation;
console.log(`Full text: ${fullTextAnnotation.text}`);
fullTextAnnotation.pages.forEach(page => {
page.blocks.forEach(block => {
console.log(`Block confidence: ${block.confidence}`);
block.paragraphs.forEach(paragraph => {
console.log(`Paragraph confidence: ${paragraph.confidence}`);
paragraph.words.forEach(word => {
const wordText = word.symbols.map(s => s.text).join('');
console.log(`Word text: ${wordText}`);
console.log(`Word confidence: ${word.confidence}`);
word.symbols.forEach(symbol => {
console.log(`Symbol text: ${symbol.text}`);
console.log(`Symbol confidence: ${symbol.confidence}`);
});
});
});
});
});
}
quickstart();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment