0

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.
Cord
  • 196
  • 11

1 Answers1

0

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
class
  • 8,621
  • 29
  • 30
  • vision.detectFaces() does not indicate a bucket param like vision.detectText() – Cord Jun 05 '17 at 19:01
  • Updated to demonstrate text detection – class Jun 05 '17 at 20:31
  • well, I have no GOOGLE_APPLICATION_CREDENTIALS environment variable; I'm not sure how that would have been set. I re-built my client_secret.json auth file and confirm that my upload-to-Drive works as it did before. My vision.js has a drive.files.get() that is also happy with auth as I do get the webviewLink parameter back. However, my vision.detectText() still fails as above. As you suggested, I tried $ node detect.js fulltext http://www.identifont.com/samples/houseindustries/NeutraText.gif and it chokes detect.js:779 .recommendCommands() ^ TypeError: require(...).demand(...).comman – Cord Jun 05 '17 at 22:42
  • boom! new information. I swapped out my google-drive URI for yours and the darn thing works. So, is that a bug? – Cord Jun 06 '17 at 00:35
  • I'm going to accept this answer as it obliquely responds properly to the original question. SO police: I'm going to open, answer, and accept a new question relating to the buggish effect of using the google drive v3 parameter webviewLink as an input to vision.detectText(). I hope this is the approved process. If not, please let me off with a warning. – Cord Jun 06 '17 at 22:30
  • @user1405141 You're hitting the "grace" quota, if you try to process a large number of images without credentials, you will begin seeing 401 responses. – class Aug 08 '17 at 17:07