| Customize Help

Steps to reading, grading, or writing a code in an image

The following steps provide a basic methodology for using the MIL Code module:

  1. Optionally, detect the code types of 1D code occurrences in your image using McodeDetect(). This returns the position of the code occurrences and their code type and encoding scheme. For information, see the Automatically detecting the code type section later in this chapter.

  2. Allocate a code context, using McodeAlloc(). A code context is a MIL object that stores the code models and code operation settings.

    Optionally, specify the initial configuration of the code context as either M_IMPROVED_RECOGNITION or M_TYPICAL_RECOGNITION, depending on whether robustness or speed is more important, respectively.

  3. Add one or more code models to the code context, using McodeModel(), depending on the operation you need to perform. A code model contains control settings to read, grade, train, or write a particular code type. Specify the code type when adding the code model. You can use the combination value M_SUPPORTED to determine whether a code model of the specified code type can be added to the code context, given the code type of the code models that already exist in the context.

    A code context can contain multiple code models of 1D code types (excluding GS1 databar, Planet, Postnet, and 4-state); for other code types, a code context can contain at most one code model.

  4. If necessary, change the control settings of the code context or the code models, using McodeControl() (for example, change the encoding scheme for your code type using McodeControl() with M_ENCODING, or change the error correction scheme for your code type using McodeControl() with M_ERROR_CORRECTION).

    You can use McodeTrain() to establish the optimal control type settings for a read or grade operation given a sample set of your images. Then, you can configure the code context and its code models with these results using McodeControl() with M_RESET_FROM_TRAINED_RESULTS. For information, see the Training read and grade operation settings section later in this chapter.

  5. If necessary, specify the number of occurrences to read or grade for 1D code models (excluding GS1 databar, Planet, Postnet, and 4-state), or Data Matrix code models, using McodeControl() with M_NUMBER. For code models of other types, this control type must be set to 1 (M_DEFAULT) because you can only read/grade one occurrence of these types of code models.

  6. If reading, grading, detecting, training or writing a code, allocate a result buffer to hold the code results, using McodeAllocResult().

  7. If reading or grading a code, grab or load an image that contains the code. If the image is large, and contains information which might be misinterpreted as a code, create a child buffer to isolate the code from the rest of the image. Alternatively, use a 2D graphics list to define a rectangular region of interest (ROI) using MbufSetRegion(). If your image contains other important information besides the code, the presearch feature can help MIL locate a 2D code; enable the feature using McodeControl() with M_USE_PRESEARCH.

    If writing a code, allocate the image buffer in which to generate the code.

  8. To perform a read operation, use McodeRead(). To perform a grade operation, use McodeGrade(). To perform a write operation, use McodeWrite().

  9. Retrieve reading, grading, detecting, training, or writing results, using McodeGetResult().

  10. If necessary, draw the results using McodeDraw().

  11. If necessary, save your code context, using McodeSave() or McodeStream().

  12. If necessary, save a report containing most of the results from a grade operation as a flat text file, using McodeStream().

  13. Free all allocated objects, using McodeFree().

Note that you must take into consideration any particularities of the chosen code type. More detailed and code type-dependent information is described in subsequent sections of this chapter, as well as in the MIL Reference.

Once created, a MIL code context can be saved and restored as needed. Restoring this information using McodeRestore() or McodeStream(), rather than creating the MIL code context from scratch saves time, especially if the restored code context requires no further modifications.