无法将 google 的视力 API 结果打印到应用屏幕
Can't print google's vision API results to app screen
我正在使用 Google 的视觉 API 来识别图像中的某些特征。当徽标出现在我的终端中时,我的徽标检测正在工作,但我无法让它出现在我的应用程序屏幕上。它不断打印 "No logos found" - 这是我的代码:
//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 = ""
}
我从 logoAnnotations 数组中调用了错误的索引。
我正在使用 Google 的视觉 API 来识别图像中的某些特征。当徽标出现在我的终端中时,我的徽标检测正在工作,但我无法让它出现在我的应用程序屏幕上。它不断打印 "No logos found" - 这是我的代码:
//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 = ""
}
我从 logoAnnotations 数组中调用了错误的索引。