我使用 tesseract 进行文本识别。我的问题是从照片库中获取照片,然后使用 tesseract。
我的代码:
import UIKit
import TesseractOCR
class ViewController: UIViewController, G8TesseractDelegate,
UINavigationControllerDelegate, UIImagePickerControllerDelegate {
@IBOutlet weak var TextView: UITextView!
@IBAction func takePhoto(_ sender: UIButton) {
let image = UIImagePickerController()
image.delegate = self
image.sourceType = UIImagePickerControllerSourceType.photoLibrary
image.allowsEditing = false
self.present(image, animated: true){
}
if let tesseract = G8Tesseract(language: "dan+eng") {
tesseract.delegate = self
tesseract.image = UIImage(named: image)?.g8_blackAndWhite()
tesseract.recognize()
TextView.text = tesseract.recognizedText
}
func progressImageRecognition(for tesseract: G8Tesseract!) {
print("Recognition Progress \(tesseract.progress) %")
}
}
在行中:
tesseract.image = UIImage(named: image)?.g8_blackAndWhite()
它说:
无法转换 UIImagePickerController 类型的值
我该如何解决?