|
Leptonica
1.54
|
Переменные | |
| static const l_int32 | INITIAL_PTR_ARRAYSIZE = 20 |
| static const l_int32 | MAX_EXAMPLES_IN_CLASS = 256 |
| static l_float32 | DEFAULT_ASPERITY_FRACT = 0.25 |
Input: str (input string representing one UTF-8 character;
not more than 4 bytes)
&val (<return> integer value for the input. Think of it
as a 1-to-1 hash code.)
Return: 0 if OK, 1 on error
Input: recoga
recog (to be added and owned by the recoga; not a copy)
Return: recoga, or null on error
Input: n (initial number of recog ptrs) Return: recoga, or null on error
| L_RECOGA* recogaCreateFromPixaa | ( | PIXAA * | paa, |
| l_int32 | scalew, | ||
| l_int32 | scaleh, | ||
| l_int32 | templ_type, | ||
| l_int32 | threshold, | ||
| l_int32 | maxyshift | ||
| ) |
Input: paa (of labelled, 1 bpp images)
scalew (scale all widths to this; use 0 for no scaling)
scaleh (scale all heights to this; use 0 for no scaling)
templ_type (L_USE_AVERAGE or L_USE_ALL)
threshold (for binarization; typically ~128)
maxyshift (from nominal centroid alignment; typically 0 or 1)
Return: recoga, or null on error
Notes: (1) This is a convenience function for training from labelled data. (2) Each pixa in the paa is a set of labelled data that is used to train a recognizer (e.g., for a set of characters in a font). Each image example in the pixa is put into a class in its recognizer, defined by its character label. All examples in the same class should be similar. (3) The pixaa can be written by recogaWritePixaa(), and must contain the unscaled bitmaps used for training.
Input: recog Return: recoga, or null on error
Notes: (1) This is a convenience function for making a recoga after you have a recog. The recog is owned by the recoga. (2) For splitting connected components, the input recog must be from the material to be identified, and not a generic bootstrap recog. Those can be added later.
Input: recog
paa (pixaa from previously trained recog)
debug
Return: 0 if OK, 1 on error
Notes: (1) This is used with the serialization routine recogRead(), where each pixa in the pixaa represents a set of characters in a different class. Two different pixa may represent characters with the same label. Before calling this function, we verify that the number of character classes, given by the setsize field in recog, equals the number of pixa in the paa. The character labels for each set are in the sa_text field.
Input: filename
recog
Return: 0 if OK, 1 on error
| void recogaDestroy | ( | L_RECOGA ** | precoga | ) |
Input: &recoga (<will be set to null before returning>) Return: void
Notes: (1) If a recog has a parent, the parent owns it. To destroy a recog, it must first be "orphaned".
Input: recoga Return: 0 if OK, 1 on error
Input: recoga Return: count of recog in array; 0 if no recog or on error
Input: recoga
index (to the index-th recog)
Return: recog, or null on error
Notes: (1) This returns a ptr to the recog, which is still owned by the recoga. Do not destroy it.
Input: recog1
recog2 (gets added to recog1)
Return: 0 if OK, 1 on error
Notes: (1) This is used to make a training recognizer from more than one trained recognizer source. It should only be used when the bitmaps for corresponding character classes are very similar. That constraint does not arise when the character classes are disjoint; e.g., if recog1 is digits and recog2 is alphabetical. (2) This is done by appending recog2 to recog1. Averages are computed for each recognizer, if necessary, before appending. (3) Non-array fields are combined using the appropriate min and max.
| L_RECOGA* recogaRead | ( | const char * | filename | ) |
Input: filename Return: recoga, or null on error
Notes: (1) This allows serialization of an array of recognizers, each of which can be used for different fonts, font styles, etc.
| L_RECOGA* recogaReadStream | ( | FILE * | fp | ) |
Input: stream Return: recog, or null on error
Input: filename
recoga
Return: 0 if OK, 1 on error
Input: filename
recoga
Return: 0 if OK, 1 on error
Notes: (1) For each recognizer, this generates a pixa of all the unscaled images. They are combined into a pixaa for the set of recognizers. Each pix has has its character string in the pix text field. (2) As a side-effect, the character class label is written into each pix in recog.
Input: stream (opened for "wb")
recoga
filename (output serialized filename; embedded in file)
Return: 0 if OK, 1 on error
| L_RECOG* recogCreate | ( | l_int32 | scalew, |
| l_int32 | scaleh, | ||
| l_int32 | templ_type, | ||
| l_int32 | threshold, | ||
| l_int32 | maxyshift | ||
| ) |
Input: scalew (scale all widths to this; use 0 for no scaling)
scaleh (scale all heights to this; use 0 for no scaling)
templ_type (L_USE_AVERAGE or L_USE_ALL)
threshold (for binarization; typically ~128)
maxyshift (from nominal centroid alignment; typically 0 or 1)
Return: recog, or null on error
Notes: (1) For a set trained on one font, such as numbers in a book, it is sensible to set scalew = scaleh = 0. (2) For a mixed training set, scaling to a fixed height, such as 32 pixels, but leaving the width unscaled, is effective. (3) The storage for most of the arrays is allocated when training is finished.
| L_RECOG* recogCreateFromPixa | ( | PIXA * | pixa, |
| l_int32 | scalew, | ||
| l_int32 | scaleh, | ||
| l_int32 | templ_type, | ||
| l_int32 | threshold, | ||
| l_int32 | maxyshift | ||
| ) |
Input: pixa (of labelled, 1 bpp images)
scalew (scale all widths to this; use 0 for no scaling)
scaleh (scale all heights to this; use 0 for no scaling)
templ_type (L_USE_AVERAGE or L_USE_ALL)
threshold (for binarization; typically ~128)
maxyshift (from nominal centroid alignment; typically 0 or 1)
Return: recog, or null on error
Notes: (1) This is a convenience function for training from labelled data. The pixa can be read from file. (2) The pixa should contain the unscaled bitmaps used for training. (3) The characters here should work as a single "font", because each image example is put into a class defined by its character label. All examples in the same class should be similar.
| L_RECOG* recogCreateFromRecog | ( | L_RECOG * | recs, |
| l_int32 | scalew, | ||
| l_int32 | scaleh, | ||
| l_int32 | templ_type, | ||
| l_int32 | threshold, | ||
| l_int32 | maxyshift | ||
| ) |
Input: recs (source recog with arbitrary input parameters)
scalew (scale all widths to this; use 0 for no scaling)
scaleh (scale all heights to this; use 0 for no scaling)
templ_type (L_USE_AVERAGE or L_USE_ALL)
threshold (for binarization; typically ~128)
maxyshift (from nominal centroid alignment; typically 0 or 1)
Return: recd, or null on error
Notes: (1) This is a convenience function that generates a recog using the unscaled training data in an existing recog.
| void recogDestroy | ( | L_RECOG ** | precog | ) |
Input: &recog (<will be set to null before returning>) Return: void
Notes: (1) If a recog has a parent, the parent owns it. A recogDestroy() will fail if there is a parent.
Input: recog (with LUT's pre-computed)
val (integer value; can be up to 3 bytes for UTF-8)
text (text from which @val was derived; used if not found)
&index (<return> index into dna_tochar)
Return: 0 if found; 1 if not found and added; 2 on error.
Notes: (1) This is used during training. It searches the dna character array for @val. If not found, it increments the setsize by 1, augmenting both the index and text arrays. (2) Returns the index in &index, except on error. (3) Caller must check the function return value.
Input: recog
index (into array of char types)
&charstr (<return> string representation;
returns an empty string on error)
Return: 0 if found, 1 on error
Notes: (1) Extracts a copy of the string from sa_text, which the caller must free. (2) Caller must check the function return value.
Input: recog Return: count of classes in recog; 0 if no recog or on error
Input: recog
&index (into the parent recoga; -1 if no parent)
Return: 0 if OK, 1 on error
Input: recog Return: recoga (back-pointer to parent); can be null
| L_RECOG* recogRead | ( | const char * | filename | ) |
Input: filename Return: recog, or null on error
Notes: (1) Serialization can be applied to any recognizer, including one with more than one "font". That is, it can have multiple character classes with the same character set description, where each of those classes contains characters that are very similar in size and shape. Each pixa in the serialized pixaa contains images for a single character class.
| L_RECOG* recogReadStream | ( | FILE * | fp | ) |
Input: stream Return: recog, or null on error
Input: &recog1 (old recog, to be destroyed)
recog2 (new recog, to be inserted in place of @recog1)
Return: 0 if OK, 1 on error
Notes: (1) This always destroys recog1. (2) If recog1 belongs to a recoga, this inserts recog2 into the slot that recog1 previously occupied.
Input: recog Return: 0 if OK, 1 on error
Notes: (1) This must be set for any bootstrap recog, where the samples are not from the media being identified. (2) It is used to enforce scaled bitmaps for identification, and to prevent the recog from being used to split touching characters (which requires unscaled samples from the material being identified).
Input: recog
text (text string for some class)
&index (<return> index for that class; -1 if not found)
Return: 0 if OK, 1 on error (not finding the string is an error)
Input: filename
recog
Return: 0 if OK, 1 on error
Input: filename
recog
Return: 0 if OK, 1 on error
Notes: (1) This generates a pixa of all the unscaled images in the recognizer, where each one has its character string in the pix text field, by flattening pixaa_u to a pixa. (2) As a side-effect, the character class label is written into each pix in recog.
Input: stream (opened for "wb")
recog
filename (output serialized filename; embedded in file)
Return: 0 if OK, 1 on error
|
static |
|
static |
|
static |