Tesseract 3.02

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Macros | Typedefs | Functions | Variables
protos.h File Reference
`#include "bitvec.h"`
`#include "cutil.h"`
`#include "unichar.h"`
`#include "unicity_table.h"`
`#include "params.h"`

Go to the source code of this file.

## Classes

struct | PROTO_STRUCT
struct | CLASS_STRUCT

## Macros

#define | NUMBER_OF_CLASSES MAX_NUM_CLASSES
#define | Y_OFFSET -40.0
#define | FEATURE_SCALE 100.0
#define | AddProtoToConfig(Pid, Config) (SET_BIT (Config, Pid))
#define | RemoveProtoFromConfig(Pid, Config) (reset_bit (Config, Pid))
#define | ClassOfChar(Char)
#define | ProtoIn(Class, Pid) (& (Class)->Prototypes [Pid])
#define | PrintProto(Proto)
#define | PrintProtoLine(Proto)

## Typedefs

typedef BIT_VECTOR * | CONFIGS
typedef PROTO_STRUCT * | PROTO
typedef CLASS_STRUCT * | CLASS_TYPE
typedef CLASS_STRUCT * | CLASSES

## Functions

int | AddConfigToClass (CLASS_TYPE Class)
int | AddProtoToClass (CLASS_TYPE Class)
FLOAT32 | ClassConfigLength (CLASS_TYPE Class, BIT_VECTOR Config)
FLOAT32 | ClassProtoLength (CLASS_TYPE Class)
void | CopyProto (PROTO Src, PROTO Dest)
void | FillABC (PROTO Proto)
void | FreeClass (CLASS_TYPE Class)
void | FreeClassFields (CLASS_TYPE Class)
void | InitPrototypes ()
CLASS_TYPE | NewClass (int NumProtos, int NumConfigs)
void | PrintProtos (CLASS_TYPE Class)
void | ReadClassFromFile (FILE *File, UNICHAR_ID unichar_id)
void | ReadConfigs (register FILE *File, CLASS_TYPE Class)
void | ReadProtos (register FILE *File, CLASS_TYPE Class)
int | SplitProto (CLASS_TYPE Class, int OldPid)
void | WriteOldConfigFile (FILE *File, CLASS_TYPE Class)
void | WriteOldProtoFile (FILE *File, CLASS_TYPE Class)

## Variables

CLASS_STRUCT | TrainingData []
char * | classify_training_file = "MicroFeatures"

## Macro Definition Documentation

#define AddProtoToConfig | ( |  | Pid,
|  |  | Config
| ) |  | (SET_BIT (Config, Pid))

AddProtoToConfig

Set a single proto bit in the specified configuration.

Definition at line 93 of file protos.h.

#define ClassOfChar | ( |  | Char | ) |

Value:
((TrainingData [Char].NumProtos) ? \
(& TrainingData [Char]) : \
NO_CLASS)

ClassOfChar

Return the class of a particular ASCII character value.

Definition at line 111 of file protos.h.

#define FEATURE_SCALE 100.0

Definition at line 75 of file protos.h.

#define NUMBER_OF_CLASSES MAX_NUM_CLASSES

Definition at line 73 of file protos.h.

#define PrintProto | ( |  | Proto | ) |

Value:
(cprintf ("X=%4.2f, Y=%4.2f, Angle=%4.2f", \
Proto->X, \
Proto->Y, \
Proto->Length, \
Proto->Angle)) \

PrintProto

Print out the contents of a prototype. The 'Proto' argument is of type 'PROTO'.

Definition at line 133 of file protos.h.

#define PrintProtoLine | ( |  | Proto | ) |

Value:
(cprintf ("A=%4.2f, B=%4.2f, C=%4.2f", \
Proto->A, \
Proto->B, \
Proto->C)) \

PrintProtoLine

Print out the contents of a prototype. The 'Proto' argument is of type 'PROTO'.

Definition at line 148 of file protos.h.

#define ProtoIn | ( |  | Class,
|  |  | Pid
| ) |  | (& (Class)->Prototypes [Pid])

ProtoIn

Choose the selected prototype in this class record. Return the pointer to it (type PROTO).

Definition at line 123 of file protos.h.

#define RemoveProtoFromConfig | ( |  | Pid,
|  |  | Config
| ) |  | (reset_bit (Config, Pid))

RemoveProtoFromConfig

Clear a single proto bit in the specified configuration.

Definition at line 102 of file protos.h.

#define Y_OFFSET -40.0

Definition at line 74 of file protos.h.

## Typedef Documentation

typedef CLASS_STRUCT* CLASS_TYPE

Definition at line 67 of file protos.h.

typedef CLASS_STRUCT* CLASSES

Definition at line 68 of file protos.h.

typedef BIT_VECTOR* CONFIGS

Definition at line 40 of file protos.h.

typedef PROTO_STRUCT* PROTO

Definition at line 52 of file protos.h.

## Function Documentation

int AddConfigToClass | ( | CLASS_TYPE | Class | ) |

Definition at line 63 of file protos.cpp.

{
int NewNumConfigs;
int NewConfig;
int MaxNumProtos;
BIT_VECTOR Config;
MaxNumProtos = Class->MaxNumProtos;
if (Class->NumConfigs >= Class->MaxNumConfigs) {
/* add configs in CONFIG_INCREMENT chunks at a time */
NewNumConfigs = (((Class->MaxNumConfigs + CONFIG_INCREMENT) /
CONFIG_INCREMENT) * CONFIG_INCREMENT);
Class->Configurations =
(CONFIGS) Erealloc (Class->Configurations,
sizeof (BIT_VECTOR) * NewNumConfigs);
Class->MaxNumConfigs = NewNumConfigs;
}
NewConfig = Class->NumConfigs++;
Config = NewBitVector (MaxNumProtos);
Class->Configurations[NewConfig] = Config;
zero_all_bits (Config, WordsInVectorOfSize (MaxNumProtos));
return (NewConfig);
}

int AddProtoToClass | ( | CLASS_TYPE | Class | ) |

Definition at line 99 of file protos.cpp.

{
int i;
int Bit;
int NewNumProtos;
int NewProto;
BIT_VECTOR Config;
if (Class->NumProtos >= Class->MaxNumProtos) {
/* add protos in PROTO_INCREMENT chunks at a time */
NewNumProtos = (((Class->MaxNumProtos + PROTO_INCREMENT) /
PROTO_INCREMENT) * PROTO_INCREMENT);
Class->Prototypes = (PROTO) Erealloc (Class->Prototypes,
sizeof (PROTO_STRUCT) *
NewNumProtos);
Class->MaxNumProtos = NewNumProtos;
for (i = 0; i < Class->NumConfigs; i++) {
Config = Class->Configurations[i];
Class->Configurations[i] = ExpandBitVector (Config, NewNumProtos);
for (Bit = Class->NumProtos; Bit < NewNumProtos; Bit++)
reset_bit(Config, Bit);
}
}
NewProto = Class->NumProtos++;
if (Class->NumProtos > MAX_NUM_PROTOS) {
tprintf("Ouch! number of protos = %d, vs max of %d!",
Class->NumProtos, MAX_NUM_PROTOS);
}
return (NewProto);
}

FLOAT32 ClassConfigLength | ( | CLASS_TYPE | Class,
|  | BIT_VECTOR | Config
| ) |  |

Definition at line 142 of file protos.cpp.

{
inT16 Pid;
FLOAT32 TotalLength = 0;
for (Pid = 0; Pid < Class->NumProtos; Pid++) {
if (test_bit (Config, Pid)) {
TotalLength += (ProtoIn (Class, Pid))->Length;
}
}
return (TotalLength);
}

FLOAT32 ClassProtoLength | ( | CLASS_TYPE | Class | ) |

Definition at line 163 of file protos.cpp.

{
inT16 Pid;
FLOAT32 TotalLength = 0;
for (Pid = 0; Pid < Class->NumProtos; Pid++) {
TotalLength += (ProtoIn (Class, Pid))->Length;
}
return (TotalLength);
}

void CopyProto | ( | PROTO | Src,
|  | PROTO | Dest
| ) |  |

Definition at line 182 of file protos.cpp.

{
Dest->X = Src->X;
Dest->Y = Src->Y;
Dest->Length = Src->Length;
Dest->Angle = Src->Angle;
Dest->A = Src->A;
Dest->B = Src->B;
Dest->C = Src->C;
}

void FillABC | ( | PROTO | Proto | ) |

Definition at line 198 of file protos.cpp.

{
FLOAT32 Slope, Intercept, Normalizer;
Slope = tan (Proto->Angle * 2.0 * PI);
Intercept = Proto->Y - Slope * Proto->X;
Normalizer = 1.0 / sqrt (Slope * Slope + 1.0);
Proto->A = Slope * Normalizer;
Proto->B = -Normalizer;
Proto->C = Intercept * Normalizer;
}

void FreeClass | ( | CLASS_TYPE | Class | ) |

Definition at line 215 of file protos.cpp.

{
if (Class) {
FreeClassFields(Class);
delete Class;
}
}

void FreeClassFields | ( | CLASS_TYPE | Class | ) |

Definition at line 228 of file protos.cpp.

{
int i;
if (Class) {
if (Class->MaxNumProtos > 0)
memfree (Class->Prototypes);
if (Class->MaxNumConfigs > 0) {
for (i = 0; i < Class->NumConfigs; i++)
FreeBitVector (Class->Configurations[i]);
memfree (Class->Configurations);
}
}
}

void InitPrototypes | ( |  | ) |

CLASS_TYPE NewClass | ( | int | NumProtos,
|  | int | NumConfigs
| ) |  |

Definition at line 248 of file protos.cpp.

{
CLASS_TYPE Class;
Class = new CLASS_STRUCT;
if (NumProtos > 0)
Class->Prototypes = (PROTO) Emalloc (NumProtos * sizeof (PROTO_STRUCT));
if (NumConfigs > 0)
Class->Configurations = (CONFIGS) Emalloc (NumConfigs *
sizeof (BIT_VECTOR));
Class->MaxNumProtos = NumProtos;
Class->MaxNumConfigs = NumConfigs;
Class->NumProtos = 0;
Class->NumConfigs = 0;
return (Class);
}

void PrintProtos | ( | CLASS_TYPE | Class | ) |

Definition at line 273 of file protos.cpp.

{
inT16 Pid;
for (Pid = 0; Pid < Class->NumProtos; Pid++) {
cprintf ("Proto %d:\t", Pid);
PrintProto (ProtoIn (Class, Pid));
cprintf ("\t");
PrintProtoLine (ProtoIn (Class, Pid));
new_line();
}
}

void ReadClassFromFile | ( | FILE * | File,
|  | UNICHAR_ID | unichar_id
| ) |  |

ReadClassFromFile

Read in a class description (protos and configs) from a file. Update the class structure record.

Definition at line 321 of file protos.cpp.

{
CLASS_TYPE Class;
Class = &TrainingData[unichar_id];
ReadProtos(File, Class);
ReadConfigs(File, Class);
}

void ReadConfigs | ( | register FILE * | File,
|  | CLASS_TYPE | Class
| ) |  |

ReadConfigs

Read the prototype configurations for this class from a file. Read the requested number of lines.

Definition at line 337 of file protos.cpp.

{
inT16 Cid;
register inT16 Wid;
register BIT_VECTOR ThisConfig;
int NumWords;
int NumConfigs;
fscanf (File, "%d %d\n", &NumConfigs, &NumWords);
Class->NumConfigs = NumConfigs;
Class->MaxNumConfigs = NumConfigs;
Class->Configurations =
(CONFIGS) Emalloc (sizeof (BIT_VECTOR) * NumConfigs);
NumWords = WordsInVectorOfSize (Class->NumProtos);
for (Cid = 0; Cid < NumConfigs; Cid++) {
ThisConfig = NewBitVector (Class->NumProtos);
for (Wid = 0; Wid < NumWords; Wid++)
fscanf (File, "%x", &ThisConfig[Wid]);
Class->Configurations[Cid] = ThisConfig;
}
}

void ReadProtos | ( | register FILE * | File,
|  | CLASS_TYPE | Class
| ) |  |

ReadProtos

Read in all the prototype information from a file. Read the number of lines requested.

Definition at line 367 of file protos.cpp.

{
register inT16 Pid;
register PROTO Proto;
int NumProtos;
fscanf (File, "%d\n", &NumProtos);
Class->NumProtos = NumProtos;
Class->MaxNumProtos = NumProtos;
Class->Prototypes = (PROTO) Emalloc (sizeof (PROTO_STRUCT) * NumProtos);
for (Pid = 0; Pid < NumProtos; Pid++) {
Proto = ProtoIn (Class, Pid);
fscanf (File, "%f %f %f %f %f %f %f\n",
&Proto->X,
&Proto->Y,
&Proto->Length,
&Proto->Angle,
&Proto->A,
&Proto->B, &Proto->C);
}
}

int SplitProto | ( | CLASS_TYPE | Class,
|  | int | OldPid
| ) |  |

Definition at line 399 of file protos.cpp.

{
int i;
int NewPid;
BIT_VECTOR Config;
NewPid = AddProtoToClass (Class);
for (i = 0; i < Class->NumConfigs; i++) {
Config = Class->Configurations[i];
if (test_bit (Config, OldPid))
SET_BIT(Config, NewPid);
}
return (NewPid);
}

void WriteOldConfigFile | ( | FILE * | File,
|  | CLASS_TYPE | Class
| ) |  |

Definition at line 425 of file protos.cpp.

{
int Cid, Pid;
BIT_VECTOR Config;
fprintf (File, "%d %d\n", Class->NumConfigs, Class->NumProtos);
for (Cid = 0; Cid < Class->NumConfigs; Cid++) {
fprintf (File, "1 ");
Config = Class->Configurations[Cid];
for (Pid = 0; Pid < Class->NumProtos; Pid++) {
if (test_bit (Config, Pid))
fprintf (File, "1");
else
fprintf (File, "0");
}
fprintf (File, "\n");
}
}

void WriteOldProtoFile | ( | FILE * | File,
|  | CLASS_TYPE | Class
| ) |  |

Definition at line 457 of file protos.cpp.

{
int Pid;
PROTO Proto;
/* print old header */
fprintf (File, "6\n");
fprintf (File, "linear essential -0.500000 0.500000\n");
fprintf (File, "linear essential -0.250000 0.750000\n");
fprintf (File, "linear essential 0.000000 1.000000\n");
fprintf (File, "circular essential 0.000000 1.000000\n");
fprintf (File, "linear non-essential -0.500000 0.500000\n");
fprintf (File, "linear non-essential -0.500000 0.500000\n");
for (Pid = 0; Pid < Class->NumProtos; Pid++) {
Proto = ProtoIn (Class, Pid);
fprintf (File, "significant elliptical 1\n");
fprintf (File, " %9.6f %9.6f %9.6f %9.6f %9.6f %9.6f\n",
Proto->X, Proto->Y,
Proto->Length, Proto->Angle, 0.0, 0.0);
fprintf (File, " %9.6f %9.6f %9.6f %9.6f %9.6f %9.6f\n",
0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001);
}
}

## Variable Documentation

char* classify_training_file = "MicroFeatures"

"Training file"

Definition at line 50 of file protos.cpp.

CLASS_STRUCT TrainingData[]

Definition at line 48 of file protos.cpp.