tesseract
4.0.0-1-g2a2b
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cassert>
#include "classify.h"
#include "callcpp.h"
#include "emalloc.h"
#include "fontinfo.h"
#include "genericvector.h"
#include "globals.h"
#include "helpers.h"
#include "intproto.h"
#include "mfoutline.h"
#include "picofeat.h"
#include "points.h"
#include "shapetable.h"
#include "svmnode.h"
Go to the source code of this file.
Classes | |
struct | FILL_SWITCH |
struct | TABLE_FILLER |
struct | FILL_SPEC |
Namespaces | |
tesseract | |
Macros | |
#define | PROTO_PRUNER_SCALE (4.0) |
#define | INT_DESCENDER (0.0 * INT_CHAR_NORM_RANGE) |
#define | INT_BASELINE (0.25 * INT_CHAR_NORM_RANGE) |
#define | INT_XHEIGHT (0.75 * INT_CHAR_NORM_RANGE) |
#define | INT_CAPHEIGHT (1.0 * INT_CHAR_NORM_RANGE) |
#define | INT_XCENTER (0.5 * INT_CHAR_NORM_RANGE) |
#define | INT_YCENTER (0.5 * INT_CHAR_NORM_RANGE) |
#define | INT_XRADIUS (0.2 * INT_CHAR_NORM_RANGE) |
#define | INT_YRADIUS (0.2 * INT_CHAR_NORM_RANGE) |
#define | INT_MIN_X 0 |
#define | INT_MIN_Y 0 |
#define | INT_MAX_X INT_CHAR_NORM_RANGE |
#define | INT_MAX_Y INT_CHAR_NORM_RANGE |
#define | HV_TOLERANCE (0.0025) /* approx 0.9 degrees */ |
#define | MAX_NUM_SWITCHES 3 |
#define | OLD_MAX_NUM_CONFIGS 32 |
#define | OLD_WERDS_PER_CONFIG_VEC |
#define | CircularIncrement(i, r) (((i) < (r) - 1)?((i)++):((i) = 0)) |
#define | MapParam(P, O, N) (std::floor(((P) + (O)) * (N))) |
#define | MAX_LEVEL 2 |
#define | XS X_SHIFT |
#define | YS Y_SHIFT |
#define | AS ANGLE_SHIFT |
#define | NB NUM_CP_BUCKETS |
Enumerations | |
enum | SWITCH_TYPE { StartSwitch, EndSwitch, LastSwitch } |
Functions | |
float | BucketStart (int Bucket, float Offset, int NumBuckets) |
float | BucketEnd (int Bucket, float Offset, int NumBuckets) |
void | DoFill (FILL_SPEC *FillSpec, CLASS_PRUNER_STRUCT *Pruner, uint32_t ClassMask, uint32_t ClassCount, uint32_t WordIndex) |
bool | FillerDone (TABLE_FILLER *Filler) |
void | FillPPCircularBits (uint32_t ParamTable[NUM_PP_BUCKETS][WERDS_PER_PP_VECTOR], int Bit, float Center, float Spread, bool debug) |
void | FillPPLinearBits (uint32_t ParamTable[NUM_PP_BUCKETS][WERDS_PER_PP_VECTOR], int Bit, float Center, float Spread, bool debug) |
void | GetCPPadsForLevel (int Level, float *EndPad, float *SidePad, float *AnglePad) |
ScrollView::Color | GetMatchColorFor (float Evidence) |
void | GetNextFill (TABLE_FILLER *Filler, FILL_SPEC *Fill) |
void | InitTableFiller (float EndPad, float SidePad, float AnglePad, PROTO Proto, TABLE_FILLER *Filler) |
void | RenderIntFeature (ScrollView *window, const INT_FEATURE_STRUCT *Feature, ScrollView::Color color) |
void | RenderIntProto (ScrollView *window, INT_CLASS Class, PROTO_ID ProtoId, ScrollView::Color color) |
int | TruncateParam (float Param, int Min, int Max, char *Id) |
void | AddIntClass (INT_TEMPLATES Templates, CLASS_ID ClassId, INT_CLASS Class) |
int | AddIntConfig (INT_CLASS Class) |
int | AddIntProto (INT_CLASS Class) |
void | AddProtoToClassPruner (PROTO Proto, CLASS_ID ClassId, INT_TEMPLATES Templates) |
void | AddProtoToProtoPruner (PROTO Proto, int ProtoId, INT_CLASS Class, bool debug) |
uint8_t | Bucket8For (float param, float offset, int num_buckets) |
uint16_t | Bucket16For (float param, float offset, int num_buckets) |
uint8_t | CircBucketFor (float param, float offset, int num_buckets) |
void | UpdateMatchDisplay () |
void | ConvertConfig (BIT_VECTOR Config, int ConfigId, INT_CLASS Class) |
void | DisplayIntFeature (const INT_FEATURE_STRUCT *Feature, float Evidence) |
void | DisplayIntProto (INT_CLASS Class, PROTO_ID ProtoId, float Evidence) |
INT_CLASS | NewIntClass (int MaxNumProtos, int MaxNumConfigs) |
INT_TEMPLATES | NewIntTemplates () |
void | free_int_templates (INT_TEMPLATES templates) |
void | tesseract::ClearFeatureSpaceWindow (NORM_METHOD norm_method, ScrollView *window) |
void | InitIntMatchWindowIfReqd () |
void | InitProtoDisplayWindowIfReqd () |
void | InitFeatureDisplayWindowIfReqd () |
ScrollView * | CreateFeatureSpaceWindow (const char *name, int xpos, int ypos) |
Variables | |
ScrollView * | IntMatchWindow = nullptr |
ScrollView * | FeatureDisplayWindow = nullptr |
ScrollView * | ProtoDisplayWindow = nullptr |
int | classify_num_cp_levels = 3 |
double | classify_cp_angle_pad_loose = 45.0 |
double | classify_cp_angle_pad_medium = 20.0 |
double | classify_cp_angle_pad_tight = 10.0 |
double | classify_cp_end_pad_loose = 0.5 |
double | classify_cp_end_pad_medium = 0.5 |
double | classify_cp_end_pad_tight = 0.5 |
double | classify_cp_side_pad_loose = 2.5 |
double | classify_cp_side_pad_medium = 1.2 |
double | classify_cp_side_pad_tight = 0.6 |
double | classify_pp_angle_pad = 45.0 |
double | classify_pp_end_pad = 0.5 |
double | classify_pp_side_pad = 2.5 |
#define AS ANGLE_SHIFT |
#define CircularIncrement | ( | i, | |
r | |||
) | (((i) < (r) - 1)?((i)++):((i) = 0)) |
macro for performing circular increments of bucket indices
Definition at line 117 of file intproto.cpp.
#define HV_TOLERANCE (0.0025) /* approx 0.9 degrees */ |
define pad used to snap near horiz/vertical protos to horiz/vertical
Definition at line 66 of file intproto.cpp.
#define INT_BASELINE (0.25 * INT_CHAR_NORM_RANGE) |
Definition at line 52 of file intproto.cpp.
#define INT_CAPHEIGHT (1.0 * INT_CHAR_NORM_RANGE) |
Definition at line 54 of file intproto.cpp.
#define INT_DESCENDER (0.0 * INT_CHAR_NORM_RANGE) |
Definition at line 51 of file intproto.cpp.
#define INT_MAX_X INT_CHAR_NORM_RANGE |
Definition at line 62 of file intproto.cpp.
#define INT_MAX_Y INT_CHAR_NORM_RANGE |
Definition at line 63 of file intproto.cpp.
#define INT_MIN_X 0 |
Definition at line 60 of file intproto.cpp.
#define INT_MIN_Y 0 |
Definition at line 61 of file intproto.cpp.
#define INT_XCENTER (0.5 * INT_CHAR_NORM_RANGE) |
Definition at line 56 of file intproto.cpp.
#define INT_XHEIGHT (0.75 * INT_CHAR_NORM_RANGE) |
Definition at line 53 of file intproto.cpp.
#define INT_XRADIUS (0.2 * INT_CHAR_NORM_RANGE) |
Definition at line 58 of file intproto.cpp.
#define INT_YCENTER (0.5 * INT_CHAR_NORM_RANGE) |
Definition at line 57 of file intproto.cpp.
#define INT_YRADIUS (0.2 * INT_CHAR_NORM_RANGE) |
Definition at line 59 of file intproto.cpp.
#define MapParam | ( | P, | |
O, | |||
N | |||
) | (std::floor(((P) + (O)) * (N))) |
macro for mapping floats to ints without bounds checking
Definition at line 120 of file intproto.cpp.
#define MAX_LEVEL 2 |
#define MAX_NUM_SWITCHES 3 |
Definition at line 71 of file intproto.cpp.
#define NB NUM_CP_BUCKETS |
#define OLD_MAX_NUM_CONFIGS 32 |
Definition at line 109 of file intproto.cpp.
#define OLD_WERDS_PER_CONFIG_VEC |
Definition at line 110 of file intproto.cpp.
#define PROTO_PRUNER_SCALE (4.0) |
Definition at line 49 of file intproto.cpp.
#define XS X_SHIFT |
#define YS Y_SHIFT |
enum SWITCH_TYPE |
Enumerator | |
---|---|
StartSwitch | |
EndSwitch | |
LastSwitch |
Definition at line 68 of file intproto.cpp.
void AddIntClass | ( | INT_TEMPLATES | Templates, |
CLASS_ID | ClassId, | ||
INT_CLASS | Class | ||
) |
This routine adds a new class structure to a set of templates. Classes have to be added to Templates in the order of increasing ClassIds.
Templates | templates to add new class to |
ClassId | class id to associate new class with |
Class | class data structure to add to templates |
Globals: none
Definition at line 232 of file intproto.cpp.
int AddIntConfig | ( | INT_CLASS | Class | ) |
This routine returns the index of the next free config in Class.
Class | class to add new configuration to |
Globals: none
Definition at line 262 of file intproto.cpp.
int AddIntProto | ( | INT_CLASS | Class | ) |
This routine allocates the next free proto in Class and returns its index.
Class | class to add new proto to |
Globals: none
Definition at line 283 of file intproto.cpp.
void AddProtoToClassPruner | ( | PROTO | Proto, |
CLASS_ID | ClassId, | ||
INT_TEMPLATES | Templates | ||
) |
This routine adds Proto to the class pruning tables for the specified class in Templates.
Globals:
Proto | floating-pt proto to add to class pruner |
ClassId | class id corresponding to Proto |
Templates | set of templates containing class pruner |
Definition at line 330 of file intproto.cpp.
This routine updates the proto pruner lookup tables for Class to include a new proto identified by ProtoId and described by Proto.
Proto | floating-pt proto to be added to proto pruner |
ProtoId | id of proto |
Class | integer class that contains desired proto pruner |
debug | debug flag |
Definition at line 370 of file intproto.cpp.
uint16_t Bucket16For | ( | float | param, |
float | offset, | ||
int | num_buckets | ||
) |
Definition at line 425 of file intproto.cpp.
uint8_t Bucket8For | ( | float | param, |
float | offset, | ||
int | num_buckets | ||
) |
Returns a quantized bucket for the given param shifted by offset, notionally (param + offset) * num_buckets, but clipped and casted to the appropriate type.
Definition at line 421 of file intproto.cpp.
float BucketEnd | ( | int | Bucket, |
float | Offset, | ||
int | NumBuckets | ||
) |
This routine returns the parameter value which corresponds to the end of the specified bucket. The bucket number should have been generated using the BucketFor() function with parameters Offset and NumBuckets.
Bucket | bucket whose end is to be computed |
Offset | offset used to map params to buckets |
NumBuckets | total number of buckets |
Definition at line 1121 of file intproto.cpp.
float BucketStart | ( | int | Bucket, |
float | Offset, | ||
int | NumBuckets | ||
) |
This routine returns the parameter value which corresponds to the beginning of the specified bucket. The bucket number should have been generated using the BucketFor() function with parameters Offset and NumBuckets.
Bucket | bucket whose start is to be computed |
Offset | offset used to map params to buckets |
NumBuckets | total number of buckets |
Definition at line 1105 of file intproto.cpp.
uint8_t CircBucketFor | ( | float | param, |
float | offset, | ||
int | num_buckets | ||
) |
Returns a quantized bucket for the given circular param shifted by offset, notionally (param + offset) * num_buckets, but modded and casted to the appropriate type.
Definition at line 435 of file intproto.cpp.
void ConvertConfig | ( | BIT_VECTOR | Config, |
int | ConfigId, | ||
INT_CLASS | Class | ||
) |
This operation updates the config vectors of all protos in Class to indicate that the protos with 1's in Config belong to a new configuration identified by ConfigId. It is assumed that the length of the Config bit vector is equal to the number of protos in Class.
Config | config to be added to class |
ConfigId | id to be used for new config |
Class | class to add new config to |
Definition at line 469 of file intproto.cpp.
ScrollView* CreateFeatureSpaceWindow | ( | const char * | name, |
int | xpos, | ||
int | ypos | ||
) |
Creates a window of the appropriate size for displaying elements in feature space.
Definition at line 1789 of file intproto.cpp.
void DisplayIntFeature | ( | const INT_FEATURE_STRUCT * | Feature, |
float | Evidence | ||
) |
This routine renders the specified feature into a global display list.
Globals:
Feature | pico-feature to be displayed |
Evidence | best evidence for this feature (0-1) |
Definition at line 599 of file intproto.cpp.
This routine renders the specified proto into a global display list.
Globals:
Class | class to take proto from |
ProtoId | id of proto in Class to be displayed |
Evidence | total evidence for proto (0-1) |
Definition at line 618 of file intproto.cpp.
void DoFill | ( | FILL_SPEC * | FillSpec, |
CLASS_PRUNER_STRUCT * | Pruner, | ||
uint32_t | ClassMask, | ||
uint32_t | ClassCount, | ||
uint32_t | WordIndex | ||
) |
This routine fills in the section of a class pruner corresponding to a single x value for a single proto of a class.
FillSpec | specifies which bits to fill in pruner |
Pruner | class pruner to be filled |
ClassMask | indicates which bits to change in each word |
ClassCount | indicates what to change bits to |
WordIndex | indicates which word to change |
Definition at line 1137 of file intproto.cpp.
bool FillerDone | ( | TABLE_FILLER * | Filler | ) |
Return TRUE if the specified table filler is done, i.e. if it has no more lines to fill.
Filler | table filler to check if done |
Definition at line 1177 of file intproto.cpp.
void FillPPCircularBits | ( | uint32_t | ParamTable[NUM_PP_BUCKETS][WERDS_PER_PP_VECTOR], |
int | Bit, | ||
float | Center, | ||
float | Spread, | ||
bool | debug | ||
) |
This routine sets Bit in each bit vector whose bucket lies within the range Center +- Spread. The fill is done for a circular dimension, i.e. bucket 0 is adjacent to the last bucket. It is assumed that Center and Spread are expressed in a circular coordinate system whose range is 0 to 1.
ParamTable | table of bit vectors, one per param bucket |
Bit | bit position in vectors to be filled |
Center | center of filled area |
Spread | spread of filled area |
debug | debug flag |
Definition at line 1201 of file intproto.cpp.
void FillPPLinearBits | ( | uint32_t | ParamTable[NUM_PP_BUCKETS][WERDS_PER_PP_VECTOR], |
int | Bit, | ||
float | Center, | ||
float | Spread, | ||
bool | debug | ||
) |
This routine sets Bit in each bit vector whose bucket lies within the range Center +- Spread. The fill is done for a linear dimension, i.e. there is no wrap-around for this dimension. It is assumed that Center and Spread are expressed in a linear coordinate system whose range is approximately 0 to 1. Values outside this range will be clipped.
ParamTable | table of bit vectors, one per param bucket |
Bit | bit number being filled |
Center | center of filled area |
Spread | spread of filled area |
debug | debug flag |
Definition at line 1242 of file intproto.cpp.
void free_int_templates | ( | INT_TEMPLATES | templates | ) |
Definition at line 708 of file intproto.cpp.
void GetCPPadsForLevel | ( | int | Level, |
float * | EndPad, | ||
float * | SidePad, | ||
float * | AnglePad | ||
) |
This routine copies the appropriate global pad variables into EndPad, SidePad, and AnglePad. This is a kludge used to get around the fact that global control variables cannot be arrays. If the specified level is illegal, the tightest possible pads are returned.
Level | "tightness" level to return pads for |
EndPad | place to put end pad for Level |
SidePad | place to put side pad for Level |
AnglePad | place to put angle pad for Level |
Definition at line 1352 of file intproto.cpp.
ScrollView::Color GetMatchColorFor | ( | float | Evidence | ) |
Evidence | evidence value to return color for |
Definition at line 1391 of file intproto.cpp.
void GetNextFill | ( | TABLE_FILLER * | Filler, |
FILL_SPEC * | Fill | ||
) |
This routine returns (in Fill) the specification of the next line to be filled from Filler. FillerDone() should always be called before GetNextFill() to ensure that we do not run past the end of the fill table.
Filler | filler to get next fill spec from |
Fill | place to put spec for next fill |
Definition at line 1415 of file intproto.cpp.
void InitFeatureDisplayWindowIfReqd | ( | ) |
Initializes the feature display window if it is not already initialized.
Definition at line 1780 of file intproto.cpp.
void InitIntMatchWindowIfReqd | ( | ) |
Initializes the int matcher window if it is not already initialized.
Definition at line 1748 of file intproto.cpp.
void InitProtoDisplayWindowIfReqd | ( | ) |
Initializes the proto display window if it is not already initialized.
Definition at line 1769 of file intproto.cpp.
void InitTableFiller | ( | float | EndPad, |
float | SidePad, | ||
float | AnglePad, | ||
PROTO | Proto, | ||
TABLE_FILLER * | Filler | ||
) |
This routine computes a data structure (Filler) which can be used to fill in a rectangle surrounding the specified Proto.
EndPad,SidePad,AnglePad | padding to add to proto |
Proto | proto to create a filler for |
Filler | place to put table filler |
Definition at line 1465 of file intproto.cpp.
INT_CLASS NewIntClass | ( | int | MaxNumProtos, |
int | MaxNumConfigs | ||
) |
This routine creates a new integer class data structure and returns it. Sufficient space is allocated to handle the specified number of protos and configs.
MaxNumProtos | number of protos to allocate space for |
MaxNumConfigs | number of configs to allocate space for |
Definition at line 636 of file intproto.cpp.
INT_TEMPLATES NewIntTemplates | ( | ) |
This routine allocates a new set of integer templates initialized to hold 0 classes.
Definition at line 692 of file intproto.cpp.
void RenderIntFeature | ( | ScrollView * | window, |
const INT_FEATURE_STRUCT * | Feature, | ||
ScrollView::Color | color | ||
) |
This routine renders the specified feature into ShapeList.
window | to add feature rendering to |
Feature | feature to be rendered |
color | color to use for feature rendering |
Definition at line 1628 of file intproto.cpp.
void RenderIntProto | ( | ScrollView * | window, |
INT_CLASS | Class, | ||
PROTO_ID | ProtoId, | ||
ScrollView::Color | color | ||
) |
This routine extracts the parameters of the specified proto from the class description and adds a rendering of the proto onto the ShapeList.
window | ScrollView instance |
Class | class that proto is contained in |
ProtoId | id of proto to be rendered |
color | color to render proto in |
Globals: none
Definition at line 1662 of file intproto.cpp.
int TruncateParam | ( | float | Param, |
int | Min, | ||
int | Max, | ||
char * | Id | ||
) |
This routine truncates Param to lie within the range of Min-Max inclusive. If a truncation is performed, and Id is not null, an warning message is printed.
Param | parameter value to be truncated |
Min,Max | parameter limits (inclusive) |
Id | string id of parameter for error messages |
Globals: none
Definition at line 1727 of file intproto.cpp.
void UpdateMatchDisplay | ( | ) |
This routine clears the global feature and proto display lists.
Globals:
Definition at line 451 of file intproto.cpp.
double classify_cp_angle_pad_loose = 45.0 |
"Class Pruner Angle Pad Loose"
Definition at line 187 of file intproto.cpp.
double classify_cp_angle_pad_medium = 20.0 |
"Class Pruner Angle Pad Medium"
Definition at line 189 of file intproto.cpp.
double classify_cp_angle_pad_tight = 10.0 |
"CLass Pruner Angle Pad Tight"
Definition at line 191 of file intproto.cpp.
double classify_cp_end_pad_loose = 0.5 |
"Class Pruner End Pad Loose"
Definition at line 192 of file intproto.cpp.
double classify_cp_end_pad_medium = 0.5 |
"Class Pruner End Pad Medium"
Definition at line 193 of file intproto.cpp.
double classify_cp_end_pad_tight = 0.5 |
"Class Pruner End Pad Tight"
Definition at line 194 of file intproto.cpp.
double classify_cp_side_pad_loose = 2.5 |
"Class Pruner Side Pad Loose"
Definition at line 195 of file intproto.cpp.
double classify_cp_side_pad_medium = 1.2 |
"Class Pruner Side Pad Medium"
Definition at line 196 of file intproto.cpp.
double classify_cp_side_pad_tight = 0.6 |
"Class Pruner Side Pad Tight"
Definition at line 197 of file intproto.cpp.
int classify_num_cp_levels = 3 |
"Number of Class Pruner Levels"
Definition at line 185 of file intproto.cpp.
double classify_pp_angle_pad = 45.0 |
"Proto Pruner Angle Pad"
Definition at line 198 of file intproto.cpp.
double classify_pp_end_pad = 0.5 |
"Proto Prune End Pad"
Definition at line 199 of file intproto.cpp.
double classify_pp_side_pad = 2.5 |
"Proto Pruner Side Pad"
Definition at line 200 of file intproto.cpp.
ScrollView* FeatureDisplayWindow = nullptr |
Definition at line 177 of file intproto.cpp.
ScrollView* IntMatchWindow = nullptr |
Definition at line 176 of file intproto.cpp.
ScrollView* ProtoDisplayWindow = nullptr |
Definition at line 178 of file intproto.cpp.