#include "l_bitmap.h"
L_LTIMGCOR_API L_INT L_FindCandidateFormFields(pBitmap, pOptions, pOutputs)
Extracts the candidate form fields from a bitmap using various options. There are two major types of fields: Text fields and OMR fields.
Pointer to the bitmap handle that references the bitmap to be processed.
Fields detection options. This value cannot be null.
Pointer to be updated with the extracted fields.
Value | Meaning |
---|---|
SUCCESS | The function was successful. |
< 1 | An error occurred. Refer to Return Codes. |
Deskew the image first, if it is skewed.
L_FindCandidateFormFields Supports 8-bit, 12-bit and 16-bit grayscale images, and supports 24-bit, 32-bit, 48-bit and 64-bit colored images.
L_FindCandidateFormFields does not support setting rectangle region.
L_FindCandidateFormFields does not support 32-bit grayscale images. It returns the error code ERROR_GRAY32_UNSUPPORTED if a 32-bit grayscale image is passed to this function.
Win32, x64, Linux.
Extracts the candidate form fields from a bitmap using various options.
L_INT FindCandidateFormFieldsExample(L_VOID)
{
L_INT nRet = SUCCESS;
BITMAPHANDLE InputBitmap = { 0 };
FIND_CANDIDATE_FORM_FIELDS_OPTIONS Options;
FIND_CANDIDATE_FORM_FIELDS_OUTPUTS* pOutputs = NULL;
COLORREF red = RGB( 255,0,0 );
COLORREF cyan = RGB( 0,255,255 );
COLORREF blue = RGB( 0,0,255 );
COLORREF green= RGB( 0,255,0 );
Options.uVerticalLineMinimumLength = 3;
Options.uHorizontalLineMinimumLength = 10;
Options.uStructSize = sizeof(FIND_CANDIDATE_FORM_FIELDS_OPTIONS);
L_TCHAR szBuffer1[100];
wsprintf(szBuffer1, TEXT("D:\\forms\\OMR\\300_OMR_sample.tif"));
nRet = L_LoadBitmap(szBuffer1, &InputBitmap,
sizeof(BITMAPHANDLE), 0, ORDER_BGRORGRAY, NULL, NULL);
nRet = L_FindCandidateFormFields(&InputBitmap, &Options, &pOutputs);
if (nRet != SUCCESS)
{
goto cleanup;
}
L_HDC hDC = NULL;
HPEN hPen = NULL;
// Normalize drawing
if (pBitmap->ViewPerspective != TOP_LEFT)
{
nRet = L_ChangeBitmapViewPerspective(pBitmap, pBitmap, sizeof(BITMAPHANDLE), TOP_LEFT);
if (nRet != SUCCESS)
goto cleanup;
}
if (pBitmap->BitsPerPixel != 24)
{
nRet = L_ColorResBitmap(pBitmap, pBitmap, sizeof(BITMAPHANDLE), 24, CRF_BYTEORDERBGR, NULL, NULL, 0, NULL, NULL);
if (nRet != SUCCESS)
goto cleanup;
}
// Start drawing on the image
hDC = L_CreateLeadDC(pBitmap);
if (hDC == NULL)
goto cleanup;
// No fill
SelectObject(hDC, GetStockObject(NULL_BRUSH));
for (L_UINT i = 0; i < pOutputs->TextFields.uCount; i++)
{
RECT rect = pOutputs->TextFields.pTextFieldAreas[i].rcBounds;
COLORREF color = (pOutputs->TextFields.pTextFieldAreas[i].uFieldType == TEXT_FIELD_TYPE_BOX) ? cyan : blue;
hPen = CreatePen(PS_SOLID, 2, color);
if (hPen == NULL)
goto cleanup;
SelectObject(hDC, hPen);
Rectangle(hDC, rect.left, rect.top, rect.right, rect.bottom);
DeleteObject(hPen);
rect = pOutputs->TextFields.pTextFieldAreas[i].rcFilledAreaBounds;
color = red;
DeleteObject(hPen);
hPen = CreatePen(PS_SOLID, 2, color);
if (hPen == NULL)
goto cleanup;
SelectObject(hDC, hPen);
Rectangle(hDC, rect.left, rect.top, rect.right, rect.bottom);
DeleteObject(hPen);
}
COLORREF color = green;
hPen = CreatePen(PS_SOLID, 2, color);
if (hPen == NULL)
goto cleanup;
SelectObject(hDC, hPen);
for (L_UINT i = 0; i < pOutputs->OMRFields.uCount; i++)
{
RECT rect = pOutputs->OMRFields.pOMRFieldAreas[i].rcUnfilledBound;
if (pOutputs->OMRFields.pOMRFieldAreas[i].uFieldType == OMR_FIELD_TYPE_BOX)
{
Rectangle(hDC, rect.left, rect.top, rect.right, rect.bottom);
}
else
{
Ellipse(hDC, rect.left, rect.top, rect.right, rect.bottom);
}
}
////////////////////////////////////////////////////////////
cleanup:
if (hPen != NULL)
DeleteObject(hPen);
if (hDC != NULL)
L_DeleteLeadDC(hDC);
// Free the loaded images
if (InputBitmap.Flags.Allocated)
L_FreeBitmap(&InputBitmap);
// Free the results
L_FindCandidateFormFieldsFree(&pOutputs);
return nRet;
}
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document