我在我的 iPhone 应用程序中使用 tesseract 进行图像 OCRing。我想在运行时停止所有 OCR 进程。
这是我的代码:
在 .h 文件中:
dispatch_queue_t main;
tesseract::TessBaseAPI *tesseract;
uint32_t *pixels;
在 .m 文件中:
- (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];
}
当我在 ocr 运行时点击后退按钮时,它会崩溃。因为 ocr 仍在运行。我怎样才能阻止它?我在 tesseract 中找不到任何方法。