Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/400.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在Node.js中的单个请求中运行Google Vision API标签检测和安全搜索检测?_Javascript_Node.js_Google Cloud Vision - Fatal编程技术网

Javascript 如何在Node.js中的单个请求中运行Google Vision API标签检测和安全搜索检测?

Javascript 如何在Node.js中的单个请求中运行Google Vision API标签检测和安全搜索检测?,javascript,node.js,google-cloud-vision,Javascript,Node.js,Google Cloud Vision,免费的州每月最多可收到5000000个请求。对我来说,这意味着应该有一种在单个请求中同时运行标签和安全搜索检测的方法,但我找不到如何做到这一点 我正在使用Node.js程序调用Google Vision API 调用时,仅将图像路径作为参数传递,我会返回安全搜索结果,但会返回标签的空数组(labelnotations),如下所示 代码片段: const visionClient = new vision.ImageAnnotatorClient(); const [ result ] = awa

免费的州每月最多可收到5000000个请求。对我来说,这意味着应该有一种在单个请求中同时运行标签和安全搜索检测的方法,但我找不到如何做到这一点

我正在使用Node.js程序调用Google Vision API

调用时,仅将图像路径作为参数传递,我会返回安全搜索结果,但会返回标签的空数组(
labelnotations
),如下所示

代码片段

const visionClient = new vision.ImageAnnotatorClient();
const [ result ] = await client.safeSearchDetection('./resources/wakeupcat.jpg');
console.log ({ result });
{
  result: {
    faceAnnotations: [],
    landmarkAnnotations: [],
    logoAnnotations: [],
    labelAnnotations: [],
    textAnnotations: [],
    localizedObjectAnnotations: [],
    safeSearchAnnotation: {
      adult: "VERY_UNLIKELY",
      spoof: "VERY_UNLIKELY",
      medical: "VERY_UNLIKELY",
      violence: "VERY_UNLIKELY",
      racy: "VERY_UNLIKELY"
    }
  }
}
输出

const visionClient = new vision.ImageAnnotatorClient();
const [ result ] = await client.safeSearchDetection('./resources/wakeupcat.jpg');
console.log ({ result });
{
  result: {
    faceAnnotations: [],
    landmarkAnnotations: [],
    logoAnnotations: [],
    labelAnnotations: [],
    textAnnotations: [],
    localizedObjectAnnotations: [],
    safeSearchAnnotation: {
      adult: "VERY_UNLIKELY",
      spoof: "VERY_UNLIKELY",
      medical: "VERY_UNLIKELY",
      violence: "VERY_UNLIKELY",
      racy: "VERY_UNLIKELY"
    }
  }
}
另一种情况发生在调用函数时。我们得到有效的
标签注释
,但我们得到空值作为
安全搜索注释

我如何使用Node.js客户端调用以运行安全搜索检测,从而返回
LabelNotations


我担心,如果我打两个电话(一个用于标签检测,另一个用于搜索安全检测),我将收到两次账单。

事实证明,确实可以提出一个请求来获取标签和安全搜索结果(在这种情况下,安全搜索是免费的,每月最多500万次请求)

我们只需要使用该函数,传递一个参数,将标签检测和安全搜索检测指定为功能:

const visionClient = new vision.ImageAnnotatorClient();
const visionRequest = {
  features: [
    { type: 'LABEL_DETECTION' },
    { type: 'SAFE_SEARCH_DETECTION' },
  ],
  image: { source: { filename: './resources/wakeupcat.jpg' } },
};

const [ result ] = await visionClient.annotateImage(request);

通过这样做,
result
包括
labelnotations
safeSearchAnnotation

,事实证明,您确实可以提出一个请求来获取标签和安全搜索结果(在这种情况下,可以免费进行安全搜索,每月最多500万次请求)

我们只需要使用该函数,传递一个参数,将标签检测和安全搜索检测指定为功能:

const visionClient = new vision.ImageAnnotatorClient();
const visionRequest = {
  features: [
    { type: 'LABEL_DETECTION' },
    { type: 'SAFE_SEARCH_DETECTION' },
  ],
  image: { source: { filename: './resources/wakeupcat.jpg' } },
};

const [ result ] = await visionClient.annotateImage(request);
通过这样做,
result
包括
labelnotations
safeSearchAnnotation