Label detection on a local file
Stay organized with collections
Save and categorize content based on your preferences.
Performs label detection on a local document file.
Code sample
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],[],[],[],null,["# Label detection on a local file\n\nPerforms label detection on a local document file.\n\nCode sample\n-----------\n\n### Node.js\n\n\nBefore trying this sample, follow the Node.js setup instructions in the\n[Vision quickstart using\nclient libraries](/vision/docs/quickstart-client-libraries).\n\n\nFor more information, see the\n[Vision Node.js API\nreference documentation](https://googleapis.dev/nodejs/vision/latest).\n\n\nTo authenticate to Vision, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n // Imports the Google Cloud client libraries\n const vision = require('https://cloud.google.com/nodejs/docs/reference/vision/latest/overview.html').v1p1beta1;\n\n // Creates a client\n const client = new vision.https://cloud.google.com/nodejs/docs/reference/vision/latest/overview.html();\n\n /**\n * TODO(developer): Uncomment the following line before running the sample.\n */\n // const fileName = 'Local image file, e.g. /path/to/image.png';\n\n // Performs label detection on the local file\n const [result] = await client.textDetection(fileName);\n const pages = https://cloud.google.com/nodejs/docs/reference/vision/latest/vision/protos.google.longrunning.operation.html.fullTextAnnotation.pages;\n pages.forEach(page =\u003e {\n page.blocks.forEach(block =\u003e {\n const blockWords = [];\n block.paragraphs.forEach(paragraph =\u003e {\n paragraph.words.forEach(word =\u003e blockWords.push(word));\n console.log(`Paragraph confidence: ${paragraph.confidence}`);\n });\n\n let blockText = '';\n const blockSymbols = [];\n blockWords.forEach(word =\u003e {\n word.symbols.forEach(symbol =\u003e blockSymbols.push(symbol));\n let wordText = '';\n word.symbols.forEach(symbol =\u003e {\n wordText = wordText + symbol.text;\n console.log(`Symbol text: ${symbol.text}`);\n console.log(`Symbol confidence: ${symbol.confidence}`);\n });\n console.log(`Word text: ${wordText}`);\n console.log(`Word confidence: ${word.confidence}`);\n blockText = blockText + ` ${wordText}`;\n });\n\n console.log(`Block text: ${blockText}`);\n console.log(`Block confidence: ${block.confidence}`);\n });\n });\n\nWhat's next\n-----------\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=vision)."]]