Tesseract加载语言引发错误-Swift4

时间:2019-02-16 08:30:35

标签: ios xcode swift4 tesseract

我正在尝试将图像转换为Swift 4语言的文本。我已按照下面的链接使用Tesseract库https://www.raywenderlich.com/306-tesseract-ocr-tutorial-for-ios 但我出错了。

Error opening data file /var/containers/Bundle/Application/EA48E754-38FC-4DE7-AD9E-303CA3689F1C/DriverApp.app/tessdata/eng.traineddata
Please make sure the TESSDATA_PREFIX environment variable is set to the parent directory of your "tessdata" directory.
Failed loading language 'eng'
Tesseract couldn't load any languages!
2018-11-23 00:01:56.747525+0530 DriverApp[444:41494] ERROR! Can't init Tesseract engine.

源代码:

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
        imageView.image = info[.originalImage] as? UIImage
        imagePicker.dismiss(animated: true, completion: {
            self.imageToText(myImage: (info[.originalImage] as? UIImage)!)
            })

        //imageToText(myImage: imageView.image!)
    }
    func imageToText(myImage: UIImage)
    {
        if let tesseract = G8Tesseract(language: "eng") {
            // 2
            tesseract.engineMode = .tesseractCubeCombined
            // 3
            tesseract.pageSegmentationMode = .auto
            // 4
            tesseract.image = myImage.g8_blackAndWhite()
            // 5
            tesseract.recognize()
            // 6
            ocrText.text = tesseract.recognizedText
        }
        // 7
        //activityIndicator.stopAnimating()

    }

我已将带有eng.traineddata文件的tessdata添加到xcode项目中。 请有人给我一个主意。

0 个答案:

没有答案