gpt4 book ai didi

ios - 如何处理拍摄的图像然后使用 Swift 查看结果到 "text View"?

转载 作者:行者123 更新时间:2023-11-28 05:45:49 24 4
gpt4 key购买 nike

我正在尝试使用一个按钮构建一个简单的应用程序。单击按钮拍照,然后使用 "TesseractOCR" 我将图像中的书面文本转换为字符串文本,并在我的“ TextView ”中查看它。

我已经完成了一切,相机和“TesseractOCR”,我面临的唯一问题是:

 tesseract.image = UIImage(named: selectedImage)

给我这个错误:

Cannot convert value of type 'UIImage' to expected argument type 'String'.

注意:selectedImage 假设是 Tesseract 用来将图像转换为文本的图像的名称。

这是我的代码:

import UIKit
import TesseractOCR

class secondViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate, G8TesseractDelegate {

@IBOutlet weak var viewText: UITextView!

override func viewDidLoad() {
super.viewDidLoad()

// Do any additional setup after loading the view.
}

@IBAction func takePhoto(_ sender: Any) {
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerController.SourceType.camera) {
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerController.SourceType.camera
imagePicker.allowsEditing = false
self.present(imagePicker, animated: true, completion: nil)
}
}


func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {

// The info dictionary may contain multiple representations of the image. You want to use the original.
guard let selectedImage = info[.originalImage] as? UIImage else {
fatalError("Expected a dictionary containing an image, but was provided the following: \(info)")
}

// Set photoImageView to display the selected image.
if let tesseract = G8Tesseract(language: "eng") {
tesseract.delegate = self
tesseract.image = UIImage(named: selectedImage)
tesseract.recognize()

textView.text = tesseract.recognizedText

}

// Dismiss the picker.
dismiss(animated: true, completion: nil)
}

}

最佳答案

替换

tesseract.image = UIImage(named: selectedImage)

tesseract.image = selectedImage

UIImage(named:<#string#>)接受一个字符串值来抑制 bundle 中图像的名称,但在这里你不需要它,而是直接提供图像

关于ios - 如何处理拍摄的图像然后使用 Swift 查看结果到 "text View"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54818077/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com