项目地址:http://code.google.com/p/tesseract-ocr/
最简单的应用示例代码:
#include <allheaders.h>
#include <baseapi.h>
#include <strngs.h>
#include <publictypes.h>

#pragma comment(lib,"liblept168.lib")
#pragma comment(lib,"libtesseract302.lib")

int test_ocr(char* img_path)
{
    tesseract::TessBaseAPI tessApi;
    int ret = tessApi.Init(
        "<tessdata所在的目录>",
        "eng", // 中文:"chi_sim"
        tesseract::OEM_DEFAULT,
        NULL,
        0,
        NULL,
        NULL,
        false);
    if(ret != 0)
    {
        return ret;
    }

    tessApi.SetPageSegMode( static_cast<tesseract::PageSegMode>( tesseract::PageSegMode::PSM_SINGLE_BLOCK));
       
    STRING text_out;
    if (!tessApi.ProcessPages(img_path, NULL, 0, &text_out))
    {
        return -1;
    }

    // 返回的字符是UTF-8编码
    // text_out.string();
   
    return 0;
}

// 这里的test.jpg是经过处理得到的二值化单行文本。
test_ocr("C:\test.jpg");

程序的目录结构:
test.exe
tessdata
liblept168.dll
libtesseract302.dll

参考:
http://blog.csdn.net/yasi_xi/article/details/8763385
http://www.cnblogs.com/baizx/archive/2010/08/23/1806136.html
http://club.excelhome.net/thread-897117-1-1.html


本文链接地址: 开源OCR引擎Tesseract的基本应用
https://blog.qingfengju.com/index.asp?id=376

分类:Win32/C++ 查看次数:11117 发布时间:2014/8/29 21:39:31