Detección de etiquetas en archivos locales
Organízate con las colecciones
Guarda y clasifica el contenido según tus preferencias.
Realiza la detección de etiquetas en un archivo de documento local.
Código de ejemplo
A menos que se indique lo contrario, el contenido de esta página está sujeto a la licencia Reconocimiento 4.0 de Creative Commons y las muestras de código están sujetas a la licencia Apache 2.0. Para obtener más información, consulta las políticas del sitio web de Google Developers. Java es una marca registrada de Oracle o sus afiliados.
[[["Es fácil de entender","easyToUnderstand","thumb-up"],["Me ofreció una solución al problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Es difícil de entender","hardToUnderstand","thumb-down"],["La información o el código de muestra no son correctos","incorrectInformationOrSampleCode","thumb-down"],["Me faltan las muestras o la información que necesito","missingTheInformationSamplesINeed","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Otro","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)."]]