码迷,mamicode.com
首页 > 其他好文 > 详细

配置EmguCV中的OCR

时间:2019-04-12 17:37:55      阅读:453      评论:0      收藏:0      [点我收藏+]

标签:create   index   isnull   com   cto   als   http   cli   sse   

问题:Unable to create ocr model using Path ‘.\‘ and language ‘eng‘.

_ocr = new Tesseract(@".\", "eng", OcrEngineMode.TesseractLstmCombined);

纠结了有几个星期,最后终于试出来了。

总结原因有N,如下:

1. 路径写法

path =  @"C:\myTools\Tess“ 后面需要加上 \,

2. 子文件夹

如果path= @"C:\myTools\Tess\", 那么文件应该放在一个名叫tessdata的子文件夹内,而不是直接放在path的目录下。

3. 版本匹配

刚开始我下载了最新的traindata放在文件夹下面,不好使呀,随后找到了正确的版本,才成功

emgu版本号:3.4.3 所需要的数据版本路径如下

https://github.com/tesseract-ocr/tessdata/blob/4592b8d453889181e01982d22328b5846765eaad/eng.traineddata

https://github.com/tesseract-ocr/tessdata/blob/4592b8d453889181e01982d22328b5846765eaad/osd.traineddata

 

运行通过的代码和文件夹配置如下

string path =  @"C:\myTools\Tess\"; 
 _ocr = new Tesseract(path, "eng", OcrEngineMode.TesseractLstmCombined);

技术图片

 

参考

从Emgu官网下载的程序包里面的例程。

http://www.emgu.com/wiki/index.php/Main_Page

技术图片

 

关键代码区域如下

        private void InitOcr(String path, String lang, OcrEngineMode mode)
        {
            try
            {
                if (_ocr != null)
                {
                    _ocr.Dispose();
                    _ocr = null;
                }

                if (String.IsNullOrEmpty(path))
                    path = ".";

                TesseractDownloadLangFile(path, lang);
                TesseractDownloadLangFile(path, "osd"); //script orientation detection
                String pathFinal = path.Length == 0 || path.Substring(path.Length - 1, 1).Equals(Path.DirectorySeparatorChar.ToString())
                    ? path
                    : String.Format("{0}{1}", path, System.IO.Path.DirectorySeparatorChar);

                _ocr = new Tesseract(pathFinal, lang, mode);

            }
            catch (Exception e)
            {
                _ocr = null;
                System.Diagnostics.Debug.Print(e.Message, "Failed to initialize tesseract OCR engine");
            }
        }
private static void TesseractDownloadLangFile(String folder, String lang) { String subfolderName = "tessdata"; String folderName = System.IO.Path.Combine(folder, subfolderName); if (!System.IO.Directory.Exists(folderName)) { System.IO.Directory.CreateDirectory(folderName); } String dest = System.IO.Path.Combine(folderName, String.Format("{0}.traineddata", lang)); if (!System.IO.File.Exists(dest)) using (System.Net.WebClient webclient = new System.Net.WebClient()) { String source = String.Format("https://github.com/tesseract-ocr/tessdata/blob/4592b8d453889181e01982d22328b5846765eaad/{0}.traineddata?raw=true", lang); Console.WriteLine(String.Format("Downloading file from ‘{0}‘ to ‘{1}‘", source, dest)); webclient.DownloadFile(source, dest); Console.WriteLine(String.Format("Download completed")); } }

 

配置EmguCV中的OCR

标签:create   index   isnull   com   cto   als   http   cli   sse   

原文地址:https://www.cnblogs.com/jiceberg420/p/10697403.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!