firebasegoogle-cloud-platformgoogle-cloud-functionscomputer-visiongoogle-vision

Google Cloud Vision Request no image error


I'm sure I'm missing something simple, but I can' get it to work:

const request = {
                    "requests": [
                      {
                        "image": {
                          "source": {
                            "imageUri":
                              `gs://${bucketName}/thumbnails/${fileName}`,
                          },
                        },
                      },
                    ],
                  };
const [textDetection] = await client.textDetection(request);

throws error: No image present. at _coerceRequest

However, with

const request = `gs://${bucketName}/thumbnails/${fileName}`
const [textDetection] = await client.textDetection(request);

everything works fine. I already read the documentation (https://googleapis.dev/nodejs/vision/latest/v1.ImageAnnotatorClient.html#textDetection) and searched the web for hints, but it doesn't seem to be a problem for other users.

What am I missing, I'm going crazy over this one :(


Solution

  • You should not use an array of requests. As said in the documentation, the textDetection() method "annotates a single image with text detection."

    So defining the request Object as follows should do the trick.

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