使用与 Go 语言相同的代码模板:
在这个page 的浏览器中搜索“type Feature struct”。您可以看到以下特征类型和描述:
// Type: The feature type.
//
// Possible values:
// "TYPE_UNSPECIFIED" - Unspecified feature type.
// "FACE_DETECTION" - Run face detection.
// "LANDMARK_DETECTION" - Run landmark detection.
// "LOGO_DETECTION" - Run logo detection.
// "LABEL_DETECTION" - Run label detection.
// "TEXT_DETECTION" - Run text detection / optical character
// recognition (OCR). Text detection
// is optimized for areas of text within a larger image; if the image
// is
// a document, use `DOCUMENT_TEXT_DETECTION` instead.
// "DOCUMENT_TEXT_DETECTION" - Run dense text document OCR. Takes
// precedence when both
// `DOCUMENT_TEXT_DETECTION` and `TEXT_DETECTION` are present.
// "SAFE_SEARCH_DETECTION" - Run Safe Search to detect potentially
// unsafe
// or undesirable content.
// "IMAGE_PROPERTIES" - Compute a set of image properties, such as
// the
// image's dominant colors.
// "CROP_HINTS" - Run crop hints.
// "WEB_DETECTION" - Run web detection.
没有直接显示 JSON 选项卡内容的选项。 JSON 选项卡内容是所有选项卡“输出”的添加。用户往往只要求一个。例如,当有人在分析人脸时,对文本检测不感兴趣。
如果您需要多个特征,您可以通过将所有可能值的结果“相加”在一起来获得多个特征输出。根据上述事实,我在您的代码中添加了以下几行:
feature2 := &vision.Feature{
Type: "LABEL_DETECTION",
MaxResults: 10,
}
req2 := &vision.AnnotateImageRequest{
Image: img,
Features: []*vision.Feature{feature2},
}
batch2 := &vision.BatchAnnotateImagesRequest{
Requests: []*vision.AnnotateImageRequest{req2},
}
res2, err := svc.Images.Annotate(batch2).Do()
if err != nil {
log.Fatal(err)
}
body2, err := json.Marshal(res2)
fmt.Println(string(body2))
我已经对其进行了测试并且可以正常工作。您应该为您感兴趣的所有功能添加此代码块。如果您打算添加其中许多,我建议创建一个函数/循环以避免重复代码。
无论如何,我建议您通过调用 API 而不是使用客户端库来完成请求 here 以便准确获取 JSON 输出(提供单词或字母级别的数据)。我已经使用下一个代码来获取我感兴趣的数字的边界框:
{
"requests":
[
{
"features":
[
{
"type":
""
"maxResults":
-- add a property --model
}
{
"type":
""
-- add a property --maxResultsmodel
}
]
"image":
{
"source":
{
"gcsImageUri":
""
-- add a property --imageUri
}
-- add a property --content
}
-- add a property --imageContext
}
]
-- add a property --
}