Skip to content
This repository has been archived by the owner on Jul 20, 2023. It is now read-only.

Commit

Permalink
Coerce requests from string or buffer. (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukesneeringer authored Nov 28, 2017
1 parent 2975948 commit 80f2978
Show file tree
Hide file tree
Showing 5 changed files with 313 additions and 200 deletions.
120 changes: 20 additions & 100 deletions samples/detect.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function detectFaces(fileName) {
// const fileName = 'Local image file, e.g. /path/to/image.png';

client
.faceDetection({image: {source: {filename: fileName}}})
.faceDetection(fileName)
.then(results => {
const faces = results[0].faceAnnotations;

Expand Down Expand Up @@ -62,17 +62,9 @@ function detectFacesGCS(bucketName, fileName) {
// const bucketName = 'Bucket where the file resides, e.g. my-bucket';
// const fileName = 'Path to file within bucket, e.g. path/to/image.png';

const request = {
image: {
source: {
imageUri: `gs://${bucketName}/${fileName}`,
},
},
};

// Performs face detection on the gcs file
client
.faceDetection(request)
.faceDetection(`gs://${bucketName}/${fileName}`)
.then(results => {
const faces = results[0].faceAnnotations;

Expand Down Expand Up @@ -106,7 +98,7 @@ function detectLabels(fileName) {

// Performs label detection on the local file
client
.labelDetection({image: {source: {filename: fileName}}})
.labelDetection(fileName)
.then(results => {
const labels = results[0].labelAnnotations;
console.log('Labels:');
Expand All @@ -132,17 +124,9 @@ function detectLabelsGCS(bucketName, fileName) {
// const bucketName = 'Bucket where the file resides, e.g. my-bucket';
// const fileName = 'Path to file within bucket, e.g. path/to/image.png';

const request = {
image: {
source: {
imageUri: `gs://${bucketName}/${fileName}`,
},
},
};

// Performs label detection on the gcs file
client
.labelDetection(request)
.labelDetection(`gs://${bucketName}/${fileName}`)
.then(results => {
const labels = results[0].labelAnnotations;
console.log('Labels:');
Expand All @@ -168,7 +152,7 @@ function detectLandmarks(fileName) {

// Performs landmark detection on the local file
client
.landmarkDetection({image: {source: {filename: fileName}}})
.landmarkDetection(fileName)
.then(results => {
const landmarks = results[0].landmarkAnnotations;
console.log('Landmarks:');
Expand All @@ -194,17 +178,9 @@ function detectLandmarksGCS(bucketName, fileName) {
// const bucketName = 'Bucket where the file resides, e.g. my-bucket';
// const fileName = 'Path to file within bucket, e.g. path/to/image.png';

const request = {
image: {
source: {
imageUri: `gs://${bucketName}/${fileName}`,
},
},
};

// Performs landmark detection on the gcs file
client
.landmarkDetection(request)
.landmarkDetection(`gs://${bucketName}/${fileName}`)
.then(results => {
const landmarks = results[0].landmarkAnnotations;
console.log('Landmarks:');
Expand All @@ -230,7 +206,7 @@ function detectText(fileName) {

// Performs text detection on the local file
client
.textDetection({image: {source: {filename: fileName}}})
.textDetection(fileName)
.then(results => {
const detections = results[0].textAnnotations;
console.log('Text:');
Expand All @@ -256,17 +232,9 @@ function detectTextGCS(bucketName, fileName) {
// const bucketName = 'Bucket where the file resides, e.g. my-bucket';
// const fileName = 'Path to file within bucket, e.g. path/to/image.png';

const request = {
image: {
source: {
imageUri: `gs://${bucketName}/${fileName}`,
},
},
};

// Performs text detection on the gcs file
client
.textDetection(request)
.textDetection(`gs://${bucketName}/${fileName}`)
.then(results => {
const detections = results[0].textAnnotations;
console.log('Text:');
Expand All @@ -292,7 +260,7 @@ function detectLogos(fileName) {

// Performs logo detection on the local file
client
.logoDetection({image: {source: {filename: fileName}}})
.logoDetection(fileName)
.then(results => {
const logos = results[0].logoAnnotations;
console.log('Logos:');
Expand All @@ -318,17 +286,9 @@ function detectLogosGCS(bucketName, fileName) {
// const bucketName = 'Bucket where the file resides, e.g. my-bucket';
// const fileName = 'Path to file within bucket, e.g. path/to/image.png';

const request = {
image: {
source: {
imageUri: `gs://${bucketName}/${fileName}`,
},
},
};

// Performs logo detection on the gcs file
client
.logoDetection(request)
.logoDetection(`gs://${bucketName}/${fileName}`)
.then(results => {
const logos = results[0].logoAnnotations;
console.log('Logos:');
Expand All @@ -354,7 +314,7 @@ function detectProperties(fileName) {

// Performs property detection on the local file
client
.imageProperties({image: {source: {filename: fileName}}})
.imageProperties(fileName)
.then(results => {
const properties = results[0].imagePropertiesAnnotation;
const colors = properties.dominantColors.colors;
Expand All @@ -380,17 +340,9 @@ function detectPropertiesGCS(bucketName, fileName) {
// const bucketName = 'Bucket where the file resides, e.g. my-bucket';
// const fileName = 'Path to file within bucket, e.g. path/to/image.png';

const request = {
image: {
source: {
imageUri: `gs://${bucketName}/${fileName}`,
},
},
};

// Performs property detection on the gcs file
client
.imageProperties(request)
.imageProperties(`gs://${bucketName}/${fileName}`)
.then(results => {
const properties = results[0].imagePropertiesAnnotation;
const colors = properties.dominantColors.colors;
Expand All @@ -416,7 +368,7 @@ function detectSafeSearch(fileName) {

// Performs safe search detection on the local file
client
.safeSearchDetection({image: {source: {filename: fileName}}})
.safeSearchDetection(fileName)
.then(results => {
const detections = results[0].safeSearchAnnotation;

Expand Down Expand Up @@ -445,17 +397,9 @@ function detectSafeSearchGCS(bucketName, fileName) {
// const bucketName = 'Bucket where the file resides, e.g. my-bucket';
// const fileName = 'Path to file within bucket, e.g. path/to/image.png';

const request = {
image: {
source: {
imageUri: `gs://${bucketName}/${fileName}`,
},
},
};

// Performs safe search property detection on the remote file
client
.safeSearchDetection(request)
.safeSearchDetection(`gs://${bucketName}/${fileName}`)
.then(results => {
const detections = results[0].safeSearchAnnotation;

Expand Down Expand Up @@ -486,7 +430,7 @@ function detectCropHints(fileName) {

// Find crop hints for the local file
client
.cropHints({image: {source: {filename: fileName}}})
.cropHints(fileName)
.then(results => {
const cropHints = results[0].cropHintsAnnotation;

Expand Down Expand Up @@ -518,17 +462,9 @@ function detectCropHintsGCS(bucketName, fileName) {
// const bucketName = 'Bucket where the file resides, e.g. my-bucket';
// const fileName = 'Path to file within bucket, e.g. path/to/image.png';

const request = {
image: {
source: {
imageUri: `gs://${bucketName}/${fileName}`,
},
},
};

// Find crop hints for the remote file
client
.cropHints(request)
.cropHints(`gs://${bucketName}/${fileName}`)
.then(results => {
const cropHints = results[0].cropHintsAnnotation;

Expand Down Expand Up @@ -561,7 +497,7 @@ function detectWeb(fileName) {

// Detect similar images on the web to a local file
client
.webDetection({image: {source: {filename: fileName}}})
.webDetection(fileName)
.then(results => {
const webDetection = results[0].webDetection;

Expand Down Expand Up @@ -614,17 +550,9 @@ function detectWebGCS(bucketName, fileName) {
// const bucketName = 'Bucket where the file resides, e.g. my-bucket';
// const fileName = 'Path to file within bucket, e.g. path/to/image.png';

const request = {
image: {
source: {
imageUri: `gs://${bucketName}/${fileName}`,
},
},
};

// Detect similar images on the web to a remote file
client
.webDetection(request)
.webDetection(`gs://${bucketName}/${fileName}`)
.then(results => {
const webDetection = results[0].webDetection;

Expand Down Expand Up @@ -678,7 +606,7 @@ function detectFulltext(fileName) {

// Read a local image as a text document
client
.documentTextDetection({image: {source: {filename: fileName}}})
.documentTextDetection(fileName)
.then(results => {
const fullTextAnnotation = results[0].fullTextAnnotation;
console.log(fullTextAnnotation.text);
Expand All @@ -704,17 +632,9 @@ function detectFulltextGCS(bucketName, fileName) {
// const bucketName = 'Bucket where the file resides, e.g. my-bucket';
// const fileName = 'Path to file within bucket, e.g. path/to/image.png';

const request = {
image: {
source: {
imageUri: `gs://${bucketName}/${fileName}`,
},
},
};

// Read a remote image as a text document
client
.documentTextDetection(request)
.documentTextDetection(`gs://${bucketName}/${fileName}`)
.then(results => {
const fullTextAnnotation = results[0].fullTextAnnotation;
console.log(fullTextAnnotation.text);
Expand Down
14 changes: 1 addition & 13 deletions samples/quickstart.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,9 @@ const vision = require('@google-cloud/vision');
// Creates a client
const client = new vision.ImageAnnotatorClient();

// The name of the image file to annotate
const fileName = './resources/wakeupcat.jpg';

// Prepare the request object
const request = {
image: {
source: {
filename: fileName,
},
},
};

// Performs label detection on the image file
client
.labelDetection(request)
.labelDetection('./resources/wakeupcat.jpg')
.then(results => {
const labels = results[0].labelAnnotations;

Expand Down
Loading

0 comments on commit 80f2978

Please sign in to comment.