File: blobclass.cpp

package info (click to toggle)
tesseract 2.04-2%2Bsqueeze1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 7,336 kB
  • ctags: 6,860
  • sloc: cpp: 81,388; sh: 3,446; java: 1,220; makefile: 376
file content (123 lines) | stat: -rw-r--r-- 4,457 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/******************************************************************************
 **      Filename:       blobclass.c
 **      Purpose:        High level blob classification and training routines.
 **      Author:         Dan Johnson
 **      History:        7/21/89, DSJ, Created.
 **
 **      (c) Copyright Hewlett-Packard Company, 1988.
 ** Licensed under the Apache License, Version 2.0 (the "License");
 ** you may not use this file except in compliance with the License.
 ** You may obtain a copy of the License at
 ** http://www.apache.org/licenses/LICENSE-2.0
 ** Unless required by applicable law or agreed to in writing, software
 ** distributed under the License is distributed on an "AS IS" BASIS,
 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 ** See the License for the specific language governing permissions and
 ** limitations under the License.
 ******************************************************************************/

/**----------------------------------------------------------------------------
      Include Files and Type Defines
----------------------------------------------------------------------------**/
#include "blobclass.h"
#include "fxdefs.h"
#include "variables.h"
#include "extract.h"
#include "efio.h"
#include "callcpp.h"
#include "chartoname.h"

#include <math.h>
#include <stdio.h>
#include <signal.h>

#define MAXFILENAME             80
#define MAXMATCHES              10

// define default font name to be used in training
#define FONT_NAME       "UnknownFont"

/**----------------------------------------------------------------------------
        Global Data Definitions and Declarations
----------------------------------------------------------------------------**/
/* name of current image file being processed */
extern char imagefile[];

/* parameters used to control the training process */
static const char *FontName = FONT_NAME;

/**----------------------------------------------------------------------------
            Public Code
----------------------------------------------------------------------------**/
/*---------------------------------------------------------------------------*/
void InitBlobClassifierVars() {
/*
 **      Parameters: none
 **      Globals:
 **              FontName        name of font being trained on
 **      Operation: Install blob classifier variables into the wiseowl
 **              variable system.
 **      Return: none
 **      Exceptions: none
 **      History: Fri Jan 19 16:13:33 1990, DSJ, Created.
 */
  VALUE dummy;

  string_variable (FontName, "FontName", FONT_NAME);

}                                /* InitBlobClassifierVars */


/*---------------------------------------------------------------------------*/
void
LearnBlob (TBLOB * Blob, TEXTROW * Row, char BlobText[])
/*
 **      Parameters:
 **              Blob            blob whose micro-features are to be learned
 **              Row             row of text that blob came from
 **              BlobText        text that corresponds to blob
 **              TextLength      number of characters in blob
 **      Globals:
 **              imagefile       base filename of the page being learned
 **              FontName        name of font currently being trained on
 **      Operation:
 **              Extract micro-features from the specified blob and append
 **              them to the appropriate file.
 **      Return: none
 **      Exceptions: none
 **      History: 7/28/89, DSJ, Created.
 */
#define MAXFILENAME     80
#define MAXCHARNAME     20
#define MAXFONTNAME     20
#define TRAIN_SUFFIX    ".tr"
{
  static FILE *FeatureFile = NULL;
  char Filename[MAXFILENAME];
  CHAR_DESC CharDesc;
  LINE_STATS LineStats;

  EnterLearnMode;

  GetLineStatsFromRow(Row, &LineStats);

  CharDesc = ExtractBlobFeatures (Blob, &LineStats);

  // if a feature file is not yet open, open it
  // the name of the file is the name of the image plus TRAIN_SUFFIX
  if (FeatureFile == NULL) {
    strcpy(Filename, imagefile);
    strcat(Filename, TRAIN_SUFFIX);
    FeatureFile = Efopen (Filename, "w");

    cprintf ("TRAINING ... Font name = %s.\n", FontName);
  }

  // label the features with a class name and font name
  fprintf (FeatureFile, "\n%s %s ", FontName, BlobText);

  // write micro-features to file and clean up
  WriteCharDescription(FeatureFile, CharDesc);
  FreeCharDescription(CharDesc);

}                                // LearnBlob