我正在使用Google的Vision API来识别图像中的某些特性。我有标志检测工作,因为标志出现在我的终端,但我不能让它出现在我的应用程序屏幕上。它不断打印“找不到徽标”-这是我的代码:
//Get logo annotations
let logoAnnotations: JSON = logoResponses["logoAnnotations"]
let numLogos: Int = logoAnnotations.count
var logos: Array<String> = []
if numLogos > 0 {
var allResultsText:String = "Logos: "
for index in 0..<numLogos {
let logo = logoAnnotations[index]["logo"].stringValue
logos.append(logo)
}
for logo in logos {
if logos[logos.count - 1] != logo {
allResultsText += "\(logo), "
} else {
allResultsText += "\(logo)."
}
}
self.allResults.text = allResultsText
} else {
self.allResults.text = "No logos found"
}
}
这是我得到的JSON响应:
[
{
"boundingPoly": {
"vertices": [
{
"x": 210,
"y": 139
},
{
"x": 229,
"y": 139
},
{
"x": 229,
"y": 179
},
{
"x": 210,
"y": 179
}
]
},
"mid": "/m/04lg33",
"score": 0.18314756,
"description": "Ralph Lauren Corporation"
}
]
如何访问返回的徽标描述值(本例为Ralph Lauren Corporation)?
最佳答案
我在代码中更正了这个问题。以下是任何需要它的人的功能代码:
let logoAnnotations: JSON = responses["logoAnnotations"]
let numLogos: Int = logoAnnotations.count
var logos: Array<String> = []
if numLogos > 0 {
var logoResultsText:String = " ,"
for index in 0..<numLogos {
let logo = logoAnnotations[index]["description"].stringValue
logos.append(logo)
}
for logo in logos {
if logos[logos.count - 1] != logo {
logoResultsText += ", \(logo), "
} else {
logoResultsText += "\(logo)."
}
}
self.logoResults.text = logoResultsText
} else {
self.logoResults.text = ""
}
我从logonotations数组调用的索引不正确。
关于swift - 无法将Google的Vision API结果打印到应用程序屏幕,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48709133/