0
votes

I'm trying to detect text in a remote image with the google Cloud Vision API, but can't seem to get the vision.detectText() syntax right.

How do I use vision.detectText() when there is no cloud storage bucket?

I'm thinking I can/should ignore the reference to storage.bucket() indicated on https://cloud.google.com/vision/docs/detecting-text

I have:

 vision.detectText('https://drive.google.com/file
   /d/0Bw4DMtLCtPMkWVlIVXE5a2ZpQlU/view?usp=drivesdk')
          .then((results) => {
            const detections = results[0];
            console.log('Text:');
            detections.forEach((text) => console.log(text));
          })
          .catch((err) => {
            console.error('ERROR:', err);
          });

the console reports:

ERROR: { PartialFailureError: A failure occurred during this request.
at /Users/node_modules/@google-cloud/vision/src/index.js:434:15
at /Users/node_modules/@google-cloud/vision/src/index.js:126:5
at _combinedTickCallback (internal/process/next_tick.js:80:11)
at process._tickCallback (internal/process/next_tick.js:104:9)
errors: 
[ { image:  'https://drive.google.com/file/d
 /0Bw4DMtLCtPMkNFFselFhU0RMV2c/view?usp=drivesdk',
   errors: [Object] } ],
 response: { responses: [ [Object] ] },
 message: 'A failure occurred during this request.' }

I have tried using:

vision.detectText(storage.bucket().file('https://......

but the error is:

Error: A bucket name is needed to use Cloud Storage.
1

1 Answers

0
votes

It looks like you're not setting your GOOGLE_APPLICATION_CREDENTIALS environment variable. The following code works as tested:

const Vision = require('@google-cloud/vision');
const vision = Vision();
const fileName = 'http://example.com/eg.jpg';

vision.detectText(fileName)
  .then((results) => {
    const detections = results[0];

    console.log('Text:');
    detections.forEach((text) => console.log(text));
    })
    .catch((err) => {
      console.error('ERROR:', err);
    });

To try it out with our sample, pass a URI (e.g. http URI) to the detect.js sample as:

node detect.js fulltext http://www.identifont.com/samples/houseindustries/NeutraText.gif