Skip to content

Vision API detectText returns TypeError: formatMethodMap[type] is not a function #2034

@clarenceh

Description

@clarenceh

Environment details

  • OS: MacOS
  • Node.js version: 7.6.0
  • yarn version: 0.21.3
  • @google-cloud/vision version: 0.8.0

Steps to reproduce

I have a testing script with sample images that worked before (i.e. successfully get the ocr text response). However, today I am having the same issue as reported in #1333 again.

Code:

let vision = require('@google-cloud/vision')({
  projectId: 'my-expense-keeper',
  keyFilename: './keyfile/keyfile.json'
});

import { Observable } from '@reactivex/rxjs';

const fs = require('fs-extra');

// const types = ['labels'];
// const types = ['faces'];
// const types = ['logos'];
const types = ['text'];

const obj = fs.readJsonSync('./test-files/receipt-image-req-1.json', {throws: false});

// console.log(JSON.stringify(obj));

let buffer = new Buffer(obj.content, 'base64');

let visionObs = Observable.fromPromise(vision.detect(buffer, types));

visionObs.subscribe(
  data => {
    console.log(`Cloud vision api response: ${JSON.stringify(data)}`);
    process.exit(1);
  },
  err => {
    console.log(`Cloud vision api error: ${JSON.stringify(err)}`);
  }
);

Where the content is base64 encoded image content.

When run the above code with type set to 'labels', I can get the following response:

[
  [
    "text",
    "label",
    "document"
  ],
  {
    "responses":[
      {
        "labelAnnotations":[
          {
            "mid":"/m/07s6nbt",
            "description":"text",
            "score":0.9377162
          },
          {
            "mid":"/m/05c0n6k",
            "description":"label",
            "score":0.591876
          },
          {
            "mid":"/m/015bv3",
            "description":"document",
            "score":0.5269188
          }
        ]
      }
    ]
  }
]

When run the above code with type set to 'labels', I can get the following error:

/Users/clarence/workspace/mek/mek-image-api/node_modules/@google-cloud/vision/src/index.js:538
          return formatMethodMap[type](annotation, options);
                                      ^
TypeError: formatMethodMap[type] is not a function
    at /Users/clarence/workspace/mek/mek-image-api/node_modules/@google-cloud/vision/src/index.js:538:39
    at Array.map (native)
    at decorateAnnotations (/Users/clarence/workspace/mek/mek-image-api/node_modules/@google-cloud/vision/src/index.js:548:16)
    at Array.map (native)
    at /Users/clarence/workspace/mek/mek-image-api/node_modules/@google-cloud/vision/src/index.js:409:10
    at /Users/clarence/workspace/mek/mek-image-api/node_modules/@google-cloud/vision/src/index.js:133:5
    at Object.handleResp (/Users/clarence/workspace/mek/mek-image-api/node_modules/@google-cloud/common/src/util.js:135:3)
    at /Users/clarence/workspace/mek/mek-image-api/node_modules/@google-cloud/common/src/util.js:466:12
    at Request.onResponse [as _callback] (/Users/clarence/workspace/mek/mek-image-api/node_modules/retry-request/index.js:120:7)
    at Request.self.callback (/Users/clarence/workspace/mek/mek-image-api/node_modules/request/request.js:186:22)

I have attached the image that I am using for your reference.

Thanks!
Clarence
receipt-image-1

Metadata

Metadata

Labels

api: visionIssues related to the Cloud Vision API.priority: p0Highest priority. Critical issue. P0 implies highest priority.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions