tesseract  4.00.00dev
cutoffs.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  ** Filename: cutoffs.c
3  ** Purpose: Routines to manipulate an array of class cutoffs.
4  ** Author: Dan Johnson
5  ** History: Wed Feb 20 09:28:51 1991, DSJ, Created.
6  **
7  ** (c) Copyright Hewlett-Packard Company, 1988.
8  ** Licensed under the Apache License, Version 2.0 (the "License");
9  ** you may not use this file except in compliance with the License.
10  ** You may obtain a copy of the License at
11  ** http://www.apache.org/licenses/LICENSE-2.0
12  ** Unless required by applicable law or agreed to in writing, software
13  ** distributed under the License is distributed on an "AS IS" BASIS,
14  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  ** See the License for the specific language governing permissions and
16  ** limitations under the License.
17  ******************************************************************************/
18 /*----------------------------------------------------------------------------
19  Include Files and Type Defines
20 ----------------------------------------------------------------------------*/
21 #include "cutoffs.h"
22 
23 #include <stdio.h>
24 
25 #include "classify.h"
26 #include "efio.h"
27 #include "globals.h"
28 #include "helpers.h"
29 #include "scanutils.h"
30 #include "serialis.h"
31 #include "unichar.h"
32 
33 #define REALLY_QUOTE_IT(x) QUOTE_IT(x)
34 
35 #define MAX_CUTOFF 1000
36 
37 namespace tesseract {
53  char Class[UNICHAR_LEN + 1];
54  CLASS_ID ClassId;
55  int Cutoff;
56  int i;
57 
58  if (shape_table_ != NULL) {
59  if (!shapetable_cutoffs_.DeSerialize(fp)) {
60  tprintf("Error during read of shapetable pffmtable!\n");
61  }
62  }
63  for (i = 0; i < MAX_NUM_CLASSES; i++)
64  Cutoffs[i] = MAX_CUTOFF;
65 
66  const int kMaxLineSize = 100;
67  char line[kMaxLineSize];
68  while (fp->FGets(line, kMaxLineSize) != nullptr &&
69  sscanf(line, "%" REALLY_QUOTE_IT(UNICHAR_LEN) "s %d", Class,
70  &Cutoff) == 2) {
71  if (strcmp(Class, "NULL") == 0) {
72  ClassId = unicharset.unichar_to_id(" ");
73  } else {
74  ClassId = unicharset.unichar_to_id(Class);
75  }
76  Cutoffs[ClassId] = Cutoff;
77  }
78 }
79 
80 } // namespace tesseract
bool DeSerialize(bool swap, FILE *fp)
UNICHAR_ID CLASS_ID
Definition: matchdefs.h:35
uinT16 CLASS_CUTOFF_ARRAY[MAX_NUM_CLASSES]
Definition: cutoffs.h:26
#define tprintf(...)
Definition: tprintf.h:31
void ReadNewCutoffs(TFile *fp, CLASS_CUTOFF_ARRAY Cutoffs)
Definition: cutoffs.cpp:52
#define UNICHAR_LEN
Definition: unichar.h:30
ShapeTable * shape_table_
Definition: classify.h:511
UNICHARSET unicharset
Definition: ccutil.h:68
#define MAX_NUM_CLASSES
Definition: matchdefs.h:31
char * FGets(char *buffer, int buffer_size)
Definition: serialis.cpp:86
UNICHAR_ID unichar_to_id(const char *const unichar_repr) const
Definition: unicharset.cpp:194
#define REALLY_QUOTE_IT(x)
Definition: cutoffs.cpp:33
#define MAX_CUTOFF
Definition: cutoffs.cpp:35