LEADTOOLS OCR C DLL Help > Tutorials > OCR Plus > OCR Plus Utility demo |
The following steps demonstrate a full example on how to use the LEADTOOLS OCR Utility demo, and how these steps are coded into an application:
1. |
Run the OCR Utility demo after the LEADTOOLS v16 with document support installation. |
|
|
2. |
Startup the OCR engine. |
|
Using OCR Utility demo: |
|
From "Engine" menu select "Start up". |
|
Or; |
|
Using the following code: |
L_HDOC hDoc = NULL;
L_DocStartUp(&hDoc, NULL);
3. |
Load an image (e.g. OCR1.TIF). |
|
Using OCR Utility demo: |
|
From "File" menu select "Open". The Open dialog will appear, then select the file and press "Open". |
|
|
|
Or; |
|
Using the following code: |
BITMAPHANDLE Bitmap;
LOADFILEOPTION LoadOptions;
memset(&Bitmap, 0, sizeof(BITMAPHANDLE));
memset(&LoadOptions, 0, sizeof(LOADFILEOPTION));
L_GetDefaultLoadFileOption(&LoadOptions, sizeof(LOADFILEOPTION));
L_LoadBitmap(TEXT(MAKE_IMAGE_PATH(TEXT("OCR1.TIF")), &Bitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGRORGRAY, &LoadOptions, NULL);
4. |
Insert the loaded image to the end of the OCR document. |
|
Using OCR Utility demo: |
|
From "Page" menu select "Insert Current Image". |
|
|
|
Or; |
|
Using the following code: |
L_DocAddPage(hDoc, &Bitmap, -1);
5. |
Find all available zones automatically. |
|
Using OCR Utility demo: |
|
Form "Zone" menu select "Find Zones". A dialog box will appear, then set the options as required and press "OK". |
|
|
|
Or; |
|
Using the following code: |
AUTOZONEOPTS ZoneOpts;
memset(&ZoneOpts, 0, sizeof(AUTOZONEOPTS));
L_DocGetZoneOptions(hDoc, &ZoneOpts, sizeof(AUTOZONEOPTS));
AutoOpts.Parser = PARSE_LEGACY;
AutoOpts.bVisibleGridLines = TRUE;
L_DocSetZoneOptions(hDoc, &ZoneOpts);
L_DocFindZones(hDoc, 0, NULL);
|
The engine will detect all zones automatically and show the detected zones in the client area. |
|
|
|
The following code draws the page with all the detected zones and selects the third zone: |
RECT clipArea;
RECT dstArea;
GetClipBox(hdc, &clipArea);
dstArea.left = 0;
dstArea.top = 0;
dstArea.right = Bitmap.Width;
dstArea.bottom = Bitmap.Height;
L_DocDrawPage(hDoc, hdc, 0, NULL, NULL, &dstArea, &clipArea, SRCCOPY, TRUE);
L_DocSelectZone(hDoc, hdc, 0, 2, TRUE);
6. |
Recognize the OCR document (which contains 1 page). |
|
Using OCR Utility demo: |
|
Form the "OCR" menu select "Recognize Page". The Recognize Page dialog box will appear, then set the options as required and press "OK": |
|
|
|
The page will be recognized and a recognition data file (RDF) will be generated in the path that is specified in the Recognize Page dialog. Keep this file for saving recognition results. |
|
Or; |
|
Using the following code: |
RECOGNIZEOPTS MyRecogOpts;
memset(&MyRecogOpts, 0, sizeof(RECOGNIZEOPTS));
MyRecogOpts.uStructSize = sizeof(RECOGNIZEOPTS);
MyRecogOpts.nPageIndexStart = 0;
MyRecogOpts.nPagesCount = 1;
MyRecogOpts.bEnableSubSystem = TRUE;
MyRecogOpts.bEnableCorrection = TRUE;
MyRecogOpts.SpellLangId = LANG_ID_ENGLISH;
MyRecogOpts.pszFileName = MAKE_IMAGE_PATH(TEXT("OCR1.rdf"));
L_DocRecognize(hDoc, &MyRecogOpts, NULL, NULL);
7. |
Save the recognition results to MS Word document. |
|
Using OCR Utility demo: |
|
From "OCR" menu select "Save Result". A dialog box will appear, then set the options as required and press "OK". |
|
|
|
Using the following code (It saves the recognition results then shuts down the OCR engine): |
RESULTOPTIONS ResOpts;
memset(&ResOpts, 0, sizeof(RESULTOPTIONS));
L_DocGetRecognitionResultOptions(hDoc, &ResOpts, sizeof(RESULTOPTIONS));
ResOpts.Format = DOC_WORD_97_2000_XP;
ResOpts.FormatLevel = FORMAT_LEVEL_FULL;
L_DocSetRecognitionResultOptions(hDoc, &ResOpts);
L_DocSaveResultsToFile(hDoc, MAKE_IMAGE_PATH(TEXT("OCR1.doc")));
L_DocShutDown(&hDoc);
8. |
Open the output file; it will be as follows: |
|
For more information, refer to:
Programming with LEADTOOLS OCR
OCR Frequently Asked Questions