I spent more than 24 hours in debugging and troubleshooting problem in tesseract, the problem that I'm looping the below function for multiple images and every time, I track the memory and I found that the memory is increased every time i call below line
Tesseract* tesseract = [[Tesseract alloc] initWithLanguage:@"eng+ita"];
and it is not impacted by below line
tesseract = nil;
below is the full function which called
-(void)recognizeImageWithTesseract:(UIImage *)img
{
UIImage *testb = [img blackAndWhite];
Tesseract* tesseract = [[Tesseract alloc] initWithLanguage:@"eng+ita"];
tesseract.delegate = self;
[tesseract setVariableValue:@"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+-/*._=':!)(" forKey:@"tessedit_char_whitelist"]; //limit search
[tesseract setImage:testb];
[tesseract recognize];
recognizedText = [tesseract recognizedText];
tesseract = nil; //deallocate and free all memory
}
UPDATE 1:
after deep troubleshooting, I discovered the tesseract code of setimage is the reason, the code as below, i need to know which code I have to update to clear this issue
- (void)setImage:(UIImage *)image {
if (image == nil || image.size.width <= 0 || image.size.height <= 0) {
NSLog(@"WARNING: Image has not size!");
return;
}
self.imageSize = image.size; //self.imageSize used in the characterBoxes method
int width = self.imageSize.width;
int height = self.imageSize.height;
CGImage *cgImage = image.CGImage;
CFDataRef data = CGDataProviderCopyData(CGImageGetDataProvider(cgImage));
_pixels = CFDataGetBytePtr(data);
size_t bitsPerComponent = CGImageGetBitsPerComponent(cgImage);
size_t bitsPerPixel = CGImageGetBitsPerPixel(cgImage);
size_t bytesPerRow = CGImageGetBytesPerRow(cgImage);
tesseract::ImageThresholder *imageThresholder = new tesseract::ImageThresholder();
assert(bytesPerRow < MAX_INT32);
{
imageThresholder->SetImage(_pixels,width,height,(int)(bitsPerPixel/bitsPerComponent),(int)bytesPerRow);
_tesseract->SetImage(imageThresholder->GetPixRect());
}
imageThresholder->Clear();
CFRelease(data);
delete imageThresholder;
imageThresholder = nil;
}
please support me to solve this problem
thanks alot