开源OCR引擎Tesseract-OCR
来源:互联网 发布:ps cs6 for mac破解版 编辑:程序博客网 时间:2024/05/18 03:43
Overview
Tesseract的OCR引擎最先由HP实验室于1985年开始研发,至1995年时已经成为OCR业内最准确的三款识别引擎之一。然而,HP不久便决定放弃OCR业务,Tesseract也从此尘封。 数年以后,HP意识到,与其将
Tesseract束之高阁,不如贡献给开源软件业,让其重焕新生–2005年,Tesseract由美国内华达州信息技术研究所获得,并求诸于Google对 Tesseract进行改进、消除Bug、优化工作。
Tesseract目前已作为开源项目发布在Google Project,其项目主页在这里查看。为了方便起见,我们直接使用apt-get进行安装, 想自己编译的可参考官方
文档配置编译环境进行编译。
Environment
uname -aLinux debian 3.2.0-4-amd64 #1 SMP Debian 3.2.57-3 x86_64 GNU/Linux
Steps:
1.安装tesseract-ocr以及相关依赖库:
sudo apt-get install tesseract-ocr-dev tesseract-ocr libtesseract-dev libleptonica-dev libpng-dev libtiff-dev libjpeg-dev
2.根据官方API文档编译第一个demo出来,验证开发环境的正确性:
/*tesseract.cpp*/#include <tesseract/baseapi.h>#include <leptonica/allheaders.h>int main(){ char *outText; tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI(); // Initialize tesseract-ocr with English, without specifying tessdata path if (api->Init(NULL, "eng")) { fprintf(stderr, "Could not initialize tesseract.\n"); exit(1); } // Open input image with leptonica library Pix *image = pixRead("/usr/src/tesseract-3.02/phototest.tif"); api->SetImage(image); // Get OCR result outText = api->GetUTF8Text(); printf("OCR output:\n%s", outText); // Destroy used object and release memory api->End(); delete [] outText; pixDestroy(&image); return 0;}g++ tesseract.cpp -o tesseract -ltesseract -llept
3.如果没有什么错误的话会生成tesseract,执行该应用:
./tesseractOCR output:This is a lot of 12 point text to test theocr code and see if it works on all typesof file format.The quick brown dog jumped over thelazy fox. The quick brown dog jumpedover the lazy fox. The quick brown dogjumped over the lazy fox. The quickbrown dog jumped over the lazy fox.
这个Demo主要是将/usr/src/tesseract-3.02/phototest.tif这幅图片上的文字通过tessert-ocr的API转化为文本,然后打印到终端。
Notice
其他发行版的Linux也可参考本文进行配置Tessert-OCR开发环境。可能会遇到的问题汇总:
编译错误:
1.未正确安装tesseract-ocr的开发库(本文中提到的是:libtesseract-dev)
tesseract.cpp:1:32: error: tesseract/baseapi.h: No such file or directory
2.未正确安装leptonica的开发库(本文中提到的是:libleptonica-dev)
tesseract.cpp:2:35: error: leptonica/allheaders.h: No such file or directory
链接错误:
1.未正确链接libtesseract
tesseract.cpp:(.text+0x21): undefined reference to `tesseract::TessBaseAPI::TessBaseAPI()'tesseract.cpp:(.text+0x94): undefined reference to `pixRead'tesseract.cpp:(.text+0xab): undefined reference to `tesseract::TessBaseAPI::SetImage(Pix const*)'tesseract.cpp:(.text+0xb7): undefined reference to `tesseract::TessBaseAPI::GetUTF8Text()'tesseract.cpp:(.text+0xdd): undefined reference to `tesseract::TessBaseAPI::End()'tesseract.cpp:(.text+0xfc): undefined reference to `pixDestroy'/tmp/ccqn3zaC.o: In function `tesseract::TessBaseAPI::Init(char const*, char const*)':
2.未正确链接libleptonica
/usr/bin/ld: /tmp/ccUzaM6g.o: undefined reference to symbol 'pixRead'/usr/bin/ld: note: 'pixRead' is defined in DSO /usr/lib/liblept.so.3 so try adding it to the linker command line/usr/lib/liblept.so.3: could not read symbols: Invalid operationcollect2: ld returned 1 exit status
运行错误:
1.图片文件位置不正确:
Error in fopenReadStream: file not foundError in pixRead: image file not foundError in pixGetDimensions: pix not definedError in pixGetColormap: pix not definedError in pixClone: pixs not definedError in pixGetDepth: pix not definedError in pixGetWpl: pix not definedError in pixGetYRes: pix not definedPlease call SetImage before attempting recognition.OCR output:
根据图片位置修改代码中的文件路径:
Pix *image = pixRead("/usr/src/tesseract-3.02/phototest.tif");
若要下载本文中的代码可执行以下命令(请确保正确安装了git):
git clone https://github.com/Bootez/tesseract-ocr-linux.git
然后:
make./tesseract
阅读全文
0 0
- 开源OCR引擎Tesseract-OCR
- 开源OCR引擎Tesseract
- 开源OCR引擎Tesseract
- 开源OCR引擎Tesseract
- 开源OCR引擎Tesseract
- 开源OCR引擎Tesseract-OCR简介
- Tesseract-OCR引擎 入门
- Tesseract-OCR引擎 入门
- Tesseract-OCR引擎 入门
- Tesseract-OCR引擎 入门
- Tesseract-OCR引擎 入门
- Tesseract-OCR引擎 入门
- Tesseract-OCR引擎 入门
- Tesseract-OCR引擎安装
- Tesseract OCR 引擎-概述
- Tesseract OCR 引擎概述
- Tesseract-OCR引擎 入门
- 如何通过Tesseract开源OCR引擎创建Android OCR应用
- NGUI学习笔记(五): 背包拖拽效果
- 10067---java集合框架【3】 java1.5新特性 ConcurrentHashMap、Collections.synchronizedMap、Hashtable讨论
- C++笔记之【Webservice通讯中文乱码】的那些事
- 使用gradle创建多项目
- 三种建模方式探索
- 开源OCR引擎Tesseract-OCR
- 数据库系统之三级结构模式
- The First
- 华为——进制转换
- 51nod 1468 小Y的IP地址
- 事务使用总结:
- Unix发展史
- Python学习笔记之函数
- JavaScript之拖拽功能、封装