| Customize Help

Steps to reading or verifying a string in an image

The following steps provide a basic methodology for using the MIL Optical Character Recognition module:

  1. Create a custom OCR font context using MocrAllocFont() and then use either MocrCopyFont() or MocrImportFont() to add character representations to the OCR font context.

  2. If necessary, specify the type of characters (alphabetic, numeric, or other) that should appear at specific positions in the string, using MocrSetConstraint().

    With custom fonts, you can hook a custom validation check function to the read/verify operations using MocrHookFunction(). After checking character constraints on a found string, the validity function will be executed. If using an OCR font context allocated for a semi font, checksum calculations are performed automatically.

  3. If necessary, adjust general processing controls to fit your application, using successive calls to MocrControl().

  4. Calibrate the OCR font context automatically to match the target image's character size and spacing, using MocrCalibrateFont(). Alternatively, you can set these values manually using MocrControl().

    To physically modify the polarity and sizing of the font of an OCR font context, use MocrModifyFont().

  5. Preprocess the OCR font context with MocrPreprocess() once all the constraints and processing controls are set.

  6. Allocate a result buffer using MocrAllocResult(). This buffer will be used to store subsequent read or verify result values.

  7. Acquire or load a target image. Optionally, limit the area to be read or verified using either a child buffer, allocated using MbufChild...(), or by defining a rectangular M_VECTOR or M_VECTOR_AND_RASTER ROI, set using MbufSetRegion(). In addition, you can improve the quality of the image using the functions of some other MIL module (such as the MIL image processing function MimMorphic() with M_TOP_HAT or M_BOTTOM_HAT). Note that OCR can only process 8-bit unsigned buffers.

    The cleaner the background of a target image, the better the results of a read/verify operation.

  8. Read or verify the string in the target image, using MocrReadString() or MocrVerifyString(), respectively. These functions are performed according to the defined character constraints and processing controls.

  9. Obtain the OCR results using MocrGetResult().

  10. Free all your allocated OCR objects using MocrFree().

In general, the first five steps are performed once, while steps 6 to 10 are repeated as required. Since you can save the font calibration results, character constraints, and processing controls with the character representations (with MocrSaveFont() or MocrStream()), steps 1 to 5 can be replaced by a single step which loads an OCR font context from disk using MocrRestoreFont().

Before performing a read/verify operation, if any font-specific control or target constraint changes, the OCR font context should be preprocessed. Use MocrInquire() to establish if the OCR font context requires preprocessing.