diff --git a/.cloud-repo-tools.json b/.cloud-repo-tools.json index 354f8b8d..0244ee6c 100644 --- a/.cloud-repo-tools.json +++ b/.cloud-repo-tools.json @@ -11,6 +11,13 @@ "file": "detect.js", "docs_link": "https://cloud.google.com/vision/docs", "usage": "node detect.js --help" + }, + { + "id": "detect.v1p1beta1.js", + "name": "Detection samples for Beta API", + "file": "detect.v1p1beta1.js", + "docs_link": "https://cloud.google.com/vision/docs", + "usage": "node detect.v1p1beta1.js --help" } ] } diff --git a/CONTRIBUTORS b/CONTRIBUTORS index caefac6e..96b20b80 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -15,4 +15,5 @@ Song Wang Stephen Sawchuk Tim Swast calibr +Rebecca Taylor rtw diff --git a/README.md b/README.md index 50f9d32e..d04cca85 100644 --- a/README.md +++ b/README.md @@ -91,6 +91,7 @@ has instructions for running the samples. | Sample | Source Code | Try it | | --------------------------- | --------------------------------- | ------ | | Detection samples | [source code](https://github.com/googleapis/nodejs-vision/blob/master/samples/detect.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-vision&page=editor&open_in_editor=samples/detect.js,samples/README.md) | +| Detection samples for Beta API | [source code](https://github.com/googleapis/nodejs-vision/blob/master/samples/detect.v1p1beta1.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-vision&page=editor&open_in_editor=samples/detect.v1p1beta1.js,samples/README.md) | The [Vision API Node.js Client API Reference][client-docs] documentation also contains samples. diff --git a/package.json b/package.json index 7d9e994b..e2a4d7b2 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ "Stephen Sawchuk ", "Tim Swast ", "calibr ", + "Rebecca Taylor ", "rtw " ], "scripts": { diff --git a/samples/README.md b/samples/README.md index 8d78307f..9ab0b895 100644 --- a/samples/README.md +++ b/samples/README.md @@ -11,6 +11,7 @@ The [Cloud Vision API](https://cloud.google.com/vision/docs) allows developers t * [Before you begin](#before-you-begin) * [Samples](#samples) * [Detection samples](#detection-samples) + * [Detection samples for Beta API](#detection-samples-for-beta-api) ## Before you begin @@ -86,5 +87,39 @@ For more information, see https://cloud.google.com/vision/docs [detect_0_docs]: https://cloud.google.com/vision/docs [detect_0_code]: detect.js +### Detection samples for Beta API + +View the [source code][detect.v1p1beta1.js_1_code]. + +[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-vision&page=editor&open_in_editor=samples/detect.v1p1beta1.js,samples/README.md) + +__Usage:__ `node detect.v1p1beta1.js --help` + +``` +detect.v1p1beta1.js + +Commands: + detect.v1p1beta1.js web-entities-geo Detects web entities with improved results using geographic metadata + detect.v1p1beta1.js safe-search Detects safe search properties including additional racy category + detect.v1p1beta1.js web Detects web entities including new best guess labels describing + content + detect.v1p1beta1.js fulltext Extracts full text from an image file including new confidence scores + +Options: + --version Show version number [boolean] + --help Show help [boolean] + +Examples: + node detect.v1p1beta1.js safe-search ./resources/wakeupcat.jpg + node detect.v1p1beta1.js web-entities-geo ./resources/city.jpg + node detect.v1p1beta1.js web ./resources/wakeupcat.jpg + node detect.v1p1beta1.js fulltext ./resources/wakeupcat.jpg + +For more information, see https://cloud.google.com/vision/docs +``` + +[detect.v1p1beta1.js_1_docs]: https://cloud.google.com/vision/docs +[detect.v1p1beta1.js_1_code]: detect.v1p1beta1.js + [shell_img]: http://gstatic.com/cloudssh/images/open-btn.png [shell_link]: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-vision&page=editor&open_in_editor=samples/README.md diff --git a/samples/detect.v1p1beta1.js b/samples/detect.v1p1beta1.js index 641a6749..f2bc9897 100644 --- a/samples/detect.v1p1beta1.js +++ b/samples/detect.v1p1beta1.js @@ -15,16 +15,12 @@ 'use strict'; -// 1. imports -// 2. web detection geotgging -// 3. text detection vision_detect_document -// 4. safe search -// 5. print detect annotations - -function detectText(fileName) { +function detectFulltext(fileName) { // [START vision_detect_document] + // [START imports] // Imports the Google Cloud client libraries const vision = require('@google-cloud/vision').v1p1beta1; + // [END imports] // Creates a client const client = new vision.ImageAnnotatorClient(); @@ -44,7 +40,7 @@ function detectText(fileName) { const blockWords = []; block.paragraphs.forEach(paragraph => { paragraph.words.forEach(word => blockWords.push(word)); - console.log(`Paragraph Confidence: ${paragraph.confidence.toFixed(2)}`); + console.log(`Paragraph confidence: ${paragraph.confidence}`); }); let blockText = ''; @@ -54,16 +50,16 @@ function detectText(fileName) { let wordText = ''; word.symbols.forEach(symbol => { wordText = wordText + symbol.text; - console.log(` Symbol text: ${symbol.text}`); - console.log(` Confidence: ${symbol.confidence.toFixed(2)}`); + console.log(`Symbol text: ${symbol.text}`); + console.log(`Symbol confidence: ${symbol.confidence}`); }); console.log(`Word text: ${wordText}`); - console.log(`Confidence: ${word.confidence.toFixed(2)}`); + console.log(`Word confidence: ${word.confidence}`); blockText = blockText + ` ${wordText}`; }); - console.log(`Block content: ${blockText}`); - console.log(`Block confidence: ${block.confidence.toFixed(2)}`); + console.log(`Block text: ${blockText}`); + console.log(`Block confidence: ${block.confidence}`); }); }); }) @@ -73,240 +69,9 @@ function detectText(fileName) { // [END vision_detect_document] } - -function detectFaces(fileName) { - // [START vision_face_detection] - // Imports the Google Cloud client library - const vision = require('@google-cloud/vision').v1p1beta1; - - // Creates a client - const client = new vision.ImageAnnotatorClient(); - - /** - * TODO(developer): Uncomment the following line before running the sample. - */ - // const fileName = 'Local image file, e.g. /path/to/image.png'; - - client - .faceDetection(fileName) - .then(results => { - const faces = results[0].faceAnnotations; - - console.log('Faces:'); - faces.forEach((face, i) => { - console.log(` Face #${i + 1}:`); - console.log(` Joy: ${face.joyLikelihood}`); - console.log(` Anger: ${face.angerLikelihood}`); - console.log(` Sorrow: ${face.sorrowLikelihood}`); - console.log(` Surprise: ${face.surpriseLikelihood}`); - }); - }) - .catch(err => { - console.error('ERROR:', err); - }); - // [END vision_face_detection] -} - -function detectFacesGCS(bucketName, fileName) { - // [START vision_face_detection_gcs] - // Imports the Google Cloud client libraries - const vision = require('@google-cloud/vision').v1p1beta1; - - // Creates a client - const client = new vision.ImageAnnotatorClient(); - - /** - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const bucketName = 'Bucket where the file resides, e.g. my-bucket'; - // const fileName = 'Path to file within bucket, e.g. path/to/image.png'; - - // Performs face detection on the gcs file - client - .faceDetection(`gs://${bucketName}/${fileName}`) - .then(results => { - const faces = results[0].faceAnnotations; - - console.log('Faces:'); - faces.forEach((face, i) => { - console.log(` Face #${i + 1}:`); - console.log(` Joy: ${face.joyLikelihood}`); - console.log(` Anger: ${face.angerLikelihood}`); - console.log(` Sorrow: ${face.sorrowLikelihood}`); - console.log(` Surprise: ${face.surpriseLikelihood}`); - }); - }) - .catch(err => { - console.error('ERROR:', err); - }); - // [END vision_face_detection_gcs] -} - -function detectLabels(fileName) { - // [START vision_label_detection] - // Imports the Google Cloud client library - const vision = require('@google-cloud/vision').v1p1beta1; - - // Creates a client - const client = new vision.ImageAnnotatorClient(); - - /** - * TODO(developer): Uncomment the following line before running the sample. - */ - // const fileName = 'Local image file, e.g. /path/to/image.png'; - - // Performs label detection on the local file - client - .labelDetection(fileName) - .then(results => { - const labels = results[0].labelAnnotations; - console.log('Labels:'); - labels.forEach(label => console.log(label)); - }) - .catch(err => { - console.error('ERROR:', err); - }); - // [END vision_label_detection] -} - -function detectLabelsGCS(bucketName, fileName) { - // [START vision_label_detection_gcs] - // Imports the Google Cloud client libraries - const vision = require('@google-cloud/vision').v1p1beta1; - - // Creates a client - const client = new vision.ImageAnnotatorClient(); - - /** - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const bucketName = 'Bucket where the file resides, e.g. my-bucket'; - // const fileName = 'Path to file within bucket, e.g. path/to/image.png'; - - // Performs label detection on the gcs file - client - .labelDetection(`gs://${bucketName}/${fileName}`) - .then(results => { - const labels = results[0].labelAnnotations; - console.log('Labels:'); - labels.forEach(label => console.log(label)); - }) - .catch(err => { - console.error('ERROR:', err); - }); - // [END vision_label_detection_gcs] -} - -function detectLandmarks(fileName) { - // [START vision_landmark_detection] - const vision = require('@google-cloud/vision').v1p1beta1; - - // Creates a client - const client = new vision.ImageAnnotatorClient(); - - /** - * TODO(developer): Uncomment the following line before running the sample. - */ - // const fileName = 'Local image file, e.g. /path/to/image.png'; - - // Performs landmark detection on the local file - client - .landmarkDetection(fileName) - .then(results => { - const landmarks = results[0].landmarkAnnotations; - console.log('Landmarks:'); - landmarks.forEach(landmark => console.log(landmark)); - }) - .catch(err => { - console.error('ERROR:', err); - }); - // [END vision_landmark_detection] -} - -function detectLandmarksGCS(bucketName, fileName) { - // [START vision_landmark_detection_gcs] - // Imports the Google Cloud client libraries - const vision = require('@google-cloud/vision').v1p1beta1; - - // Creates a client - const client = new vision.ImageAnnotatorClient(); - - /** - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const bucketName = 'Bucket where the file resides, e.g. my-bucket'; - // const fileName = 'Path to file within bucket, e.g. path/to/image.png'; - - // Performs landmark detection on the gcs file - client - .landmarkDetection(`gs://${bucketName}/${fileName}`) - .then(results => { - const landmarks = results[0].landmarkAnnotations; - console.log('Landmarks:'); - landmarks.forEach(landmark => console.log(landmark)); - }) - .catch(err => { - console.error('ERROR:', err); - }); - // [END vision_landmark_detection_gcs] -} - -function detectProperties(fileName) { - // [START vision_image_property_detection] - const vision = require('@google-cloud/vision').v1p1beta1; - - // Creates a client - const client = new vision.ImageAnnotatorClient(); - - /** - * TODO(developer): Uncomment the following line before running the sample. - */ - // const fileName = 'Local image file, e.g. /path/to/image.png'; - - // Performs property detection on the local file - client - .imageProperties(fileName) - .then(results => { - const properties = results[0].imagePropertiesAnnotation; - const colors = properties.dominantColors.colors; - colors.forEach(color => console.log(color)); - }) - .catch(err => { - console.error('ERROR:', err); - }); - // [END vision_image_property_detection] -} - -function detectPropertiesGCS(bucketName, fileName) { - // [START vision_image_property_detection_gcs] - // Imports the Google Cloud client libraries - const vision = require('@google-cloud/vision').v1p1beta1; - - // Creates a client - const client = new vision.ImageAnnotatorClient(); - - /** - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const bucketName = 'Bucket where the file resides, e.g. my-bucket'; - // const fileName = 'Path to file within bucket, e.g. path/to/image.png'; - - // Performs property detection on the gcs file - client - .imageProperties(`gs://${bucketName}/${fileName}`) - .then(results => { - const properties = results[0].imagePropertiesAnnotation; - const colors = properties.dominantColors.colors; - colors.forEach(color => console.log(color)); - }) - .catch(err => { - console.error('ERROR:', err); - }); - // [END vision_image_property_detection_gcs] -} - function detectSafeSearch(fileName) { // [START vision_safe_search_detection] + // Imports the Google Cloud client library const vision = require('@google-cloud/vision').v1p1beta1; // Creates a client @@ -323,118 +88,21 @@ function detectSafeSearch(fileName) { .then(results => { const detections = results[0].safeSearchAnnotation; + console.log('Safe search:'); console.log(`Adult: ${detections.adult}`); - console.log(`Spoof: ${detections.spoof}`); console.log(`Medical: ${detections.medical}`); - console.log(`Violence: ${detections.violence}`); - }) - .catch(err => { - console.error('ERROR:', err); - }); - // [END vision_safe_search_detection] -} - -function detectSafeSearchGCS(bucketName, fileName) { - // [START vision_safe_search_detection_gcs] - // Imports the Google Cloud client libraries - const vision = require('@google-cloud/vision').v1p1beta1; - - // Creates a client - const client = new vision.ImageAnnotatorClient(); - - /** - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const bucketName = 'Bucket where the file resides, e.g. my-bucket'; - // const fileName = 'Path to file within bucket, e.g. path/to/image.png'; - - // Performs safe search property detection on the remote file - client - .safeSearchDetection(`gs://${bucketName}/${fileName}`) - .then(results => { - const detections = results[0].safeSearchAnnotation; - - console.log(`Adult: ${detections.adult}`); console.log(`Spoof: ${detections.spoof}`); - console.log(`Medical: ${detections.medical}`); console.log(`Violence: ${detections.violence}`); + console.log(`Racy: ${detections.racy}`); }) .catch(err => { console.error('ERROR:', err); }); - // [END vision_safe_search_detection_gcs] -} - -function detectCropHints(fileName) { - // [START vision_crop_hint_detection] - - // Imports the Google Cloud client library - const vision = require('@google-cloud/vision').v1p1beta1; - - // Creates a client - const client = new vision.ImageAnnotatorClient(); - - /** - * TODO(developer): Uncomment the following line before running the sample. - */ - // const fileName = 'Local image file, e.g. /path/to/image.png'; - - // Find crop hints for the local file - client - .cropHints(fileName) - .then(results => { - const cropHints = results[0].cropHintsAnnotation; - - cropHints.cropHints.forEach((hintBounds, hintIdx) => { - console.log(`Crop Hint ${hintIdx}:`); - hintBounds.boundingPoly.vertices.forEach((bound, boundIdx) => { - console.log(` Bound ${boundIdx}: (${bound.x}, ${bound.y})`); - }); - }); - }) - .catch(err => { - console.error('ERROR:', err); - }); - // [END vision_crop_hint_detection] -} - -function detectCropHintsGCS(bucketName, fileName) { - // [START vision_crop_hint_detection_gcs] - - // Imports the Google Cloud client libraries - const vision = require('@google-cloud/vision').v1p1beta1; - - // Creates a client - const client = new vision.ImageAnnotatorClient(); - - /** - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const bucketName = 'Bucket where the file resides, e.g. my-bucket'; - // const fileName = 'Path to file within bucket, e.g. path/to/image.png'; - - // Find crop hints for the remote file - client - .cropHints(`gs://${bucketName}/${fileName}`) - .then(results => { - const cropHints = results[0].cropHintsAnnotation; - - cropHints.cropHints.forEach((hintBounds, hintIdx) => { - console.log(`Crop Hint ${hintIdx}:`); - hintBounds.boundingPoly.vertices.forEach((bound, boundIdx) => { - console.log(` Bound ${boundIdx}: (${bound.x}, ${bound.y})`); - }); - }); - }) - .catch(err => { - console.error('ERROR:', err); - }); - // [END vision_crop_hint_detection_gcs] + // [END vision_safe_search_detection] } function detectWeb(fileName) { // [START vision_web_detection] - // Imports the Google Cloud client library const vision = require('@google-cloud/vision').v1p1beta1; @@ -452,68 +120,45 @@ function detectWeb(fileName) { .then(results => { const webDetection = results[0].webDetection; - if (webDetection.fullMatchingImages.length) { - console.log( - `Full matches found: ${webDetection.fullMatchingImages.length}` - ); - webDetection.fullMatchingImages.forEach(image => { - console.log(` URL: ${image.url}`); - console.log(` Score: ${image.score}`); + if (webDetection.bestGuessLabels.length) { + webDetection.bestGuessLabels.forEach(label => { + console.log(`Best guess label: ${label.label}`); }); } - if (webDetection.partialMatchingImages.length) { - console.log( - `Partial matches found: ${webDetection.partialMatchingImages.length}` - ); - webDetection.partialMatchingImages.forEach(image => { - console.log(` URL: ${image.url}`); - console.log(` Score: ${image.score}`); - }); - } + if (webDetection.pagesWithMatchingImages.length) { + const pages = webDetection.pagesWithMatchingImages; + console.log(`Pages with matching images found: ${pages.length}`); - if (webDetection.webEntities.length) { - console.log(`Web entities found: ${webDetection.webEntities.length}`); - webDetection.webEntities.forEach(webEntity => { - console.log(` Description: ${webEntity.description}`); - console.log(` Score: ${webEntity.score}`); + pages.forEach(page => { + console.log(`Page url: ${page.url}`); + + if (page.fullMatchingImages.length) { + const fullMatchingImages = page.fullMatchingImages; + console.log(`Full Matches found: ${fullMatchingImages.length}`); + fullMatchingImages.forEach(image => { + console.log(`Image url: ${image.url}`); + }); + } + + if (page.partialMatchingImages.length) { + const partialMatchingImages = page.partialMatchingImages; + console.log( + `Partial Matches found: ${partialMatchingImages.length}` + ); + partialMatchingImages.forEach(image => { + console.log(`Image url: ${image.url}`); + }); + } }); } - }) - .catch(err => { - console.error('ERROR:', err); - }); - // [END vision_web_detection] -} - -function detectWebGCS(bucketName, fileName) { - // [START vision_web_detection_gcs] - - // Imports the Google Cloud client libraries - const vision = require('@google-cloud/vision').v1p1beta1; - - // Creates a client - const client = new vision.ImageAnnotatorClient(); - - /** - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const bucketName = 'Bucket where the file resides, e.g. my-bucket'; - // const fileName = 'Path to file within bucket, e.g. path/to/image.png'; - - // Detect similar images on the web to a remote file - client - .webDetection(`gs://${bucketName}/${fileName}`) - .then(results => { - const webDetection = results[0].webDetection; if (webDetection.fullMatchingImages.length) { console.log( `Full matches found: ${webDetection.fullMatchingImages.length}` ); webDetection.fullMatchingImages.forEach(image => { - console.log(` URL: ${image.url}`); - console.log(` Score: ${image.score}`); + console.log(` Image url: ${image.url}`); }); } @@ -522,28 +167,36 @@ function detectWebGCS(bucketName, fileName) { `Partial matches found: ${webDetection.partialMatchingImages.length}` ); webDetection.partialMatchingImages.forEach(image => { - console.log(` URL: ${image.url}`); - console.log(` Score: ${image.score}`); + console.log(` Image url: ${image.url}`); }); } if (webDetection.webEntities.length) { console.log(`Web entities found: ${webDetection.webEntities.length}`); webDetection.webEntities.forEach(webEntity => { - console.log(` Description: ${webEntity.description}`); console.log(` Score: ${webEntity.score}`); + console.log(` Description: ${webEntity.description}`); + }); + } + + if (webDetection.visuallySimilarImages.length) { + const visuallySimilarImages = webDetection.visuallySimilarImages; + console.log( + `Visually similar images found: ${visuallySimilarImages.length}` + ); + visuallySimilarImages.forEach(image => { + console.log(` Image url: ${image.url}`); }); } }) .catch(err => { console.error('ERROR:', err); }); - // [END vision_web_detection_gcs] + // [END vision_web_detection] } -function detectFulltext(fileName) { - // [START vision_fulltext_detection] - +function detectWebEntitiesIncludingGeoResults(fileName) { + // [START vision_web_entities_include_geo_results] // Imports the Google Cloud client library const vision = require('@google-cloud/vision').v1p1beta1; @@ -555,186 +208,67 @@ function detectFulltext(fileName) { */ // const fileName = 'Local image file, e.g. /path/to/image.png'; - // Read a local image as a text document - client - .documentTextDetection(fileName) - .then(results => { - const fullTextAnnotation = results[0].fullTextAnnotation; - console.log(fullTextAnnotation.text); - }) - .catch(err => { - console.error('ERROR:', err); - }); - // [END vision_fulltext_detection] -} - -function detectFulltextGCS(bucketName, fileName) { - // [START vision_fulltext_detection_gcs] + const request = { + image: { + source: { + filename: fileName, + }, + }, + imageContext: { + webDetectionParams: { + includeGeoResults: true, + }, + }, + }; - // Imports the Google Cloud client libraries - const vision = require('@google-cloud/vision').v1p1beta1; - - // Creates a client - const client = new vision.ImageAnnotatorClient(); - - /** - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const bucketName = 'Bucket where the file resides, e.g. my-bucket'; - // const fileName = 'Path to file within bucket, e.g. path/to/image.png'; - - // Read a remote image as a text document + // Performs safe search detection on the local file client - .documentTextDetection(`gs://${bucketName}/${fileName}`) + .webDetection(request) .then(results => { - const fullTextAnnotation = results[0].fullTextAnnotation; - console.log(fullTextAnnotation.text); + const webDetection = results[0].webDetection; + + webDetection.webEntities.forEach(entity => { + console.log(`Score: ${entity.score}`); + console.log(`Description: ${entity.description}`); + }); }) .catch(err => { console.error('ERROR:', err); }); - // [END vision_fulltext_detection_gcs] + // [END vision_web_entities_include_geo_results] } +//.usage('$0 ', 'Cloud Vision Beta API Samples') require(`yargs`) // eslint-disable-line .demand(1) .command( - `faces `, - `Detects faces in a local image file.`, - {}, - opts => detectFaces(opts.fileName) - ) - .command( - `faces-gcs `, - `Detects faces in an image in Google Cloud Storage.`, - {}, - opts => detectFacesGCS(opts.bucketName, opts.fileName) - ) - .command( - `labels `, - `Detects labels in a local image file.`, - {}, - opts => detectLabels(opts.fileName) - ) - .command( - `labels-gcs `, - `Detects labels in an image in Google Cloud Storage.`, - {}, - opts => detectLabelsGCS(opts.bucketName, opts.fileName) - ) - .command( - `landmarks `, - `Detects landmarks in a local image file.`, - {}, - opts => detectLandmarks(opts.fileName) - ) - .command( - `landmarks-gcs `, - `Detects landmarks in an image in Google Cloud Storage.`, - {}, - opts => detectLandmarksGCS(opts.bucketName, opts.fileName) - ) - .command(`text `, `Detects text in a local image file.`, {}, opts => - detectText(opts.fileName) - ) - .command( - `text-gcs `, - `Detects text in an image in Google Cloud Storage.`, - {}, - opts => detectTextGCS(opts.bucketName, opts.fileName) - ) - .command( - `logos `, - `Detects logos in a local image file.`, - {}, - opts => detectLogos(opts.fileName) - ) - .command( - `logos-gcs `, - `Detects logos in an image in Google Cloud Storage.`, + `web-entities-geo `, + `Detects web entities with improved results using geographic metadata`, {}, - opts => detectLogosGCS(opts.bucketName, opts.fileName) - ) - .command( - `properties `, - `Detects image properties in a local image file.`, - {}, - opts => detectProperties(opts.fileName) - ) - .command( - `properties-gcs `, - `Detects image properties in an image in Google Cloud Storage.`, - {}, - opts => detectPropertiesGCS(opts.bucketName, opts.fileName) + opts => detectWebEntitiesIncludingGeoResults(opts.fileName) ) .command( `safe-search `, - `Detects safe search properties in a local image file.`, + `Detects safe search properties including additional racy category`, {}, opts => detectSafeSearch(opts.fileName) ) - .command( - `safe-search-gcs `, - `Detects safe search properties in an image in Google Cloud Storage.`, - {}, - opts => detectSafeSearchGCS(opts.bucketName, opts.fileName) - ) - .command( - `crops `, - `Detects crop hints in a local image file.`, - {}, - opts => detectCropHints(opts.fileName) - ) - .command( - `crops-gcs `, - `Detects crop hints in an image in Google Cloud Storage.`, - {}, - opts => detectCropHintsGCS(opts.bucketName, opts.fileName) - ) .command( `web `, - `Finds similar photos on the web for a local image file.`, + `Detects web entities including new best guess labels describing content`, {}, opts => detectWeb(opts.fileName) ) - .command( - `web-gcs `, - `Finds similar photos on the web for an image in Google Cloud Storage.`, - {}, - opts => detectWebGCS(opts.bucketName, opts.fileName) - ) .command( `fulltext `, - `Extracts full text from a local image file.`, + `Extracts full text from an image file including new confidence scores`, {}, opts => detectFulltext(opts.fileName) ) - .command( - `fulltext-gcs `, - `Extracts full text from an image in Google Cloud Storage.`, - {}, - opts => detectFulltextGCS(opts.bucketName, opts.fileName) - ) - .example(`node $0 faces ./resources/face_no_surprise.jpg`) - .example(`node $0 faces-gcs my-bucket your-image.jpg`) - .example(`node $0 labels ./resources/wakeupcat.jpg`) - .example(`node $0 labels-gcs my-bucket your-image.jpg`) - .example(`node $0 landmarks ./resources/landmark.jpg`) - .example(`node $0 landmarks-gcs my-bucket your-image.jpg`) - .example(`node $0 text ./resources/wakeupcat.jpg`) - .example(`node $0 text-gcs my-bucket your-image.jpg`) - .example(`node $0 logos ./resources/logos.png`) - .example(`node $0 logos-gcs my-bucket your-image.jpg.png`) - .example(`node $0 properties ./resources/landmark.jpg`) - .example(`node $0 properties-gcs my-bucket your-image.jpg`) .example(`node $0 safe-search ./resources/wakeupcat.jpg`) - .example(`node $0 safe-search-gcs my-bucket your-image.jpg`) - .example(`node $0 crops ./resources/wakeupcat.jpg`) - .example(`node $0 crops-gcs my-bucket your-image.jpg`) + .example(`node $0 web-entities-geo ./resources/city.jpg`) .example(`node $0 web ./resources/wakeupcat.jpg`) - .example(`node $0 web-gcs my-bucket your-image.jpg`) .example(`node $0 fulltext ./resources/wakeupcat.jpg`) - .example(`node $0 fulltext-gcs my-bucket your-image.jpg`) .wrap(120) .recommendCommands() .epilogue(`For more information, see https://cloud.google.com/vision/docs`) diff --git a/samples/resources/city.jpg b/samples/resources/city.jpg new file mode 100644 index 00000000..b14282e7 Binary files /dev/null and b/samples/resources/city.jpg differ diff --git a/samples/system-test/detect.v1p1beta1.test.js b/samples/system-test/detect.v1p1beta1.test.js new file mode 100644 index 00000000..6b85c987 --- /dev/null +++ b/samples/system-test/detect.v1p1beta1.test.js @@ -0,0 +1,65 @@ +/** + * Copyright 2017, Google, Inc. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +'use strict'; + +const path = require(`path`); +const test = require(`ava`); +const tools = require(`@google-cloud/nodejs-repo-tools`); + +const cmd = `node detect.v1p1beta1.js`; +const cwd = path.join(__dirname, `..`); +const files = [`text.jpg`, `wakeupcat.jpg`, `landmark.jpg`, `city.jpg`].map( + name => { + return { + name, + localPath: path.resolve(path.join(__dirname, `../resources/${name}`)), + }; + } +); + +test.before(tools.checkCredentials); + +test(`should extract text from image file and print confidence`, async t => { + const output = await tools.runAsync( + `${cmd} fulltext ${files[0].localPath}`, + cwd + ); + t.true(output.includes('Word text: class')); + t.true(output.includes('Word confidence:')); +}); + +test(`should detect safe search properties from image file`, async t => { + const output = await tools.runAsync( + `${cmd} safe-search ${files[1].localPath}`, + cwd + ); + t.true(output.includes('VERY_LIKELY')); + t.true(output.includes('Racy:')); +}); + +test(`should detect web entities including best guess labels`, async t => { + const output = await tools.runAsync(`${cmd} web ${files[2].localPath}`, cwd); + t.true(output.includes('Description: Palace of Fine Arts Theatre')); + t.true(output.includes('Best guess label: palace of fine arts')); +}); + +test(`should detect web entities using geographical metadata`, async t => { + const output = await tools.runAsync( + `${cmd} web-entities-geo ${files[3].localPath}`, + cwd + ); + t.true(output.includes('Zepra')); +}); diff --git a/src/v1p1beta1/image_annotator_client.js b/src/v1p1beta1/image_annotator_client.js index 1e91141d..cd731ef0 100644 --- a/src/v1p1beta1/image_annotator_client.js +++ b/src/v1p1beta1/image_annotator_client.js @@ -120,9 +120,7 @@ class ImageAnnotatorClient { // Iterate over each of the methods that the service provides // and create an API call method for each. - var imageAnnotatorStubMethods = [ - 'batchAnnotateImages', - ]; + var imageAnnotatorStubMethods = ['batchAnnotateImages']; for (let methodName of imageAnnotatorStubMethods) { this._innerApiCalls[methodName] = gax.createApiCall( imageAnnotatorStub.then( @@ -225,5 +223,4 @@ class ImageAnnotatorClient { } } - module.exports = ImageAnnotatorClient; diff --git a/test/gapic-v1p1beta1.js b/test/gapic-v1p1beta1.js index fbd63c44..404f21c8 100644 --- a/test/gapic-v1p1beta1.js +++ b/test/gapic-v1p1beta1.js @@ -79,7 +79,6 @@ describe('ImageAnnotatorClient', () => { }); }); }); - }); function mockSimpleGrpcMethod(expectedRequest, response, error) {