public class L_Recog
extends com.sun.jna.Structure
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.
| Modifier and Type | Class | Description |
|---|---|---|
static class |
L_Recog.ByReference |
|
static class |
L_Recog.ByValue |
| 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.
|
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.
|
Pix.ByReference |
pixdb_range |
debug: best matches within range
C type : Pix* |
Pta.ByReference |
pta |
centroids of (scaled) ave. templates
C type : Pta* |
Pta.ByReference |
pta_u |
centroids of unscaled ave. templates
C type : Pta* |
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 |
| Constructor | Description |
|---|---|
L_Recog() |
|
L_Recog(com.sun.jna.Pointer peer) |
| Modifier and Type | Method | Description |
|---|---|---|
protected java.util.List<java.lang.String> |
getFieldOrder() |
Gets this Structure's field names in their proper order.
|
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, writeFieldpublic int scalew
public int scaleh
public int linew
public int templ_use
public int maxarraysize
public int setsize
public int threshold
public int maxyshift
public int charset_type
public int charset_size
public int min_nopad
public int num_samples
public int minwidth_u
public int maxwidth_u
public int minheight_u
public int maxheight_u
public int minwidth
public int maxwidth
public int ave_done
public int train_done
public float max_wh_ratio
public float max_ht_ratio
public int min_splitw
public int max_splith
public Sarray.ByReference sa_text
public L_Dna.ByReference dna_tochar
public com.sun.jna.ptr.IntByReference centtab
public com.sun.jna.ptr.IntByReference sumtab
public Pixaa.ByReference pixaa_u
public Ptaa.ByReference ptaa_u
public Numaa.ByReference naasum_u
public Pixaa.ByReference pixaa
public Ptaa.ByReference ptaa
public Numaa.ByReference naasum
public Pixa.ByReference pixa_u
public Pta.ByReference pta_u
public Numa.ByReference nasum_u
public Pixa.ByReference pixa
public Pta.ByReference pta
public Numa.ByReference nasum
public Pixa.ByReference pixa_tr
public Pixa.ByReference pixadb_ave
public Pixa.ByReference pixa_id
public Pix.ByReference pixdb_ave
public Pix.ByReference pixdb_range
public Pixa.ByReference pixadb_boot
public Pixa.ByReference pixadb_split
public L_Bmf.ByReference bmf
public int bmf_size
public L_Rdid.ByReference did
public L_Rch.ByReference rch
public L_Rcha.ByReference rcha
Copyright © 2026. All rights reserved.