tesseract  3.03
/usr/local/google/home/jbreiden/tesseract-ocr-read-only/classify/protos.cpp File Reference
#include "protos.h"
#include "const.h"
#include "emalloc.h"
#include "freelist.h"
#include "callcpp.h"
#include "tprintf.h"
#include "scanutils.h"
#include "globals.h"
#include "classify.h"
#include "params.h"
#include <stdio.h>
#include <math.h>

Go to the source code of this file.

Defines

#define PROTO_INCREMENT   32
#define CONFIG_INCREMENT   16

Functions

AddConfigToClass

Add a new config to this class. Malloc new space and copy the old configs if necessary. Return the config id for the new config.

Parameters:
ClassThe class to add to
int AddConfigToClass (CLASS_TYPE Class)
AddProtoToClass

Add a new proto to this class. Malloc new space and copy the old protos if necessary. Return the proto id for the new proto.

Parameters:
ClassThe class to add to
int AddProtoToClass (CLASS_TYPE Class)
ClassConfigLength

Return the length of all the protos in this class.

Parameters:
ClassThe class to add to
ConfigFIXME
FLOAT32 ClassConfigLength (CLASS_TYPE Class, BIT_VECTOR Config)
ClassProtoLength

Return the length of all the protos in this class.

Parameters:
ClassThe class to use
FLOAT32 ClassProtoLength (CLASS_TYPE Class)
CopyProto

Copy the first proto into the second.

Parameters:
SrcSource
DestDestination
void CopyProto (PROTO Src, PROTO Dest)
void FillABC (PROTO Proto)
void FreeClass (CLASS_TYPE Class)
void FreeClassFields (CLASS_TYPE Class)
CLASS_TYPE NewClass (int NumProtos, int NumConfigs)
void PrintProtos (CLASS_TYPE Class)

Variables

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

Define Documentation

#define CONFIG_INCREMENT   16

Definition at line 43 of file protos.cpp.

#define PROTO_INCREMENT   32

Definition at line 42 of file protos.cpp.


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);
}

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);
}

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);
    }
  }
}
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();
  }
}

Variable Documentation

char* classify_training_file = "MicroFeatures"

"Training file"

Definition at line 50 of file protos.cpp.

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines