javascript - 谷歌视觉 api annotateImage 返回空
问题描述
我正在尝试使用 google vision 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],
[EntityAnnotation],
[EntityAnnotation],
[EntityAnnotation],
[EntityAnnotation],
[EntityAnnotation],
[EntityAnnotation],
[EntityAnnotation]
],
localizedObjectAnnotations: [],
textAnnotations: []
}
]
const result = await client.annotateImage(request);
console.log(result)
// RESPONSE
[
AnnotateImageResponse {
faceAnnotations: [],
landmarkAnnotations: [],
logoAnnotations: [],
labelAnnotations: [],
localizedObjectAnnotations: [],
textAnnotations: []
}
]
解决方案
推荐阅读
- javascript - 传播操作员在反应 js 中给出错误,说意外的令牌
- unix - /usr/xpg4/bin/grep -q [^0-9] 并不总是按预期工作
- c# - GameObject.Find 在 DontDestroyOnLoad 中对 Player 不起作用
- java - 它没有显示任何错误,但编译器只是继续加载或显示 [object object]
- c# - 使用另一个类名反序列化
- java - 如何在 Windows 中检测规范路径中的制表符/空格
- c# - 嵌套列表中的可查询搜索
- excel - 从excel中的超链接打印文档
- javascript - Socket IO 和 Express Cross origin 错误或 404 not found 控制台中的错误
- algorithm - 提供的算法的时间复杂度是多少?