ローカル ファイルのラベル検出
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
ローカルのドキュメント ファイルに対してラベル検出を実行します。
コードサンプル
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。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)."]]