tesseract-ocr 图像识别所遇到的些问题

来源:互联网 发布:创业法学网络课答案 编辑:程序博客网 时间:2024/06/05 23:06
 其通过不同的语言训练库可以支持多种语言(包括中文、日文)。
从项目地址http://code.google.com/p/tesseract-ocr下载最新版本的项目

程序安装包:
tesseract-ocr-setup-3.02.02.exe


项目环境搭建:
新建一个文件夹:
tesseract-build,然后再在tesseract-build目录下面创建三个文件:

include
lib
tesseract-ocr   

include以及lib对应下载的文件名:tesseract-3.02.02-win32-lib-include-dirs.zip

tesseract-ocr直接到官网下载tesseract-ocr-3.02.02.tar.gz

然后可以打开项目路径下:tesseract-build\tesseract-or\vs2008\tesseract.sln;

vs2008转vs 2010的话,直接把vs2008目录拷贝到当前下面重命名



剩下的就是对工程转换后一些编译环境的错误处理,不详述了;

该项目跑的时候默认读取的语言包是从tesseract-ocr-setup-3.02.02.exe安装路径里面的tessdata文件夹下,例如我的安装路径D:\Program Files (x86)\Tesseract-OCR\tessdata目录下*.traineddata后缀名;

当使用api.init函数的时候,
参数一:表示tessdata所在文件的父路径
参数二:表示tessdata文件下面的语言包名称如eng.traineddata语言包直接填写"eng"就OK了
参数三:tesseract::OEM_TESSERACT_ONLY;可以取如下的值:

enum OcrEngineMode {
  OEM_TESSERACT_ONLY,           // Run Tesseract only - fastest
  OEM_CUBE_ONLY,                // Run Cube only - better accuracy, but slower
  OEM_TESSERACT_CUBE_COMBINED,  // Run both and combine results - best accuracy
  OEM_DEFAULT                   // Specify this mode when calling init_*(),
                                // to indicate that any of the above modes
                                // should be automatically inferred from the
                                // variables in the language-specific config,
                                // command-line configs, or if not specified
                                // in any of the above should be set to the
                                // default OEM_TESSERACT_ONLY.
};

初始化语言包,总感觉路径和文件名路径分开不舒服,直接传个语言包的绝对路径不更方便,所以做了如下修改;
我的方法比较简单粗暴,直接修改
bool Tesseract::init_tesseract_lang_data(
    const char *arg0, const char *textbase, const char *language,
    OcrEngineMode oem, char **configs, int configs_size,
    const GenericVector<STRING> *vars_vec,
    const GenericVector<STRING> *vars_values,
    bool set_only_non_debug_params) 函数;
在STRING tessdata_path = language_data_path_prefix + kTrainedDataSuffix;这行代码下面加一行
tessdata_path = arg0;

方便在调用api.init函数的时候可以直接填写好语言包的绝对路径就OK了;

0 0
原创粉丝点击