#include "ltocr.h"
L_LTOCR_API L_INT EXT_FUNCTION L_OcrPage_GetDeskewAngle(page, value)
Gets the angle of the skew of this L_OcrPage in degrees.
Handle to the OCR page.
Address to L_INT variable to be updated with the page deskew angle.
Value | Meaning |
---|---|
SUCCESS | The function was successful. |
< 1 | An error occurred. Refer to Return Codes. |
Gets the angle of the skew of this page expressed in tenth of degrees.
Use L_OcrPage_AutoPreprocess with L_OcrAutoPreprocessPageCommands_Deskew to automatically deskew the page bitmap prior to calling L_OcrPage_Recognize. This could enhance the quality of the image before starting its recognition.
If the bitmap is skewed, L_OcrPage_GetDeskewAngle will return the angle needed to deskew the page bitmap, if you call L_OcrPage_AutoPreprocess on the page, all subsequent calls to L_OcrPage_GetDeskewAngle will return 0 since the bitmap is not skewed. Hence, you must use L_OcrPage_GetDeskewAngle before calling L_OcrPage_AutoPreprocess.
Use L_OcrPage_GetAutoPreprocessValues to obtain the accumulative pre-processing values applied to this L_OcrPage.
Required DLLs and Libraries
L_INT L_OcrPage_GetDeskewAngleExample()
{
BITMAPHANDLE bitmap = { 0 };
L_OcrEngine ocrEngine = NULL;
L_OcrPage ocrPage = NULL;
L_OcrDocumentManager ocrDocumentManager = NULL;
L_OcrDocument ocrDocument = NULL;
// Create an instance of the engine
L_INT retCode = L_OcrEngineManager_CreateEngine(L_OcrEngineType_Advantage, &ocrEngine);
if(retCode == SUCCESS)
{
// Start the engine using default parameters
retCode = L_OcrEngine_Startup(ocrEngine, NULL, OCR_ADVANTAGE_RUNTIME_DIR);
if(retCode != SUCCESS)
return retCode;
// Load a page to be recognized
retCode = L_LoadBitmap(MAKE_IMAGE_PATH(L_TEXT("Clean.tif")), &bitmap, sizeof(BITMAPHANDLE), 0, ORDER_RGB, NULL, NULL);
if(retCode != SUCCESS)
goto CLEANUP;
// Add an image to OCR page. don't transfer ownership of the bitmap to the page
retCode = L_OcrPage_FromBitmap(ocrEngine, &ocrPage, &bitmap, L_OcrBitmapSharingMode_None, NULL, NULL);
if(retCode != SUCCESS)
goto CLEANUP;
L_INT deskewAngle = 0;
L_OcrPage_GetDeskewAngle(ocrPage, &deskewAngle);
if(deskewAngle > 0)
L_DeskewBitmap(&bitmap, NULL,RGB(0, 0, 0), DSKW_PROCESS | DSKW_RESAMPLE);
L_INT rotateAngle = 0;
L_OcrPage_GetRotateAngle(ocrPage, &rotateAngle, NULL);
if(rotateAngle > 0)
L_RotateBitmap(&bitmap, rotateAngle, ROTATE_RESAMPLE, RGB(0, 0, 0));
// set the bitmap back to the page after we corrected its deskew and rotate angle
retCode = L_OcrPage_SetBitmap(ocrPage, &bitmap, L_TRUE);
if(retCode != SUCCESS)
goto CLEANUP;
// Automatically find areas/zones on the page where text is located
retCode = L_OcrPage_AutoZone(ocrPage, NULL, NULL);
if(retCode != SUCCESS)
goto CLEANUP;
// Recognize the page
// Note: Recognize can be called without calling AutoZone or manually adding zones.
// The engine will check and automatically auto-zones the page.
retCode = L_OcrPage_Recognize(ocrPage, NULL, NULL);
if(retCode != SUCCESS)
goto CLEANUP;
//Get the document manager
retCode = L_OcrEngine_GetDocumentManager(ocrEngine, &ocrDocumentManager);
if(retCode != SUCCESS)
goto CLEANUP;
// Create file-based OCR document
retCode = L_OcrDocumentManager_CreateDocument(ocrDocumentManager, &ocrDocument, L_OcrCreateDocumentOptions_AutoDeleteFile, NULL);
if(retCode != SUCCESS)
goto CLEANUP;
// Add page to the document.
retCode = L_OcrDocument_AddPage(ocrDocument, ocrPage);
if(retCode != SUCCESS)
goto CLEANUP;
// Adding the page to a file based document will take a snap shot of the recognition data and store it in the document. At this
// point, the page is no longer needed. So destroy it to free up memory not used anymore
L_OcrPage_Destroy(ocrPage);
// Set the handle to NULL so we do not free it in our clean-up code
ocrPage = NULL;
// Save the document we have as PDF
retCode = L_OcrDocument_Save(ocrDocument, MAKE_IMAGE_PATH(L_TEXT("Ocr1.pdf")), DOCUMENTFORMAT_PDF, NULL, NULL);
}
CLEANUP:
if(bitmap.Flags.Allocated)
L_FreeBitmap(&bitmap);
if(ocrPage != NULL)
L_OcrPage_Destroy(ocrPage);
if(ocrDocument != NULL)
L_OcrDocument_Destroy(ocrDocument);
if(ocrEngine != NULL)
L_OcrEngine_Destroy(ocrEngine);
return retCode;
}