#質問したいこと
SwiftyTesseractを使って、画像内の文字を読み取りたいのですが、
Thread 1: Fatal error: Initialization of SwiftyTesseract has failed. Check that the tessdata folder has been added to the project as a folder reference and contains the correct .traineddata files for the specified engine mode and language(s).
というエラーが出てきてしまいます。
どうすれば良いでしょうか?
#コード
import UIKit import Photos import SwiftyTesseract final class AddMemoViewController: UITableViewController { // MARK: IBOutlet @IBOutlet weak var titleTextField: UITextField! @IBOutlet weak var contentTextField: UITextField! @IBOutlet weak var imageView: UIImageView! // MARK: Properties private let model = UserDefaultsModel() //contentTextViewの文字列を取得 var textViewString = "" let swiftyTesseract = SwiftyTesseract(language: .japanese) // MARK: Lifecycle static func instance() -> AddMemoViewController { let vc = UIStoryboard(name: "AddMemoViewController", bundle: nil).instantiateInitialViewController() as! AddMemoViewController return vc } override func viewDidLoad() { super.viewDidLoad() let start = Date() guard let image = imageView.image else { return } textViewString = contentTextField.text! swiftyTesseract.performOCR(on: image) { recognizedString in guard let text = recognizedString else { return } self.contentTextField.text = "(self.textViewString)\n(text)" print(text) print("(-start.timeIntervalSinceNow)") } configureUI() } } // MARK: - Configure extension AddMemoViewController { private func configureUI() { tableView.delegate = self navigationItem.title = "メモを追加" } } // MARK: - Model extension AddMemoViewController { private func saveMemo() { guard let title = titleTextField.text, let content = contentTextField.text else { return } // Save memo let memo = Memo(id: UUID().uuidString, title: title, content: content) if let storedMemos = model.loadMemos() { var newMemos = storedMemos newMemos.append(memo) model.saveMemos(newMemos) } else { model.saveMemos([memo]) } // Save image if let image = imageView.image { model.saveImage(id: memo.id, image: image) } // Pop navigationController?.popViewController(animated: true) } } // MARK: - TableView delegate extension AddMemoViewController { override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { tableView.deselectRow(at: indexPath, animated: true) switch indexPath.section { case 2: presentImagePicker() case 3: saveMemo() default: break } } } // MARK: - ImagePicker delegate extension AddMemoViewController: UIImagePickerControllerDelegate, UINavigationControllerDelegate { private func presentImagePicker() { let imagePicker = UIImagePickerController() imagePicker.delegate = self present(imagePicker, animated: true, completion: nil) } func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) { defer { picker.dismiss(animated: true, completion: nil) } guard let image = info[.originalImage] as? UIImage else { return } imageView.image = image } func imagePickerControllerDidCancel(_ picker: UIImagePickerController) { picker.dismiss(animated: true, completion: nil) } }
よろしくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/03/02 04:18
2020/03/02 04:27
2020/03/02 10:56