2

So I want to take a picture of some text, but when using tesseract it gives me the following error:

actual_tessdata_num_entries_ <= TESSDATA_NUM_ENTRIES:Error:Assert failed:in file tessdatamanager.cpp, line 53

so when ViewController1 captures a picture it sends it to the TextViewController like this:

send from ViewController1:

extension CameraViewController: AVCapturePhotoCaptureDelegate {
    func photoOutput(_ output: AVCapturePhotoOutput, didFinishProcessingPhoto photo: AVCapturePhoto, error: Error?) {
        if let imageData = photo.fileDataRepresentation() {
            self.image = UIImage(data: imageData)
            let text = TextViewController()
            text.image = self.image
            self.present(text, animated: true, completion: nil)
        }
    }
}

And it should receive like this in TextViewController() and display on textView, but it just crashes:

@IBOutlet weak var textView: UITextView!
    var image: UIImage?

    override func viewDidLoad() {
        super.viewDidLoad()

        if let tesseract = G8Tesseract(language: "eng") {
            tesseract.delegate = self
            tesseract.image = self.image
            tesseract.recognize()

            textView.text = tesseract.recognizedText
        }
}

1 Answers1

1

Actually, That error is nothing to do with your code. The .traineddata you linked in your code is not working with current version of Tesseract-OCR-iOS.

Because pod 'TesseractOCRiOS', '4.0.0' runs with tesseract engine version 3.03-rc1. If you are using the latest traineddata files from the source tessdata, it only works with Tesseract 4.0.0 not with 3.03-rc1.

If you want to use only eng.traineddata, you can check the solutionhere. The other option is to train [lang].traineddata yourself and tesseract is fully trainable. If you want, you can check tesseract training process.

Selva
  • 60
  • 8