LEADTOOLS Support
Document
Document SDK Examples
HOW TO: Preemptively terminate an OCR operation
#1
Posted
:
Thursday, April 27, 2017 12:41:47 PM(UTC)
Groups: Registered, Tech Support, Administrators
Posts: 163
Was thanked: 9 time(s) in 9 post(s)
Some LEADTOOLS operations contain callbacks which reports information regarding the state of the operation. In addition, these operations offer a way to preemptively terminate the operation in question. For example, OcrDocument.AutoZone() and OcrDocument.Recognize() both implement the OcrProgressCallback event.
https://www.leadtools.com/help/leadtools/v20/dh/fo/ocrprogresscallback.htmlThis event is raised internally and provides data relevant to the progress of the operation.
https://www.leadtools.com/help/leadtools/v20/dh/fo/iocrprogressdata--members.htmlNote all these properties are read-only save one: Status. This value is of the OcrProgressStatus enumeration type and has two values--Continue and Abort.
https://www.leadtools.com/help/leadtools/v20/dh/fo/ocrprogressstatus.htmlThe default value is Continue which instructs the operation to proceed normally. However, this can be changed to Abort to instruct the operation to cease as soon as possible.
Code:
IOcrEngine engine = OcrEngineManager.CreateEngine(OcrEngineType.LEAD, false);
IOcrDocument document = engine.DocumentManager.CreateDocument();
document.Pages.AddPages("input.tiff", 1, -1, null);
document.Pages.AutoZone(null);
document.Pages.Recognize(ocr_callback);
Code:
private void ocr_callback(IOcrProgressData data)
{
data.Status = OcrProgressStatus.Abort;
}
Do note this does not halt the operation immediately, but rather when it is convenient for the operation to do so. As a general rule, the operation stops after the current page. Note that when an operation is completed this way, any existing result of the operation is discarded, so using this to only perform a specific number of pages in a document is infeasible. This can be used to either force a timeout for long operations, or to accommodate a "Cancel" button exposed to the end-user via the project's UI.
For more information on callbacks used by LEADTOOLS operations and ways to implement them, see this forum post.
https://www.leadtools.com/support/forum/posts/t12155-How-To--Inlining-Anonymous-Methods-As-a-ParameterEdited by moderator Friday, October 18, 2019 4:41:48 PM(UTC)
| Reason: Updating links and code to v20
Nick Crook
Developer Support Engineer
LEAD Technologies, Inc.
LEADTOOLS Support
Document
Document SDK Examples
HOW TO: Preemptively terminate an OCR operation
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.