我正在将 tesseract 3.01 和 magick++ 构建到一个程序中,因为命令行版本太慢了。正确编译所有内容需要很长时间,但最后我的编译器没有错误,但只要我去运行我的控制台应用程序,我就会得到
PS C:\Users\sirus\Documents\Visual Studio 2013\Projects\ConsoleApplication4\Release> .\ConsoleApplication4.exe
first command
actual_tessdata_num_entries_ <= TESSDATA_NUM_ENTRIES:Error:Assert failed:in file ..\ccutil\tessdatamanager.cpp, line 48
PS C:\Users\sirus\Documents\Visual Studio 2013\Projects\ConsoleApplication4\Release> l
在线搜索此内容表明,当您必须不正确的语言数据时会发生这种情况,但我有 tesseract 3.01 和直接从他们的谷歌代码站点下载的 tesseract 3.01 语言数据。
我在构建 32 位 /MD 的 Windows 8.1 上使用 Visual Studio 2013
这是我的来源示例
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <locale>
#include <sstream>
#include <string>
#include <Magick++.h>
#include "baseapi.h"
#include "allheaders.h"
using namespace Magick;
using namespace std;
using namespace tesseract;
#define MaxRGB ((Magick::Quantum)65545)
tesseract::TessBaseAPI tess;
string cmd = "";
string cmd2 = "";
void img_split(){
string tesseract = "\"C:\\Program Files (x86)\\Tesseract-OCR\\tesseract.exe\" text/";
int rect_y = 141;
string del = "del /s /q text\\*";
system(del.c_str());
for (int x = 1; x < 40; x++){
rect_y += 19;
Image image;
image.read("source.jpg");
Magick::Image* mImage;
Image sub_image(image);
mImage = &sub_image;
//mImage->write("test.jpg");
sub_image.chop(Geometry(1481, rect_y));
sub_image.crop(Geometry(220, 17));
sub_image.quantizeColorSpace(GRAYColorspace);
sub_image.quantizeColors(2);
sub_image.quantizeDither(false);
sub_image.quantize();
sub_image.scale(Geometry(2200,170));
sub_image.antiAlias();
sub_image.compressType(Magick::NoCompression);
//const unsigned char* imagedata = (unsigned char*)mImage;
//tess.SetImage(imagedata, 2200, 170, 1, 17300);
//tess.Recognize(0);
//const char* out = tess.GetUTF8Text();
//cout << "\n\nno idea if this will work: " << out << endl;
sub_image.write("text/" + static_cast<ostringstream*>(&(ostringstream() << x))->str() + ".gif");
//cmd2 = tesseract + static_cast<ostringstream*>(&(ostringstream() << x))->str() + ".png text/" + static_cast<ostringstream*>(&(ostringstream() << x))->str();
//tesseract_ocr(x);
}
}
int main(int argc, char **argv)
{
cout << "first command\n";
//tess.Init(argv[0], "eng", tesseract::OEM_DEFAULT);
tess.Init(*argv, "eng");
tess.SetPageSegMode(tesseract::PSM_AUTO);
cout << "\ntest" << endl;
InitializeMagick(*argv);
//img_split();
return 0;
}
如果您能告诉我如何正确地将 sub_image 中的图像传递给 tesseract 的 setimage 函数,则可以加分(因为我很确定我也不会正确)