对本地文件执行标签检测
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","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)."]]