im using tesseract for OCRing images in my iPhone app. I want to stop the entire OCR process while it is running.
here is my code:
in the .h file:
dispatch_queue_t main; tesseract::TessBaseAPI *tesseract; uint32_t *pixels;
in the .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 press the back button when ocr is working, it crashes. because ocr is still working. How can I stop him? I could not find any method in tesseract.
source share