Class L_Recog

java.lang.Object
com.sun.jna.Structure
net.sourceforge.lept4j.L_Recog
Direct Known Subclasses:
L_Recog.ByReference, L_Recog.ByValue

public class L_Recog
extends com.sun.jna.Structure
recog.h

This is a simple utility for training and recognizing individual
machine-printed text characters. It is designed to be adapted
to a particular set of character images; e.g., from a book.
There are two methods of training the recognizer. In the most
simple, a set of bitmaps has been labeled by some means, such
a generic OCR program. This is input either one template at a time
or as a pixa of templates, to a function that creates a recog.
If in a pixa, the text string label must be embedded in the
text field of each pix.
If labeled data is not available, we start with a bootstrap
recognizer (BSR) that has labeled data from a variety of sources.
These images are scaled, typically to a fixed height, and then
fed similarly scaled unlabeled images from the source (e.g., book),
and the BSR attempts to identify them. All images that have
a high enough correlation score with one of the templates in the
BSR are emitted in a pixa, which now holds unscaled and labeled
templates from the source. This is the generator for a book adapted
recognizer (BAR).
The pixa should always be thought of as the primary structure.
It is the generator for the recog, because a recog is built
from a pixa of unscaled images.
New image templates can be added to a recog as long as it is
in training mode. Once training is finished, to add templates
it is necessary to extract the generating pixa, add templates
to that pixa, and make a new recog. Similarly, we do not
join two recog; instead, we simply join their generating pixa,
and make a recog from that.
To remove outliers from a pixa of labeled pix, make a recog,
determine the outliers, and generate a new pixa with the
outliers removed. The outliers are determined by building
special templates for each character set that are scaled averages
of the individual templates. Then a correlation score is found
between each template and the averaged templates. There are
two implementations; outliers are determined as either:
(1) a template having a correlation score with its class average
that is below a threshold, or
(2) a template having a correlation score with its class average
that is smaller than the correlation score with the average
of another class.
Outliers are removed from the generating pixa. Scaled averaging
is only performed for determining outliers and for splitting
characters; it is never used in a trained recognizer for identifying
unlabeled samples.
Two methods using averaged templates are provided for splitting
touching characters:
(1) greedy matching
(2) document image decoding (DID)
The DID method is the default. It is about 5x faster and
possibly more accurate.
Once a BAR has been made, unlabeled sample images are identified
by finding the individual template in the BAR with highest
correlation. The input images and images in the BAR can be
represented in two ways:
(1) as scanned, binarized to 1 bpp
(2) as a width-normalized outline formed by thinning to a
skeleton and then dilating by a fixed amount.
The recog can be serialized to file and read back. The serialized
version holds the templates used for correlation (which may have
been modified by scaling and turning into lines from the unscaled
templates), plus, for arbitrary character sets, the UTF8
representation and the lookup table mapping from the character
representation to index.
Why do we not use averaged templates for recognition?
Letterforms can take on significantly different shapes (eg.,
the letters 'a' and 'g'), and it makes no sense to average these.
The previous version of this utility allowed multiple recognizers
to exist, but this is an unnecessary complication if recognition
is done on all samples instead of on averages.

native declaration : recog.h:126
This file was autogenerated by JNAerator,
a tool written by Olivier Chafik that uses a few opensource projects..
For help, please visit NativeLibs4Java or JNA.
  • Nested Class Summary

    Nested Classes 
    Modifier and Type Class Description
    static class  L_Recog.ByReference  
    static class  L_Recog.ByValue  

    Nested classes/interfaces inherited from class com.sun.jna.Structure

    com.sun.jna.Structure.FieldOrder, com.sun.jna.Structure.StructField
  • Field Summary

    Fields 
    Modifier and Type Field Description
    int ave_done
    set to 1 when averaged bitmaps are made
    C type : l_int32
    L_Bmf.ByReference bmf
    bmf fonts
    C type : L_Bmf*
    int bmf_size
    font size of bmf; default is 6 pt
    C type : l_int32
    com.sun.jna.ptr.IntByReference centtab
    table for finding centroids
    C type : l_int32*
    int charset_size
    expected number of classes in charset
    C type : l_int32
    int charset_type
    one of L_ARABIC_NUMERALS, etc.
    C type : l_int32
    L_Rdid.ByReference did
    temp data used for image decoding
    C type : L_Rdid*
    L_Dna.ByReference dna_tochar
    index-to-char lut for arbitrary charset
    C type : L_Dna*
    int linew
    use a value > 0 to convert the bitmap
    C type : l_int32
    float max_ht_ratio
    max of max/min template height ratio
    C type : l_float32
    int max_splith
    max component height kept in splitting
    C type : l_int32
    float max_wh_ratio
    max width/height ratio to split
    C type : l_float32
    int maxarraysize
    initialize container arrays to this
    C type : l_int32
    int maxheight_u
    max height averaged unscaled templates
    C type : l_int32
    int maxwidth
    max width averaged scaled templates
    C type : l_int32
    int maxwidth_u
    max width averaged unscaled templates
    C type : l_int32
    int maxyshift
    vertical jiggle on nominal centroid
    C type : l_int32
    int min_nopad
    min number of samples without padding
    C type : l_int32
    int min_splitw
    min component width kept in splitting
    C type : l_int32
    int minheight_u
    min height averaged unscaled templates
    C type : l_int32
    int minwidth
    min width averaged scaled templates
    C type : l_int32
    int minwidth_u
    min width averaged unscaled templates
    C type : l_int32
    Numaa.ByReference naasum
    area of all (scaled) templates
    C type : Numaa*
    Numaa.ByReference naasum_u
    area of all unscaled templates
    C type : Numaa*
    Numa.ByReference nasum
    area of (scaled) averaged templates
    C type : Numa*
    Numa.ByReference nasum_u
    area of unscaled averaged templates
    C type : Numa*
    int num_samples
    number of training samples
    C type : l_int32
    Pixa.ByReference pixa
    averaged (scaled) templates per class
    C type : Pixa*
    Pixa.ByReference pixa_id
    input images for identifying
    C type : Pixa*
    Pixa.ByReference pixa_tr
    all input training images
    C type : Pixa*
    Pixa.ByReference pixa_u
    averaged unscaled templates per class
    C type : Pixa*
    Pixaa.ByReference pixaa
    all (scaled) templates for each class
    C type : Pixaa*
    Pixaa.ByReference pixaa_u
    all unscaled templates for each class
    C type : Pixaa*
    Pixa.ByReference pixadb_ave
    unscaled and scaled averaged bitmaps
    C type : Pixa*
    Pixa.ByReference pixadb_boot
    debug: bootstrap training results
    C type : Pixa*
    Pixa.ByReference pixadb_split
    debug: splitting results
    C type : Pixa*
    Pix.ByReference pixdb_ave
    debug: best match of input against ave.
    C type : Pix*
    Pix.ByReference pixdb_range
    debug: best matches within range
    C type : Pix*
    Pta.ByReference pta
    centroids of (scaled) ave.
    Pta.ByReference pta_u
    centroids of unscaled ave.
    Ptaa.ByReference ptaa
    centroids of all (scaledl) templates
    C type : Ptaa*
    Ptaa.ByReference ptaa_u
    centroids of all unscaled templates
    C type : Ptaa*
    L_Rch.ByReference rch
    temp data used for holding best char
    C type : L_Rch*
    L_Rcha.ByReference rcha
    temp data used for array of best chars
    C type : L_Rcha*
    Sarray.ByReference sa_text
    text array for arbitrary charset
    C type : Sarray*
    int scaleh
    scale all examples to this height;
    C type : l_int32
    int scalew
    scale all examples to this width;
    C type : l_int32
    int setsize
    size of character set
    C type : l_int32
    com.sun.jna.ptr.IntByReference sumtab
    table for finding pixel sums
    C type : l_int32*
    int templ_use
    template use: use either the average
    C type : l_int32
    int threshold
    for binarizing if depth > 1
    C type : l_int32
    int train_done
    set to 1 when training is complete or
    C type : l_int32

    Fields inherited from class com.sun.jna.Structure

    ALIGN_DEFAULT, ALIGN_GNUC, ALIGN_MSVC, ALIGN_NONE, CALCULATE_SIZE
  • Constructor Summary

    Constructors 
    Constructor Description
    L_Recog()  
    L_Recog​(com.sun.jna.Pointer peer)  
  • Method Summary

    Modifier and Type Method Description
    protected java.util.List<java.lang.String> getFieldOrder()
    Gets this Structure's field names in their proper order.

    Methods inherited from class com.sun.jna.Structure

    allocateMemory, allocateMemory, autoAllocate, autoRead, autoRead, autoWrite, autoWrite, cacheTypeInfo, calculateSize, clear, createFieldsOrder, createFieldsOrder, createFieldsOrder, createFieldsOrder, dataEquals, dataEquals, ensureAllocated, equals, fieldOffset, getAutoRead, getAutoWrite, getFieldList, getFields, getNativeAlignment, getNativeSize, getNativeSize, getPointer, getStringEncoding, getStructAlignment, hashCode, newInstance, newInstance, read, readField, readField, setAlignType, setAutoRead, setAutoSynch, setAutoWrite, setStringEncoding, size, sortFields, toArray, toArray, toString, toString, useMemory, useMemory, write, writeField, writeField, writeField

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • scalew

      public int scalew
      scale all examples to this width;
      C type : l_int32
    • scaleh

      public int scaleh
      scale all examples to this height;
      C type : l_int32
    • linew

      public int linew
      use a value > 0 to convert the bitmap
      C type : l_int32
    • templ_use

      public int templ_use
      template use: use either the average
      C type : l_int32
    • maxarraysize

      public int maxarraysize
      initialize container arrays to this
      C type : l_int32
    • setsize

      public int setsize
      size of character set
      C type : l_int32
    • threshold

      public int threshold
      for binarizing if depth > 1
      C type : l_int32
    • maxyshift

      public int maxyshift
      vertical jiggle on nominal centroid
      C type : l_int32
    • charset_type

      public int charset_type
      one of L_ARABIC_NUMERALS, etc.
      C type : l_int32
    • charset_size

      public int charset_size
      expected number of classes in charset
      C type : l_int32
    • min_nopad

      public int min_nopad
      min number of samples without padding
      C type : l_int32
    • num_samples

      public int num_samples
      number of training samples
      C type : l_int32
    • minwidth_u

      public int minwidth_u
      min width averaged unscaled templates
      C type : l_int32
    • maxwidth_u

      public int maxwidth_u
      max width averaged unscaled templates
      C type : l_int32
    • minheight_u

      public int minheight_u
      min height averaged unscaled templates
      C type : l_int32
    • maxheight_u

      public int maxheight_u
      max height averaged unscaled templates
      C type : l_int32
    • minwidth

      public int minwidth
      min width averaged scaled templates
      C type : l_int32
    • maxwidth

      public int maxwidth
      max width averaged scaled templates
      C type : l_int32
    • ave_done

      public int ave_done
      set to 1 when averaged bitmaps are made
      C type : l_int32
    • train_done

      public int train_done
      set to 1 when training is complete or
      C type : l_int32
    • max_wh_ratio

      public float max_wh_ratio
      max width/height ratio to split
      C type : l_float32
    • max_ht_ratio

      public float max_ht_ratio
      max of max/min template height ratio
      C type : l_float32
    • min_splitw

      public int min_splitw
      min component width kept in splitting
      C type : l_int32
    • max_splith

      public int max_splith
      max component height kept in splitting
      C type : l_int32
    • sa_text

      public Sarray.ByReference sa_text
      text array for arbitrary charset
      C type : Sarray*
    • dna_tochar

      public L_Dna.ByReference dna_tochar
      index-to-char lut for arbitrary charset
      C type : L_Dna*
    • centtab

      public com.sun.jna.ptr.IntByReference centtab
      table for finding centroids
      C type : l_int32*
    • sumtab

      public com.sun.jna.ptr.IntByReference sumtab
      table for finding pixel sums
      C type : l_int32*
    • pixaa_u

      public Pixaa.ByReference pixaa_u
      all unscaled templates for each class
      C type : Pixaa*
    • ptaa_u

      public Ptaa.ByReference ptaa_u
      centroids of all unscaled templates
      C type : Ptaa*
    • naasum_u

      public Numaa.ByReference naasum_u
      area of all unscaled templates
      C type : Numaa*
    • pixaa

      public Pixaa.ByReference pixaa
      all (scaled) templates for each class
      C type : Pixaa*
    • ptaa

      public Ptaa.ByReference ptaa
      centroids of all (scaledl) templates
      C type : Ptaa*
    • naasum

      public Numaa.ByReference naasum
      area of all (scaled) templates
      C type : Numaa*
    • pixa_u

      public Pixa.ByReference pixa_u
      averaged unscaled templates per class
      C type : Pixa*
    • pta_u

      public Pta.ByReference pta_u
      centroids of unscaled ave. templates
      C type : Pta*
    • nasum_u

      public Numa.ByReference nasum_u
      area of unscaled averaged templates
      C type : Numa*
    • pixa

      public Pixa.ByReference pixa
      averaged (scaled) templates per class
      C type : Pixa*
    • pta

      public Pta.ByReference pta
      centroids of (scaled) ave. templates
      C type : Pta*
    • nasum

      public Numa.ByReference nasum
      area of (scaled) averaged templates
      C type : Numa*
    • pixa_tr

      public Pixa.ByReference pixa_tr
      all input training images
      C type : Pixa*
    • pixadb_ave

      public Pixa.ByReference pixadb_ave
      unscaled and scaled averaged bitmaps
      C type : Pixa*
    • pixa_id

      public Pixa.ByReference pixa_id
      input images for identifying
      C type : Pixa*
    • pixdb_ave

      public Pix.ByReference pixdb_ave
      debug: best match of input against ave.
      C type : Pix*
    • pixdb_range

      public Pix.ByReference pixdb_range
      debug: best matches within range
      C type : Pix*
    • pixadb_boot

      public Pixa.ByReference pixadb_boot
      debug: bootstrap training results
      C type : Pixa*
    • pixadb_split

      public Pixa.ByReference pixadb_split
      debug: splitting results
      C type : Pixa*
    • bmf

      public L_Bmf.ByReference bmf
      bmf fonts
      C type : L_Bmf*
    • bmf_size

      public int bmf_size
      font size of bmf; default is 6 pt
      C type : l_int32
    • did

      public L_Rdid.ByReference did
      temp data used for image decoding
      C type : L_Rdid*
    • rch

      public L_Rch.ByReference rch
      temp data used for holding best char
      C type : L_Rch*
    • rcha

      public L_Rcha.ByReference rcha
      temp data used for array of best chars
      C type : L_Rcha*
  • Constructor Details

    • L_Recog

      public L_Recog()
    • L_Recog

      public L_Recog​(com.sun.jna.Pointer peer)
  • Method Details

    • getFieldOrder

      protected java.util.List<java.lang.String> getFieldOrder()
      Gets this Structure's field names in their proper order.
      Overrides:
      getFieldOrder in class com.sun.jna.Structure
      Returns:
      list of ordered field names