Google视觉api annotateImage返回空

问题描述

我正在尝试使用Google视觉API对单个图像进行多种类型的检测。但是,它返回空响应。如果我使用特定方法进行单一类型的工作,例如labelDetection检测标签。

await client.annotateImage(request);在做什么?我尝试通过content并在两种情况下都定义filename失败

    const client = new vision.ImageAnnotatorClient({ fallback: true,auth })
 
    const content = await readFileSync(imagePath,'base64');

    const image = {
      source: {
        // Try filename / path
        filename: path.join(__dirname,'..',imagePath)
      },// Try base64
      content
    }
    const features = [
      {type: 'FACE_DETECTION'},{type: 'LABEL_DETECTION'},{type: 'SAFE_SEARCH_DETECTION'},]
    const request = {
      image,features,};
    const labelResults = await client.labelDetection(imagePath);
    console.log(labelResults)
// RESPONSE
[
  AnnotateImageResponse {
    faceAnnotations: [],landmarkAnnotations: [],logoAnnotations: [],labelAnnotations: [
      [EntityAnnotation],[EntityAnnotation],[EntityAnnotation]
    ],localizedObjectAnnotations: [],textAnnotations: []
  }
]

    const result = await client.annotateImage(request);
    console.log(result)

// RESPONSE 
[
  AnnotateImageResponse {
    faceAnnotations: [],labelAnnotations: [],textAnnotations: []
  }
]

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)