【发布时间】:2019-01-17 18:39:19
【问题描述】:
我在我的 swift 应用程序中使用机器学习和图像检测,但不是在我的 textView 中打印模型认为图像可能是什么的结果,我想用我创建的数组替换它,但每次我试试它会给我一条错误消息说Cannot assign value of type '[[String]]' to type 'String?'
@IBOutlet weak var imageView: UIImageView!
@IBOutlet weak var choosePhotoLib: UIButton!
@IBOutlet weak var textView: UITextView!
var graduation = ["Living your Best Life", "Happiness looks good on you","ive been growing the business", "there are things i want in this life, things i gotta do things i want"]
let imagePicker = UIImagePickerController()
override func viewDidLoad() {
super.viewDidLoad()
imagePicker.delegate = self
imagePicker.sourceType = .camera
imagePicker.allowsEditing = false
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
if let userPickedImage = info[UIImagePickerController.InfoKey.originalImage] as? UIImage {
imageView.image = userPickedImage
guard let ciimage = CIImage(image: userPickedImage) else {
fatalError("Could Not Convert To CIImage")
}
detect(image: ciimage)
}
imagePicker.dismiss(animated: true, completion: nil)
}
func detect(image: CIImage) {
guard let model = try? VNCoreMLModel(for: Inceptionv3__1__1().model) else {
fatalError("Could Not Load Core ML Model")
}
let request = VNCoreMLRequest(model: model) { (request, error) in
guard let results = request.results as? [VNClassificationObservation] else {
fatalError("Could Not Get Reuest")
}
if let firstResult = results.first {
if firstResult.identifier.contains("Graduation") {
self.textView.text = [graduation] WHERE THE ERROR OCCURS
【问题讨论】:
-
渐变是一个字符串数组。因此,当您执行
[graduation]时,它是一个字符串数组的数组(只有一个对象)。而self.textView.text想要String,仅此而已。你的意思是graduation.joined(separator:"\n")(或类似的东西)?你到底想在你的 textView 中放什么? -
感谢您抽出宝贵时间回复 Larme。我希望我的文本视图包含我创建的毕业数组
-
您是要在 textView 中显示所有数组内容还是数组中的单个元素?
标签: arrays swift machine-learning coreml createml