Created
April 1, 2019 13:40
-
-
Save yhdesai/7b33e4c00abddafb9eebe1585cd5127e to your computer and use it in GitHub Desktop.
Cloud Vision API NodeJS Sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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