Labelerkennung in einer lokalen Datei
Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Führt eine Labelerkennung für eine lokale Dokumentdatei durch.
Codebeispiel
Nächste Schritte
Wenn Sie nach Codebeispielen für andere Google Cloud -Produkte suchen und filtern möchten, können Sie den Google Cloud -Beispielbrowser verwenden.
Sofern nicht anders angegeben, sind die Inhalte dieser Seite unter der Creative Commons Attribution 4.0 License und Codebeispiele unter der Apache 2.0 License lizenziert. Weitere Informationen finden Sie in den Websiterichtlinien von Google Developers. Java ist eine eingetragene Marke von Oracle und/oder seinen Partnern.
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","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)."]]