如何实现Tesseract在Visual Studio 2010中运行项目 [英] How to implement Tesseract to run with project in Visual Studio 2010
问题描述
我在Visual Studio 2010中有一个C ++项目,并希望使用OCR。我遇到了许多Tesseract的教程,但可惜的是,我得到的是头痛和浪费时间。
I have a C++ project in Visual Studio 2010 and wish to use OCR. I came across many "tutorials" for Tesseract but sadly, all I got was a headache and wasted time.
在我的项目中,我有一个图像存储为 Mat 。我的问题的一个解决方案是保存此Mat作为图像(例如image.jpg),然后调用Tesseract可执行文件像这样:
In my project I have an image stored as a Mat. One solution to my problem is to save this Mat as an image (image.jpg for example) and then call Tesseract executable file like this:
system("tesseract.exe image.jpg out");
这给了我一个输出 out.txt p>
Which gets me an output out.txt and then I call
infile.open ("out.txt");
来读取Tesseract的输出。
to read the output from Tesseract.
这是很好的,像椅子一样工作,但不是最佳的解决方案。在我的项目中,我正在处理一个视频,所以保存/调用.exe /写/读取在10+ FPS不是我真正寻找的。我想对现有的代码实现Tesseract,以便能够传递一个Mat作为参数,并立即得到一个结果作为String。
It is all good and works like a chair but it is not an optimal solution. In my project I am processing a video so save/call .exe/write/read at 10+ FPS is not what I am really looking for. I want to implement Tesseract to existing code so to be able to pass a Mat as an argument and immediately get a result as a String.
你知道任何好的教程逐步的)使用Visual Studio 2010实现Tesseract OCR?
Do you know any good tutorial(pref. step-by-step) to implement Tesseract OCR with Visual Studio 2010? Or your own solution?
推荐答案
确定,我想出来,但它适用于发布 strong> Win32 配置(无调试或x64)。在调试配置下有很多链接错误。
OK, I figured it out but it works for Release and Win32 configuration only (No debug or x64). There are many linking errors under Debug configuration.
因此,
1。首先,在这里下载准备的图书馆文件夹(Tesseract + Leptonica):
1. First of all, download prepared library folder(Tesseract + Leptonica) here:
2。将 tesseract.zip
解压缩到 C:\
3。在Visual Studio中,在 C / C ++>一般>其他包含目录
3. In Visual Studio, go under C/C++ > General > Additional Include Directories
插入 C:\tesseract\include
4。 链接器>一般>其他图书馆目录
插入 C:\tesseract\lib
5。链接器>输入>其他依赖项
添加:
liblept168.lib
libtesseract302.lib
示例代码应如下所示:
Sample code should look like this:
#include <tesseract\baseapi.h>
#include <leptonica\allheaders.h>
#include <iostream>
using namespace std;
int main(void){
tesseract::TessBaseAPI api;
api.Init("", "eng", tesseract::OEM_DEFAULT);
api.SetPageSegMode(static_cast<tesseract::PageSegMode>(7));
api.SetOutputName("out");
cout<<"File name:";
char image[256];
cin>>image;
PIX *pixs = pixRead(image);
STRING text_out;
api.ProcessPages(image, NULL, 0, &text_out);
cout<<text_out.string();
system("pause");
}
与OpenCV和 Mat 这里
这篇关于如何实现Tesseract在Visual Studio 2010中运行项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!