Step 10 : Error: No image present. at _coerceRequest (/workspace/node_modules/@google-cloud/vision/build/src/helpers.js:54:25)

オープン
#579 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
25/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
google-cloud, javascript, node.js
領域
backend, cloud

調査の方向性

Firebase Cloud Functions codelab の Step 10 から始め、そこでの @google-cloud/[email protected] の使用方法を、issue に示されている代替クライアントコードと比較します。「No image present」エラーを再現し、その後、ドキュメントに記載された実装が、参照されている Vision API のバージョンおよび safe-search のレスポンスで動作することを確認します。

索引モデルが issue の本文から書いたものです。

説明

Problem
The code lab explanation uses "@google-cloud/[email protected]", but the latest version of cloud vision api was 2.3.0

I proceeded as "https://codelabs.developers.google.com/codelabs/firebase-cloud-functions" explains, but I got an error below.

Step 10 : Error: No image present.     at _coerceRequest (/workspace/node_modules/@google-cloud/vision/build/src/helpers.js:54:25)

how to resolve
Here's are the code I modified and I could finally got it!

Comment out line is the github code.
Not comment out line is the alternate code I wrote.

// const Vision = require("@google-cloud/vision");
// const vision = new Vision();
const vision = require("@google-cloud/vision");
const visionClient = new vision.ImageAnnotatorClient();

// const image = {
//   source: { imageUri: `gs://${object.bucket}/${object.name}` },
// };
const request = {
    image: {
    source: { imageUri: `gs://${object.bucket}/${object.name}` },
    },
};

// const batchAnnotateImagesResponse = await vision.safeSearchDetection(
//   image
// );
// const safeSearchResult =
//   batchAnnotateImagesResponse[0].safeSearchAnnotation;
// const Likelihood = visionClient.types.Likelihood;
// if (
//   Likelihood[safeSearchResult.adult] >= Likelihood.LIKELY ||
//   Likelihood[safeSearchResult.violence] >= Likelihood.LIKELY
// ) {
//   console.log(
//     "The image",
//     object.name,
//     "has been detected as inappropriate."
//   );
//   return blurImage(object.name);
// }
// console.log("The image", object.name, "has been detected as OK.");

visionClient
.safeSearchDetection(request)
.then((batchAnnotateImagesResponse) => {
safeSearchResult = batchAnnotateImagesResponse[0].safeSearchAnnotation;
const Likelihood = {
    UNKNOWN: 0,
    VERY_UNLIKELY: 1,
    UNLIKELY: 2,
    POSSIBLE: 3,
    LIKELY: 4,
    VERY_LIKELY: 5,
};
if (
    Likelihood[safeSearchResult.adult] >= Likelihood.LIKELY ||
    Likelihood[safeSearchResult.violence] >= Likelihood.LIKELY
) {
    console.log(
    "The image",
    object.name,
    "has been detected as inappropriate."
    );
    return blurImage(object.name);
}
console.log("The image", object.name, "has been detected as OK.");
})
.catch((err) => {
console.error(err);
});

I hope this help someone like me who will almost spend a lot of time to resolve this problem.

主要言語
JavaScript
スター
1.9k
フォーク
1.8k
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

firebase/codelab-friendlychat-web のほかの issue

firebase/codelab-friendlychat-web の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。