L_FindCandidateFormFields

#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.

Parameters

pBITMAPHANDLE pBitmap

Pointer to the bitmap handle that references the bitmap to be processed.

FIND_CANDIDATE_FORM_FIELDS_OPTIONS *pOptions

Fields detection options. This value cannot be null.

FIND_CANDIDATE_FORM_FIELDS_OUTPUTS *pOutputs

Pointer to be updated with the extracted fields.

Returns

Value Meaning
SUCCESS The function was successful.
< 1 An error occurred. Refer to Return Codes.

Comments

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.

Required DLLs and Libraries

Platforms

Win32, x64, Linux.

See Also

Functions

Example

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 Version 21.0.2023.2.15
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Raster Imaging C API Help
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.