Hi All,
I used the Tesseract 4.0 to extract text from a bitmap but i get a error when i call Recognize method.
=> Error : Assertion failed: index >= 0 && index < size_used_, file E:\Libs\Text\tesseract-master\src\ccutil\genericvector.h, line 720
Can you help me?
My Code :
tesseract::TessBaseAPI tess;
const int init_failed = tess.Init("e:\\Libs\\Text\\tesseract-master\\tessdata\\", "eng");
if (init_failed == -1)
{
std::cout << "OCRTesseract: Could not initialize tesseract." << std::endl;
return 1;
}
// setup
tess.SetPageSegMode(tesseract::PageSegMode::PSM_AUTO);
tess.SetVariable("save_best_choices", "T");
tess.SetOutputName("out");
// read image
auto pixs = pixRead("C:\\Users\\NhatKhanh\\Desktop\\IMG_1345.bmp");
if (!pixs)
{
std::cout << "Cannot open input file." << std::endl;
return 1;
}
// recognize
tess.SetImage(pixs);
tess.Recognize(0);
// get result and delete[] returned char* string
std::string szText = std::string(tess.GetUTF8Text());
std::cout << std::unique_ptr<char[]>(tess.GetUTF8Text()).get() << std::endl;
// cleanup
tess.Clear();
pixDestroy(&pixs);