【发布时间】:2019-06-08 12:37:53
【问题描述】:
我将我的对象检测模型 (latestObservation ) 的结果附加到一个列表 (listofObservation) 中,它工作正常,但我想添加一个条件,以便仅在最新观察结果与之前不同时才添加它3 观察。
将最新结果与之前的观察结果进行比较时,我无法访问该变量。
这是我的代码:
var latestObservation = (topIdentifier: String(), topConfidence: Float(), scndIdentifier: String(), scndConfidence: Float())
var listofObservation:[(topIdentifier: String, topConfidence: Float, scndIdentifier: String, scndConfidence: Float)] = []
var LastTopIdentifierCounter = 0
// ... and the part of the func drawVisionRequestResults that is relevant here follows:
for observation in results where observation is VNRecognizedObjectObservation {
guard let objectObservation = observation as? VNRecognizedObjectObservation else {
continue
}
// Select only the label with the highest confidence and the second highest confidence:
let topLabelObservation = objectObservation.labels[0]
let secondLabelObservation = objectObservation.labels[1]
latestObservation = (topIdentifier: topLabelObservation.identifier, topConfidence: topLabelObservation.confidence, scndIdentifier: secondLabelObservation.identifier, scndConfidence: secondLabelObservation.confidence)
let OFL = listofObservation.count
if (listofObservation.topIdentifier(OFL)) == latestObservation.topIdentifier
&& latestObservation.topidentifier == listofObservation.topIdentifier[OFL-1]
&& latestObservation.topidentifier == listofObservation.topIdentifier[OFL-2]
{
LastTopIdentifierCounter += (1)
}
else {
listofObservation.append(latestObservation)
LastTopIdentifierCounter = 0
print(latestObservation)
print(listofObservation)
打印显示变量的以下内容(如果我使附加无条件):
- 最新观察:
(topIdentifier:“6.no_phase”,topConfidence:0.87878287,scndIdentifier:“4.Faden_abnehmen”,scndConfidence:0.06840562)
- 观察列表:
[(topIdentifier:“6.no_phase”,topConfidence:0.87878287,scndIdentifier:“4.Faden_abnehmen”,scndConfidence:0.06840562),(topIdentifier:“6.no_phase”,topConfidence:0.7264241,scndIdentifier:“4.Faden_abnehmen” , scndConfidence: 0.22894023), (topIdentifier: "6.no_phase", topConfidence: 0.92339694, scndIdentifier: "4.Faden_abnehmen", scndConfidence: 0.058480877)]
在代码行上:
if (listofObservation.topIdentifier(OFL)) == latestObservation.topIdentifier
我确实收到以下消息: '[(topIdentifier: String, topConfidence: Float, scndIdentifier: String, scndConfidence: Float)]'类型的值没有成员'topIdentifier'
我对 swift 非常陌生,因此不得不道歉,因为这可能是一个非常幼稚的问题......我已经为此苦苦挣扎了 2 天,在任何地方都找不到关于如何解决这个问题的正确提示。 任何评论都非常感谢。 非常感谢!
【问题讨论】: