52 #define PROTO_PRUNER_SCALE (4.0) 54 #define INT_DESCENDER (0.0 * INT_CHAR_NORM_RANGE) 55 #define INT_BASELINE (0.25 * INT_CHAR_NORM_RANGE) 56 #define INT_XHEIGHT (0.75 * INT_CHAR_NORM_RANGE) 57 #define INT_CAPHEIGHT (1.0 * INT_CHAR_NORM_RANGE) 59 #define INT_XCENTER (0.5 * INT_CHAR_NORM_RANGE) 60 #define INT_YCENTER (0.5 * INT_CHAR_NORM_RANGE) 61 #define INT_XRADIUS (0.2 * INT_CHAR_NORM_RANGE) 62 #define INT_YRADIUS (0.2 * INT_CHAR_NORM_RANGE) 65 #define INT_MAX_X INT_CHAR_NORM_RANGE 66 #define INT_MAX_Y INT_CHAR_NORM_RANGE 69 #define HV_TOLERANCE (0.0025) 74 #define MAX_NUM_SWITCHES 3 112 #define OLD_MAX_NUM_CONFIGS 32 113 #define OLD_WERDS_PER_CONFIG_VEC ((OLD_MAX_NUM_CONFIGS + BITS_PER_WERD - 1) /\ 120 #define CircularIncrement(i,r) (((i) < (r) - 1)?((i)++):((i) = 0)) 123 #define MapParam(P,O,N) (floor (((P) + (O)) * (N))) 134 register uinT32 ClassMask,
135 register uinT32 ClassCount,
136 register uinT32 WordIndex);
162 #ifndef GRAPHICS_DISABLED 170 #endif // GRAPHICS_DISABLED 190 "Class Pruner Angle Pad Loose");
192 "Class Pruner Angle Pad Medium");
194 "CLass Pruner Angle Pad Tight");
243 fprintf(stderr,
"Please make sure that classes are added to templates");
244 fprintf(stderr,
" in increasing order of ClassIds\n");
310 memset(ProtoSet, 0,
sizeof(*ProtoSet));
351 FLOAT32 EndPad, SidePad, AnglePad;
366 DoFill(&FillSpec, Pruner, ClassMask, ClassCount, WordIndex);
392 cprintf(
"AddProtoToProtoPruner:assert failed: %d < %d",
394 assert(ProtoId < Class->NumProtos);
399 Angle = Proto->
Angle;
401 assert(!isnan(Angle));
412 Pad =
MAX (fabs (cos (Angle)) * (Length / 2.0 +
421 Pad =
MAX (fabs (sin (Angle)) * (Length / 2.0 +
451 return static_cast<uinT8>(
Modulo(bucket, num_buckets));
455 #ifndef GRAPHICS_DISABLED 492 for (ProtoId = 0, TotalLength = 0;
520 assert(ProtoId < Class->NumProtos);
543 cprintf(
"Converted ffeat to (A=%d,B=%d,C=%d,L=%d)",
569 for (ClassId = 0; ClassId < target_unicharset.
size(); ClassId++) {
570 FClass = &(FloatProtos[ClassId]);
572 strcmp(target_unicharset.
id_to_unichar(ClassId),
" ") != 0) {
573 cprintf(
"Warning: no protos/configs for %s in CreateIntTemplates()\n",
581 for (
int i = 0; i < fs.
size; ++i) {
592 for (ProtoId = 0; ProtoId < FClass->
NumProtos; ProtoId++) {
600 for (ConfigId = 0; ConfigId < FClass->
NumConfigs; ConfigId++) {
605 return (IntTemplates);
610 #ifndef GRAPHICS_DISABLED 683 memset(ProtoSet, 0,
sizeof(*ProtoSet));
762 int i, j, w, x, y, z;
774 int b, bit_number, last_cp_bit_number, new_b, new_i, new_w;
782 uinT32 Mask, NewMask, ClassBits;
789 if (fread(&unicharset_size,
sizeof(
int), 1,
File) != 1)
790 cprintf(
"Bad read of inttemp!\n");
795 cprintf(
"Bad read of inttemp!\n");
809 cprintf(
"Bad read of inttemp!\n");
814 if (version_id < 3) {
819 if (version_id < 2) {
820 for (i = 0; i < unicharset_size; ++i) {
821 if (fread(&IndexFor[i],
sizeof(
inT16), 1,
File) != 1)
822 cprintf(
"Bad read of inttemp!\n");
825 if (fread(&ClassIdFor[i],
sizeof(
CLASS_ID), 1,
File) != 1)
826 cprintf(
"Bad read of inttemp!\n");
842 cprintf(
"Bad read of inttemp!\n");
854 if (version_id < 2) {
855 TempClassPruner[i] = Pruner;
862 if (version_id < 2) {
866 if (ClassIdFor[i] > max_class_id)
867 max_class_id = ClassIdFor[i];
880 if (TempClassPruner[i]->p[x][y][z][w] == 0)
884 if (bit_number > last_cp_bit_number)
888 Mask = SetBitsForMask << b;
889 ClassBits = TempClassPruner[i]->
p[x][y][z][w] & Mask;
896 ClassBits <<= (new_b - b);
898 ClassBits >>= (b - new_b);
902 NewMask = SetBitsForMask << new_b;
903 Templates->
ClassPruners[new_i]->
p[x][y][z][new_w] &= ~NewMask;
904 Templates->
ClassPruners[new_i]->
p[x][y][z][new_w] |= ClassBits;
909 delete TempClassPruner[i];
920 cprintf (
"Bad read of inttemp!\n");
921 if (version_id == 0) {
923 for (j = 0; j < 5; ++j) {
925 if (fread(&junk,
sizeof(junk), 1,
File) != 1)
926 cprintf (
"Bad read of inttemp!\n");
929 if (version_id < 4) {
930 for (j = 0; j < MaxNumConfigs; ++j) {
932 cprintf (
"Bad read of inttemp!\n");
936 for (j = 0; j < MaxNumConfigs; j++)
943 cprintf (
"Bad read of inttemp!\n");
947 for (j = 0; j < MaxNumConfigs; j++)
951 if (version_id < 2) {
962 fread((
char *)Lengths,
sizeof(
uinT8),
964 cprintf (
"Bad read of inttemp!\n");
971 if (version_id < 3) {
975 cprintf(
"Bad read of inttemp!\n");
977 if ((nread = fread((
char *) &ProtoSet->
Protos[x].
A, 1,
979 (nread = fread((
char *) &ProtoSet->
Protos[x].
B, 1,
981 (nread = fread((
char *) &ProtoSet->
Protos[x].
C, 1,
983 (nread = fread((
char *) &ProtoSet->
Protos[x].
Angle, 1,
985 cprintf(
"Bad read of inttemp!\n");
986 for (y = 0; y < WerdsPerConfigVec; y++)
987 if ((nread = fread((
char *) &ProtoSet->
Protos[x].
Configs[y], 1,
989 cprintf(
"Bad read of inttemp!\n");
995 cprintf(
"Bad read of inttemp!\n");
1003 for (y = 0; y < WerdsPerConfigVec; y++)
1017 if (version_id < 2) {
1025 if (i < Templates->NumClasses) {
1027 fprintf(stderr,
"Non-contiguous class ids in inttemp\n");
1032 fprintf(stderr,
"Class id %d exceeds NumClassesIn (Templates) %d\n",
1039 if (version_id >= 4) {
1041 if (version_id >= 5) {
1051 delete[] ClassIdFor;
1052 delete[] TempClassPruner;
1058 #ifndef GRAPHICS_DISABLED 1133 int unicharset_size = target_unicharset.
size();
1134 int version_id = -5;
1136 if (Templates->
NumClasses != unicharset_size) {
1137 cprintf(
"Warning: executing WriteIntTemplates() with %d classes in" 1138 " Templates, while target_unicharset size is %d\n",
1143 fwrite(&unicharset_size,
sizeof(unicharset_size), 1,
File);
1144 fwrite(&version_id,
sizeof(version_id), 1,
File);
1155 for (i = 0; i < Templates->
NumClasses; i++) {
1156 Class = Templates->
Class[i];
1208 return (((
FLOAT32) Bucket / NumBuckets) - Offset);
1226 return (((
FLOAT32) (Bucket + 1) / NumBuckets) - Offset);
1245 register uinT32 ClassMask,
1246 register uinT32 ClassCount,
1247 register uinT32 WordIndex) {
1257 if (FillSpec->
YStart < 0)
1262 for (Y = FillSpec->
YStart; Y <= FillSpec->YEnd; Y++)
1265 OldWord = Pruner->
p[X][Y][Angle][WordIndex];
1266 if (ClassCount > (OldWord & ClassMask)) {
1267 OldWord &= ~ClassMask;
1268 OldWord |= ClassCount;
1269 Pruner->
p[X][Y][Angle][WordIndex] = OldWord;
1316 int i, FirstBucket, LastBucket;
1322 if (FirstBucket < 0)
1328 if (debug)
tprintf(
"Circular fill from %d to %d", FirstBucket, LastBucket);
1333 if (i == LastBucket)
1359 int i, FirstBucket, LastBucket;
1362 if (FirstBucket < 0)
1369 if (debug)
tprintf(
"Linear fill from %d to %d", FirstBucket, LastBucket);
1370 for (i = FirstBucket; i <= LastBucket; i++)
1377 #ifndef GRAPHICS_DISABLED 1392 bool* pretrained_on,
int* shape_id) {
1396 int unichar_id = INVALID_UNICHAR_ID;
1405 *adaptive_on =
false;
1406 *pretrained_on =
true;
1407 if (*shape_id >= 0 && *shape_id < shape_table_->NumShapes()) {
1411 tprintf(
"Shape %d, first unichar=%d, font=%d\n",
1412 *shape_id, unichar_id, font_id);
1417 tprintf(
"No shape table loaded!\n");
1423 *adaptive_on =
true;
1424 *pretrained_on =
false;
1427 *adaptive_on =
false;
1428 *pretrained_on =
true;
1430 *adaptive_on =
true;
1431 *pretrained_on =
true;
1443 tprintf(
"Char class '%s' not found in unicharset",
1500 if (*AnglePad > 0.5)
1513 assert (Evidence >= 0.0);
1514 assert (Evidence <= 1.0);
1516 if (Evidence >= 0.90)
1518 else if (Evidence >= 0.75)
1520 else if (Evidence >= 0.50)
1544 Fill->
X = Filler->
X;
1550 while (Filler->
X >= Next->
X) {
1551 Fill->
X = Filler->
X = Next->
X;
1558 Fill->
YEnd = Next->
Y;
1594 #define AS ANGLE_SHIFT 1595 #define NB NUM_CP_BUCKETS 1601 FPOINT Start, Switch1, Switch2, End;
1605 Angle = Proto->
Angle;
1608 HalfLength = Proto->
Length / 2.0;
1636 if ((Angle > 0.0 && Angle < 0.25) || (Angle > 0.5 && Angle < 0.75)) {
1639 Cos = fabs(cos(Angle));
1640 Sin = fabs(sin(Angle));
1643 Start.
x = X - (HalfLength + EndPad) * Cos - SidePad * Sin;
1644 Start.
y = Y - (HalfLength + EndPad) * Sin + SidePad * Cos;
1645 End.
x = 2.0 * X - Start.
x;
1646 End.
y = 2.0 * Y - Start.
y;
1647 Switch1.
x = X - (HalfLength + EndPad) * Cos + SidePad * Sin;
1648 Switch1.
y = Y - (HalfLength + EndPad) * Sin - SidePad * Cos;
1649 Switch2.
x = 2.0 * X - Switch1.
x;
1650 Switch2.
y = 2.0 * Y - Switch1.
y;
1652 if (Switch1.
x > Switch2.
x) {
1663 YAdjust = XAdjust * Cos / Sin;
1665 YAdjust = XAdjust * Sin / Cos;
1672 YAdjust = XAdjust * Sin / Cos;
1680 YAdjust = XAdjust * Cos / Sin;
1689 Cos = fabs(cos(Angle));
1690 Sin = fabs(sin(Angle));
1693 Start.
x = X - (HalfLength + EndPad) * Cos - SidePad * Sin;
1694 Start.
y = Y + (HalfLength + EndPad) * Sin - SidePad * Cos;
1695 End.
x = 2.0 * X - Start.
x;
1696 End.
y = 2.0 * Y - Start.
y;
1697 Switch1.
x = X - (HalfLength + EndPad) * Cos + SidePad * Sin;
1698 Switch1.
y = Y + (HalfLength + EndPad) * Sin + SidePad * Cos;
1699 Switch2.
x = 2.0 * X - Switch1.
x;
1700 Switch2.
y = 2.0 * Y - Switch1.
y;
1702 if (Switch1.
x > Switch2.
x) {
1715 YAdjust = XAdjust * Sin / Cos;
1717 YAdjust = XAdjust * Cos / Sin;
1724 YAdjust = XAdjust * Sin / Cos;
1732 YAdjust = XAdjust * Cos / Sin;
1744 #ifndef GRAPHICS_DISABLED 1760 assert(Feature != NULL);
1768 Dx = (Length / 2.0) * cos((Feature->
Theta / 256.0) * 2.0 *
PI -
PI);
1769 Dy = (Length / 2.0) * sin((Feature->
Theta / 256.0) * 2.0 *
PI -
PI);
1772 window->
DrawTo(X + Dx, Y + Dy);
1800 int Xmin, Xmax, Ymin, Ymax;
1805 assert(ProtoId >= 0);
1806 assert(Class != NULL);
1807 assert(ProtoId < Class->NumProtos);
1813 Proto = &(ProtoSet->
Protos[ProtoSetIndex]);
1835 Dx = (Length / 2.0) * cos((Proto->
Angle / 256.0) * 2.0 *
PI -
PI);
1836 Dy = (Length / 2.0) * sin((Proto->
Angle / 256.0) * 2.0 *
PI -
PI);
1839 window->
DrawTo(X + Dx, Y + Dy);
1861 cprintf(
"Warning: Param %s truncated from %f to %d!\n",
1864 }
else if (Param > Max) {
1866 cprintf(
"Warning: Param %s truncated from %f to %d!\n",
1870 return static_cast<int>(floor(Param));
1874 #ifndef GRAPHICS_DISABLED 1885 "x",
"Class to debug");
1887 "x",
"Class to debug");
1889 "x",
"Class to debug");
1891 "0",
"Index to debug");
1921 return new ScrollView(name, xpos, ypos, 520, 520, 260, 260,
true);
1923 #endif // GRAPHICS_DISABLED void AddIntClass(INT_TEMPLATES Templates, CLASS_ID ClassId, INT_CLASS Class)
#define OLD_WERDS_PER_CONFIG_VEC
ScrollView * FeatureDisplayWindow
ScrollView * CreateFeatureSpaceWindow(const char *name, int xpos, int ypos)
void DrawTo(int x, int y)
void AddProtoToProtoPruner(PROTO Proto, int ProtoId, INT_CLASS Class, bool debug)
UnicityTable< FontSet > fontset_table_
INT_TEMPLATES ReadIntTemplates(FILE *File)
#define PPrunerWordIndexFor(I)
double classify_pp_angle_pad
double classify_cp_angle_pad_tight
void cprintf(const char *format,...)
void UpdateRange(const T1 &x, T2 *lower_bound, T2 *upper_bound)
#define PROTO_PRUNER_SCALE
struct INT_TEMPLATES_STRUCT * INT_TEMPLATES
#define WERDS_PER_PP_VECTOR
int IntCastRounded(double x)
bool read_info(FILE *f, FontInfo *fi, bool swap)
#define ProtoForProtoId(C, P)
void DisplayIntFeature(const INT_FEATURE_STRUCT *Feature, FLOAT32 Evidence)
ScrollView::Color GetMatchColorFor(FLOAT32 Evidence)
void InitIntMatchWindowIfReqd()
struct INT_CLASS_STRUCT * INT_CLASS
bool TESS_API contains_unichar(const char *const unichar_repr) const
struct PROTO_SET_STRUCT * PROTO_SET
_ConstTessMemberResultCallback_0_0< false, R, T1 >::base * NewPermanentTessCallback(const T1 *obj, R(T2::*member)() const)
void SetCursor(int x, int y)
void RenderIntFeature(ScrollView *window, const INT_FEATURE_STRUCT *Feature, ScrollView::Color color)
void Reverse32(void *ptr)
#define WERDS_PER_CP_VECTOR
void AddProtoToClassPruner(PROTO Proto, CLASS_ID ClassId, INT_TEMPLATES Templates)
BOOL8 FillerDone(TABLE_FILLER *Filler)
void RenderIntProto(ScrollView *window, INT_CLASS Class, PROTO_ID ProtoId, ScrollView::Color color)
#define MAX_NUM_CLASS_PRUNERS
void GetNextFill(TABLE_FILLER *Filler, FILL_SPEC *Fill)
#define UnusedClassIdIn(T, c)
void InitTableFiller(FLOAT32 EndPad, FLOAT32 SidePad, FLOAT32 AnglePad, PROTO Proto, TABLE_FILLER *Filler)
#define NUM_BITS_PER_CLASS
double classify_cp_side_pad_loose
#define OLD_MAX_NUM_CONFIGS
CLASS_ID GetClassToDebug(const char *Prompt, bool *adaptive_on, bool *pretrained_on, int *shape_id)
UnicityTableEqEq< int > font_set
FLOAT32 BucketStart(int Bucket, FLOAT32 Offset, int NumBuckets)
T ClipToRange(const T &x, const T &lower_bound, const T &upper_bound)
bool ContainsUnichar(int unichar_id) const
void InitProtoDisplayWindowIfReqd()
#define MaxNumIntProtosIn(C)
#define PROTOS_PER_PROTO_SET
void DoFill(FILL_SPEC *FillSpec, CLASS_PRUNER_STRUCT *Pruner, register uinT32 ClassMask, register uinT32 ClassCount, register uinT32 WordIndex)
void FillPPCircularBits(uinT32 ParamTable[NUM_PP_BUCKETS][WERDS_PER_PP_VECTOR], int Bit, FLOAT32 Center, FLOAT32 Spread, bool debug)
void UpdateMatchDisplay()
bool write_spacing_info(FILE *f, const FontInfo &fi)
int AddIntProto(INT_CLASS Class)
UnicityTable< FontInfo > fontinfo_table_
double classify_cp_angle_pad_loose
void free_int_class(INT_CLASS int_class)
bool write_set(FILE *f, const FontSet &fs)
#define ClassForClassId(T, c)
#define WERDS_PER_CONFIG_VEC
int size() const
Return the size used.
const char * string() const
#define MaxNumClassesIn(T)
ScrollView * ProtoDisplayWindow
#define SET_BIT(array, bit)
double classify_cp_end_pad_medium
uinT32 PROTO_PRUNER[NUM_PP_PARAMS][NUM_PP_BUCKETS][WERDS_PER_PP_VECTOR]
uinT8 Bucket8For(FLOAT32 param, FLOAT32 offset, int num_buckets)
uinT32 Configs[WERDS_PER_CONFIG_VEC]
INT_CLASS NewIntClass(int MaxNumProtos, int MaxNumConfigs)
ScrollView * IntMatchWindow
#define BITS_PER_CP_VECTOR
#define CPrunerWordIndexFor(c)
#define CPrunerMaskFor(L, c)
SVEvent * AwaitEvent(SVEventType type)
void ClearFeatureSpaceWindow(NORM_METHOD norm_method, ScrollView *window)
#define CPrunerBitIndexFor(c)
void free_int_templates(INT_TEMPLATES templates)
void InitFeatureDisplayWindowIfReqd()
int AddIntConfig(INT_CLASS Class)
INT_PROTO_STRUCT Protos[PROTOS_PER_PROTO_SET]
FILL_SWITCH Switch[MAX_NUM_SWITCHES]
void DisplayIntProto(INT_CLASS Class, PROTO_ID ProtoId, FLOAT32 Evidence)
void * Erealloc(void *ptr, int size)
double classify_cp_side_pad_tight
void GetFirstUnicharAndFont(int shape_id, int *unichar_id, int *font_id) const
#define PPrunerMaskFor(I)
void BuildMenu(ScrollView *sv, bool menu_bar=true)
UNICHAR_ID TESS_API unichar_to_id(const char *const unichar_repr) const
void Rectangle(int x1, int y1, int x2, int y2)
void ConvertProto(PROTO Proto, int ProtoId, INT_CLASS Class)
#define MAX_NUM_PROTO_SETS
PROTO_SET ProtoSets[MAX_NUM_PROTO_SETS]
FLOAT32 BucketEnd(int Bucket, FLOAT32 Offset, int NumBuckets)
double classify_pp_end_pad
uinT32 p[NUM_CP_BUCKETS][NUM_CP_BUCKETS][NUM_CP_BUCKETS][WERDS_PER_CP_VECTOR]
int classify_learning_debug_level
void GetCPPadsForLevel(int Level, FLOAT32 *EndPad, FLOAT32 *SidePad, FLOAT32 *AnglePad)
INT_TEMPLATES NewIntTemplates()
ShapeTable * shape_table_
#define MapParam(P, O, N)
void Reverse16(void *ptr)
#define CircularIncrement(i, r)
void WriteIntTemplates(FILE *File, INT_TEMPLATES Templates, const UNICHARSET &target_unicharset)
double classify_cp_end_pad_tight
const Shape & GetShape(int shape_id) const
int TruncateParam(FLOAT32 Param, int Min, int Max, char *Id)
SVMenuNode * AddChild(const char *txt)
#define ProtoIn(Class, Pid)
#define test_bit(array, bit)
void ConvertConfig(BIT_VECTOR Config, int ConfigId, INT_CLASS Class)
#define INT_CHAR_NORM_RANGE
uinT16 Bucket16For(FLOAT32 param, FLOAT32 offset, int num_buckets)
const T & get(int id) const
Return the object from an id.
CLASS_PRUNER_STRUCT * ClassPruners[MAX_NUM_CLASS_PRUNERS]
double classify_cp_side_pad_medium
void FillPPLinearBits(uinT32 ParamTable[NUM_PP_BUCKETS][WERDS_PER_PP_VECTOR], int Bit, FLOAT32 Center, FLOAT32 Spread, bool debug)
uinT8 CircBucketFor(FLOAT32 param, FLOAT32 offset, int num_buckets)
double classify_pp_side_pad
double classify_cp_end_pad_loose
#define double_VAR(name, val, comment)
double classify_cp_angle_pad_medium
const char * id_to_unichar(UNICHAR_ID id) const
uinT16 ConfigLengths[MAX_NUM_CONFIGS]
bool read_spacing_info(FILE *f, FontInfo *fi, bool swap)
STRING DebugStr(int shape_id) const
int classify_num_cp_levels
INT_CLASS Class[MAX_NUM_CLASSES]
#define INT_VAR(name, val, comment)
#define GetPicoFeatureLength()
bool write_info(FILE *f, const FontInfo &fi)
bool read_set(FILE *f, FontSet *fs, bool swap)
void ZoomToRectangle(int x1, int y1, int x2, int y2)
INT_TEMPLATES CreateIntTemplates(CLASSES FloatProtos, const UNICHARSET &target_unicharset)