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

Function detectFulltext

vision/detect.v1p1beta1.js:17–61  ·  view source on GitHub ↗
(fileName)

Source from the content-addressed store, hash-verified

15'use strict';
16
17async function detectFulltext(fileName) {
18 // [START vision_detect_document]
19 // Imports the Google Cloud client libraries
20 const vision = require('@google-cloud/vision').v1p1beta1;
21
22 // Creates a client
23 const client = new vision.ImageAnnotatorClient();
24
25 /**
26 * TODO(developer): Uncomment the following line before running the sample.
27 */
28 // const fileName = 'Local image file, e.g. /path/to/image.png';
29
30 // Performs label detection on the local file
31 const [result] = await client.textDetection(fileName);
32 const pages = result.fullTextAnnotation.pages;
33 pages.forEach(page => {
34 page.blocks.forEach(block => {
35 const blockWords = [];
36 block.paragraphs.forEach(paragraph => {
37 paragraph.words.forEach(word => blockWords.push(word));
38 console.log(`Paragraph confidence: ${paragraph.confidence}`);
39 });
40
41 let blockText = '';
42 const blockSymbols = [];
43 blockWords.forEach(word => {
44 word.symbols.forEach(symbol => blockSymbols.push(symbol));
45 let wordText = '';
46 word.symbols.forEach(symbol => {
47 wordText = wordText + symbol.text;
48 console.log(`Symbol text: ${symbol.text}`);
49 console.log(`Symbol confidence: ${symbol.confidence}`);
50 });
51 console.log(`Word text: ${wordText}`);
52 console.log(`Word confidence: ${word.confidence}`);
53 blockText = blockText + ` ${wordText}`;
54 });
55
56 console.log(`Block text: ${blockText}`);
57 console.log(`Block confidence: ${block.confidence}`);
58 });
59 });
60 // [END vision_detect_document]
61}
62
63//.usage('$0 <command> <local-image-file>', 'Cloud Vision Beta API Samples')
64require('yargs')

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected