MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/nodejs-docs-samples / detectFulltext

Function detectFulltext

vision/detect.js:626–662  ·  view source on GitHub ↗
(fileName)

Source from the content-addressed store, hash-verified

624}
625
626async function detectFulltext(fileName) {
627 // [START vision_fulltext_detection]
628
629 // Imports the Google Cloud client library
630 const vision = require('@google-cloud/vision');
631
632 // Creates a client
633 const client = new vision.ImageAnnotatorClient();
634
635 /**
636 * TODO(developer): Uncomment the following line before running the sample.
637 */
638 // const fileName = 'Local image file, e.g. /path/to/image.png';
639
640 // Read a local image as a text document
641 const [result] = await client.documentTextDetection(fileName);
642 const fullTextAnnotation = result.fullTextAnnotation;
643 console.log(`Full text: ${fullTextAnnotation.text}`);
644 fullTextAnnotation.pages.forEach(page => {
645 page.blocks.forEach(block => {
646 console.log(`Block confidence: ${block.confidence}`);
647 block.paragraphs.forEach(paragraph => {
648 console.log(`Paragraph confidence: ${paragraph.confidence}`);
649 paragraph.words.forEach(word => {
650 const wordText = word.symbols.map(s => s.text).join('');
651 console.log(`Word text: ${wordText}`);
652 console.log(`Word confidence: ${word.confidence}`);
653 word.symbols.forEach(symbol => {
654 console.log(`Symbol text: ${symbol.text}`);
655 console.log(`Symbol confidence: ${symbol.confidence}`);
656 });
657 });
658 });
659 });
660 });
661 // [END vision_fulltext_detection]
662}
663
664async function detectFulltextGCS(bucketName, fileName) {
665 // [START vision_fulltext_detection_gcs]

Callers 1

detect.jsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected