【发布时间】:2019-01-11 11:40:55
【问题描述】:
我正在学习使用 Watson 的 VisualRecognition 服务。应用程序将图像发送到 Watson,然后从 Watson 接收分类结果。它以前工作正常。但是它今天突然停止工作。
let apiKey = "my api key"
let version = "2019-01-01"
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
if let image = info[UIImagePickerController.InfoKey.originalImage] as? UIImage{
SVProgressHUD.show()
self.cameraButton.isEnabled = false
self.folderButton.isEnabled = false
self.ShareButton.isHidden = true
foodNameIndicatorText.isHidden = true
foodDescriptionButtonA.isHidden = true
foodDescriptionButtonB.isHidden = true
foodDescriptionButtonC.isHidden = true
//clear the results array everytime users pick an new image
self.classificationResults = []
self.foodItemResults = []
imageView.image = image
//dismiss the imgPickerController after presented
imgPickerController.dismiss(animated: true, completion: nil)
let visualRecognition = VisualRecognition(version: version, apiKey: apiKey)
visualRecognition.classify(image: image, threshold: 0.0, owners: ["default"], classifierIDs: ["food"], acceptLanguage: "en") { response, error in
if let error = error {
print("============================here is error =========================================")
print(error)
print("============================end of error =========================================")
}
guard let classifiedImages = response?.result else {
print("Failed to classify the image")
return
}
print(classifiedImages) ......
错误:
http(statusCode: Optional(400), message: nil, metadata: nil)
=============================错误结束================ ===================
我尝试创建一个新的visualRecognition实例,并根据Watson的IOS文档使用它的分类方法。我使用的图像参数来自 imagePickerController,我允许用户从库中选择图像。但是,我在响应处理程序中收到错误,并且代码无法对我的图像进行分类。究竟发生了什么?
【问题讨论】:
标签: swift ibm-watson visual-recognition