im using tesseract for image OCRing in my iPhone app.
i want to stop all OCR process while its running.
here is my code:
in .h file:
dispatch_queue_t main;
tesseract::TessBaseAPI *tesseract;
uint32_t *pixels;
in .m file:
- (void)processOcrAt:(UIImage *)image
{
[self setTesseractImage:image];
//char* utf8Text = tesseract->GetUTF8Text();
//[self performSelector:@selector(ocrProcessingFinished:) withObject:[NSString stringWithUTF8String:utf8Text]];
//dispatch_queue_t queue = dispatch_queue_create("com.awesome", 0);
main = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(main, ^{
tesseract->Recognize(NULL);
char* utf8Text = tesseract->GetUTF8Text();
[self performSelectorOnMainThread:@selector(ocrProcessingFinished:)
withObject:[NSString stringWithUTF8String:utf8Text]
waitUntilDone:NO];
delete [] utf8Text;
});
}
-(IBAction)backPressed:(id)sender{
dispatch_release(main);
tesseract->Clear();
//tesseract->End();
delete tesseract;
tesseract = nil;
delete pixels;
[self.navigationController popViewControllerAnimated:YES];
}
When i tap to back button while ocr is running it crashes. because ocr is still running. How can i stop it? i couldnt find any method in tesseract.
here is the answer from tesseract form:
https://groups.google.com/forum/?fromgroups=#!topic/tesseract-ocr/1uLF4BmmmUg
I think the crux of the problem is your attempt to stop the OCR thread at a random spot in its execution yet expect the state of the Tesseract instance to be consistent. You are right to want to delete the instance otherwise you would have a memory leak but it looks like you can’t do that after stopping the OCR thread abnormally. In our own iPhone app (ScanBizCards) what we do in that case is to let the OCR thread finish its work in the background even though its results will be ignored and not shown to the user. The downside is mostly that if the user starts a new scan right after aborting one we delay the start of the new scan until the previous (aborted) scan finishes.