Crash if repeated call init,open,finalrecogn., save, close, done in a loop
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Cuneiform for Linux |
New
|
Undecided
|
Unassigned |
Bug Description
Hello,
I am using cuneiform-1.0 as base for an XMLRPC based recognition server. I am using the example of cuneiform-cli.cpp as base.
If cuneiform is repeatedly called in a loop, the first iteration will work fine, the second reports an error in PUMA_XFinalReco
The error lies in cuneiform itself (checked carefully with valgrind and gdb).
Here my code:
// simple_ocr method, first parameter is language, second the bitmap as stream
const std::string simple_ocr::_ocr (std::string language, std::vector<char> stream) {
int dotmatrix=FALSE;
int fax=FALSE;
int onecolumn=TRUE; //FALSE;
// create the return string
std::string recognized_text ="";
try {
int bpp = 24;
uinT8 * pixels=NULL;
inT32 x = 0;
inT32 y = 0;
bmpstream2raw(&x, &y, stream, &pixels);
int32_t dibsize=(40+x*y) * sizeof(uinT8);
uinT8 * dib = new uinT8[dibsize];
if (pixels == NULL) throw (1);
if (dib == NULL) throw (1);
*((int32_t *)dib) = 40;
*((int32_t *) (dib+4)) = x; // width
*((int32_t *) (dib+8)) = y; // height
*((int16_t *) (dib+12)) = 1; // biplanes
*((int16_t *) (dib+14)) = bpp; // bpp
*((int32_t *) (dib+16)) = 0; // bi_rgb
*((int32_t *) (dib+20)) = 0; //bi size image
*((int32_t *) (dib+24)) = 0; // pixels per meter
*((int32_t *) (dib+28)) = 0; // pixels per meter
*((int32_t *) (dib+32)) = 0; // clr used
*((int32_t *) (dib+36)) = 0; // clr important
if (!PUMA_Init(0,0)) {
std::cerr << "PUMA_Init failed." << std::endl;
uint32_t rc = PUMA_GetReturnC
std::cerr << "Error was: "<< PUMA_GetReturnS
throw(SDKError);
}
int lang = get_language_index( language );
PUMA_
PUMA_
PUMA_
PUMA_
if (!PUMA_XOpen(dib, (tmpnam(
std::cerr << "PUMA_Xopen failed.
uint32_t rc = PUMA_GetReturnC
std::cerr << "Error was: "<< PUMA_GetReturnS
throw(SDKError);
}
if(!PUMA_
std::cerr << "PUMA_XFinalRec
uint32_t rc = PUMA_GetReturnC
std::cerr << "Error was: "<< rc << " "<< PUMA_GetReturnS
throw(SDKError);
}
#ifdef PUMA_GETSPECIAL
char * buffer = NULL;
int32_t bufferlen=0;
PUMA_
if (NULL==buffer || 0=bufferlen) {
std::cerr << "PUMA_GetSpecia
uint32_t rc = PUMA_GetReturnC
std::cerr << "Error was: "<< PUMA_GetReturnS
throw(SDKError);
}
for (int i=0; i < bufferlen; i++) {
recognized_
}
#else
std::string outfilename=
if(!PUMA_
std::cerr << "PUMA_XSave failed.\n";
uint32_t rc = PUMA_GetReturnC
std::cerr << "Error was: "<< PUMA_GetReturnS
throw(
}
FILE* f=fopen(
if (!f) {
std::cerr << "Could not open file '"<<outfilename
throw(
}
struct stat filestatus;
stat( outfilename.
char * buffer = new char[ filestatus.st_size ];
fread(buffer, filestatus.st_size, 1, f);
fclose(f);
unlink(
recognized_
delete[] buffer;
delete[] pixels;
#endif
if(!PUMA_
std::cerr << "PUMA_XClose failed.
uint32_t rc = PUMA_GetReturnC
std::cerr << "Error was: "<< PUMA_GetReturnS
throw(SDKError);
}
if(!PUMA_Done()) {
std::cerr << "PUMA_Done failed."<< std::endl;
uint32_t rc = PUMA_GetReturnC
std::cerr << "Error was: "<< PUMA_GetReturnS
throw(SDKError);
}
} catch (enum ocr_error) {
std::cout << "ocr error :(" << std::endl;
//recognized_
}
return recognized_text;
};
The method _ocr() is called in a loop. The stream-data is still correct (checked by dumping it on harddisk and comparing it with bitmap-definition)
Any hints, what is going wrong?
Thanks for your help,
Bye Andreas
Cuneiform is unfortunately buggy. You probably just found one.
It is likewise unfortunate that we don't have the resources to fix these.
As a workaround, you can run Cuneiform by writing the image to a file, invoking the Cuneiform binary, loading the result and repeating this for each page. This is what I do, and it's fast enough for me.