如何在Swift中使用VisualRecognition分类器

时间:2016-09-07 19:27:47

标签: ibm-watson

https://github.com/watson-developer-cloud/ios-sdk#visual-recognition相关,我插入了classifierIDs参数:

import VisualRecognitionV3
let apiKey = "your-apikey-here"
let version = "YYYY-MM-DD" // use today's date for the most recent version
let visualRecognition = VisualRecognition(apiKey: apiKey, version: version)
let url = "your-image-url"
let failure = { (error: NSError) in print(error) }
visualRecognition.classify(url, classifierIDs: "x", failure: failure) { classifiedImages in
    print(classifiedImages)
}

这会导致错误:

Ambiguous reference to member 'classify(_:owner:classifierIDs:showLowConfidence:outputLanguage:failure:success)'

1 个答案:

答案 0 :(得分:0)

根据我的经验,ambiguous reference错误通常是由于类型不匹配造成的。在这种情况下,SDK中有两个classify函数,一个是第一个参数是String,另一个是第一个参数是NSURL。发生ambiguous reference错误是因为编译器无法使用类型推断来消除两个classify函数的歧义并确定您要执行的函数。

我认为这里的特定问题与classifierIDs参数有关。根据{{​​3}},classifierIDs的类型为[String]?,与"x"的类型不匹配。请改为["x"]

即尝试:

visualRecognition.classify(url, classifierIDs: ["x"], failure: failure) { classifiedImages in
    print(classifiedImages)
}