google-cloud-functions - Cloud Vision 和 Cloud Functions 返回空响应
问题描述
我正在收听存储桶中的更改以检测图像中的人脸。并将结果记录下来。
我的功能如下
import * as functions from "firebase-functions";
import vision from "@google-cloud/vision";
import path = require('path');
const client = new vision.ImageAnnotatorClient();
export const CheckFace = functions.storage.object().onFinalize(async (image) => {
try {
if(image == null) return;
const imageID = image.name;
const contentType = image?.contentType;
if(!contentType?.startsWith('image/')) return;
const userID = imageID.includes(".")? path.basename(imageID).split(".")[0]:imageID;
console.log(userID);
const [result] = await client.faceDetection(`gs://${image.bucket}/${imageID}`);
const faces = result.faceAnnotations;
console.log(result)
console.log(faces)
if(faces == undefined || faces == null || faces.length < 0){
console.log("noFace");
return;
}else if(faces.length > 1){
console.log("more than 1");
return;
}else if(faces.length == 1){
console.log("one face")
return;
}else{
console.log("error")
return;
}
} catch (error) {
console.log(error);
return;
}
});
我得到的只是
{
faceAnnotations: [],
landmarkAnnotations: [],
logoAnnotations: [],
labelAnnotations: [],
textAnnotations: [],
safeSearchAnnotation: null,
imagePropertiesAnnotation: null,
error: null,
cropHintsAnnotation: null,
fullTextAnnotation: null,
webDetection: null
}
我可能做错了什么?我已尝试添加服务帐户,但仍然遇到相同的错误。我是否需要一个服务帐户或 Firebase 管理员是否会处理它