【问题标题】:Asynchronous reading text from image with Tesseract?使用 Tesseract 从图像中异步读取文本?
【发布时间】:2012-05-29 21:07:08
【问题描述】:

是否可以使用 tesseract 异步从图像中获取文本? 如果扫描需要很长时间,我很乐意让用户取消扫描。

char* utf8Text = tesseract->GetUTF8Text();

锁定屏幕直到 OCR 完成。

【问题讨论】:

  • 块没有内置方法来阻止它们,您必须手动编写它,或者尝试使用具有方法 cancelAllOperations 的 NSOperationQueue。这个网站有一篇很好的文章eng.pulse.me/concurrent-downloads-using-nsoperationqueues
  • 请发布一个 new 问题,这是一个新问题,而不是将其编辑到现有问题中。

标签: iphone ios asynchronous ocr tesseract


【解决方案1】:

在后台线程中运行将使用户界面继续接收请求。试试这样的:

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    char* utf8Text = tesseract->GetUTF8Text();
});

【讨论】:

  • 谢谢你。但我现在有另一个问题。如果用户点击后退按钮,ocr 正在运行,它会崩溃。我想我必须杀死所有的作品。这是我的代码:dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ tesseract->Recognize(NULL); char* utf8Text = tesseract->GetUTF8Text(); [self performSelectorOnMainThread:@selector(ocrProcessingFinished:) withObject:[NSString stringWithUTF8String:utf8Text] waitUntilDone:NO]; delete [] utf8Text; });
  • 尝试使用调试器检查传递给 ocrProcessingFinished 方法的对象的内容,并检查它是否为 nil。
猜你喜欢
  • 2018-06-18
  • 1970-01-01
  • 2018-09-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-25
  • 1970-01-01
相关资源
最近更新 更多