Tesseract  3.02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
blobclass.h File Reference
#include "featdefs.h"
#include "oldlist.h"
#include "blobs.h"

Go to the source code of this file.

Macros

#define EnableCharDisplay()   (DisplayCharacters = TRUE)
 
#define DisableCharDisplay()   (DisplayCharacters = FALSE)
 
#define EnableMatchDisplay()   (DisplayMatchList = TRUE)
 
#define DisableMatchDisplay()   (DisplayMatchList = FALSE)
 

Functions

void LearnBlob (const FEATURE_DEFS_STRUCT &FeatureDefs, const STRING &filename, TBLOB *Blob, const DENORM &denorm, const char *BlobText)
 
void LearnBlob (const FEATURE_DEFS_STRUCT &FeatureDefs, FILE *File, TBLOB *Blob, const DENORM &denorm, const char *BlobText, const char *FontName)
 

Macro Definition Documentation

#define DisableCharDisplay ( )    (DisplayCharacters = FALSE)

Definition at line 33 of file blobclass.h.

#define DisableMatchDisplay ( )    (DisplayMatchList = FALSE)

Definition at line 37 of file blobclass.h.

#define EnableCharDisplay ( )    (DisplayCharacters = TRUE)

Include Files and Type Defines

Definition at line 32 of file blobclass.h.

#define EnableMatchDisplay ( )    (DisplayMatchList = TRUE)

Definition at line 36 of file blobclass.h.

Function Documentation

void LearnBlob ( const FEATURE_DEFS_STRUCT FeatureDefs,
const STRING filename,
TBLOB Blob,
const DENORM denorm,
const char *  BlobText 
)

Public Function Prototypes


Public Code

Definition at line 52 of file blobclass.cpp.

53  {
54 /*
55  ** Parameters:
56  ** Blob blob whose micro-features are to be learned
57  ** Row row of text that blob came from
58  ** BlobText text that corresponds to blob
59  ** TextLength number of characters in blob
60  ** Globals:
61  ** imagefile base filename of the page being learned
62  ** classify_font_name
63  ** name of font currently being trained on
64  ** Operation:
65  ** Extract micro-features from the specified blob and append
66  ** them to the appropriate file.
67  ** Return: none
68  ** Exceptions: none
69  ** History: 7/28/89, DSJ, Created.
70  */
71 #define TRAIN_SUFFIX ".tr"
72  static FILE *FeatureFile = NULL;
73  STRING Filename(filename);
74 
75  // If no fontname was set, try to extract it from the filename
76  STRING CurrFontName = classify_font_name;
77  if (CurrFontName == kUnknownFontName) {
78  // filename is expected to be of the form [lang].[fontname].exp[num]
79  // The [lang], [fontname] and [num] fields should not have '.' characters.
80  const char *basename = strrchr(filename.string(), '/');
81  const char *firstdot = strchr(basename ? basename : filename.string(), '.');
82  const char *lastdot = strrchr(filename.string(), '.');
83  if (firstdot != lastdot && firstdot != NULL && lastdot != NULL) {
84  ++firstdot;
85  CurrFontName = firstdot;
86  CurrFontName[lastdot - firstdot] = '\0';
87  }
88  }
89 
90  // if a feature file is not yet open, open it
91  // the name of the file is the name of the image plus TRAIN_SUFFIX
92  if (FeatureFile == NULL) {
93  Filename += TRAIN_SUFFIX;
94  FeatureFile = Efopen(Filename.string(), "wb");
95  cprintf("TRAINING ... Font name = %s\n", CurrFontName.string());
96  }
97 
98  LearnBlob(FeatureDefs, FeatureFile, Blob, denorm, BlobText,
99  CurrFontName.string());
100 } // LearnBlob
#define NULL
Definition: host.h:144
FILE * Efopen(const char *Name, const char *Mode)
Definition: efio.cpp:32
#define TRAIN_SUFFIX
const char * string() const
Definition: strngs.cpp:156
Definition: strngs.h:40
char * classify_font_name
Definition: blobclass.cpp:39
void LearnBlob(const FEATURE_DEFS_STRUCT &FeatureDefs, const STRING &filename, TBLOB *Blob, const DENORM &denorm, const char *BlobText)
Definition: blobclass.cpp:52
void cprintf(const char *format,...)
Definition: callcpp.cpp:41
void LearnBlob ( const FEATURE_DEFS_STRUCT FeatureDefs,
FILE *  File,
TBLOB Blob,
const DENORM denorm,
const char *  BlobText,
const char *  FontName 
)

Definition at line 102 of file blobclass.cpp.

104  {
105  CHAR_DESC CharDesc;
106 
107  ASSERT_HOST(FeatureFile != NULL);
108 
109  CharDesc = ExtractBlobFeatures(FeatureDefs, denorm, Blob);
110  if (CharDesc == NULL) {
111  cprintf("LearnBLob: CharDesc was NULL. Aborting.\n");
112  return;
113  }
114 
115  if (ValidCharDescription(FeatureDefs, CharDesc)) {
116  // label the features with a class name and font name
117  fprintf(FeatureFile, "\n%s %s\n", FontName, BlobText);
118 
119  // write micro-features to file and clean up
120  WriteCharDescription(FeatureDefs, FeatureFile, CharDesc);
121  } else {
122  tprintf("Blob learned was invalid!\n");
123  }
124  FreeCharDescription(CharDesc);
125 
126 } // LearnBlob
#define NULL
Definition: host.h:144
bool ValidCharDescription(const FEATURE_DEFS_STRUCT &FeatureDefs, CHAR_DESC CharDesc)
Definition: featdefs.cpp:219
void FreeCharDescription(CHAR_DESC CharDesc)
Definition: featdefs.cpp:141
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:41
CHAR_DESC ExtractBlobFeatures(const FEATURE_DEFS_STRUCT &FeatureDefs, const DENORM &denorm, TBLOB *Blob)
Definition: extract.cpp:51
void cprintf(const char *format,...)
Definition: callcpp.cpp:41
#define ASSERT_HOST(x)
Definition: errcode.h:84
void WriteCharDescription(const FEATURE_DEFS_STRUCT &FeatureDefs, FILE *File, CHAR_DESC CharDesc)
Definition: featdefs.cpp:200