Extracts the candidate form fields from a bitmap using various options.
There are two major types of fields: Text fields and OMR fields.
#include "l_bitmap.h"
L_LTIMGCOR_API L_INT L_FindCandidateFormFields(pBitmap, pOptions, pOutputs)
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 Outputs;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, MAKE_IMAGE_PATH(L_TEXT("Forms\\Forms to be Recognized\\OMR\\AnswerSheet_Pattern.jpg")));nRet = L_LoadBitmap(szBuffer1, &InputBitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGRORGRAY, NULL, NULL);nRet = L_FindCandidateFormFields(&InputBitmap, &Options, &Outputs);if (nRet != SUCCESS){goto cleanup;}L_HDC hDC = NULL;HPEN hPen = NULL;// Normalize drawingif (InputBitmap.ViewPerspective != TOP_LEFT){nRet = L_ChangeBitmapViewPerspective(&InputBitmap, &InputBitmap, sizeof(BITMAPHANDLE), TOP_LEFT);if (nRet != SUCCESS)goto cleanup;}if (InputBitmap.BitsPerPixel != 24){nRet = L_ColorResBitmap(&InputBitmap, &InputBitmap, sizeof(BITMAPHANDLE), 24, CRF_BYTEORDERBGR, NULL, NULL, 0, NULL, NULL);if (nRet != SUCCESS)goto cleanup;}// Start drawing on the imagehDC = L_CreateLeadDC(&InputBitmap);if (hDC == NULL)goto cleanup;// No fillSelectObject(hDC, GetStockObject(NULL_BRUSH));for (L_UINT i = 0; i < Outputs.TextFields.uCount; i++){RECT rect = Outputs.TextFields.pTextFieldAreas[i].rcBounds;COLORREF color = (Outputs.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 = Outputs.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 < Outputs.OMRFields.uCount; i++){RECT rect = Outputs.OMRFields.pOMRFieldAreas[i].rcUnfilledBound;if (Outputs.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 imagesif (InputBitmap.Flags.Allocated)L_FreeBitmap(&InputBitmap);// Free the resultsL_FindCandidateFormsFieldsFree(&Outputs);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
