All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
float2int.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  ** Filename: float2int.c
3  ** Purpose: Routines for converting float features to int features
4  ** Author: Dan Johnson
5  ** History: Wed Mar 13 07:47:48 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 "float2int.h"
22 #include "normmatch.h"
23 #include "mfoutline.h"
24 #include "classify.h"
25 #include "helpers.h"
26 #include "picofeat.h"
27 
28 #define MAX_INT_CHAR_NORM (INT_CHAR_NORM_RANGE - 1)
29 
30 /*-----------------------------------------------------------------------------
31  Public Code
32 -----------------------------------------------------------------------------*/
33 /*---------------------------------------------------------------------------*/
34 namespace tesseract {
35 
48 void Classify::ClearCharNormArray(uinT8* char_norm_array) {
49  memset(char_norm_array, 0, sizeof(*char_norm_array) * unicharset.size());
50 } /* ClearCharNormArray */
51 
52 
53 /*---------------------------------------------------------------------------*/
70  uinT8* char_norm_array) {
71  for (int i = 0; i < unicharset.size(); i++) {
72  if (i < PreTrainedTemplates->NumClasses) {
73  int norm_adjust = static_cast<int>(INT_CHAR_NORM_RANGE *
74  ComputeNormMatch(i, norm_feature, FALSE));
75  char_norm_array[i] = ClipToRange(norm_adjust, 0, MAX_INT_CHAR_NORM);
76  } else {
77  // Classes with no templates (eg. ambigs & ligatures) default
78  // to worst match.
79  char_norm_array[i] = MAX_INT_CHAR_NORM;
80  }
81  }
82 } /* ComputeIntCharNormArray */
83 
84 
85 /*---------------------------------------------------------------------------*/
101  INT_FEATURE_ARRAY IntFeatures) {
102  int Fid;
103  FEATURE Feature;
104  FLOAT32 YShift;
105 
107  YShift = BASELINE_Y_SHIFT;
108  else
109  YShift = Y_SHIFT;
110 
111  for (Fid = 0; Fid < Features->NumFeatures; Fid++) {
112  Feature = Features->Features[Fid];
113 
114  IntFeatures[Fid].X =
116  IntFeatures[Fid].Y =
117  Bucket8For(Feature->Params[PicoFeatY], YShift, INT_FEAT_RANGE);
118  IntFeatures[Fid].Theta = CircBucketFor(Feature->Params[PicoFeatDir],
120  IntFeatures[Fid].CP_misses = 0;
121  }
122 } /* ComputeIntFeatures */
123 } // namespace tesseract
void ClearCharNormArray(uinT8 *char_norm_array)
Definition: float2int.cpp:48
#define X_SHIFT
Definition: intproto.h:40
#define ANGLE_SHIFT
Definition: intproto.h:39
#define INT_CHAR_NORM_RANGE
Definition: intproto.h:133
float FLOAT32
Definition: host.h:111
uinT8 Bucket8For(FLOAT32 param, FLOAT32 offset, int num_buckets)
Definition: intproto.cpp:441
UNICHARSET unicharset
Definition: ccutil.h:72
#define Y_SHIFT
Definition: intproto.h:41
FEATURE Features[1]
Definition: ocrfeatures.h:72
void ComputeIntCharNormArray(const FEATURE_STRUCT &norm_feature, uinT8 *char_norm_array)
Definition: float2int.cpp:69
T ClipToRange(const T &x, const T &lower_bound, const T &upper_bound)
Definition: helpers.h:115
void ComputeIntFeatures(FEATURE_SET Features, INT_FEATURE_ARRAY IntFeatures)
Definition: float2int.cpp:100
INT_FEATURE_STRUCT INT_FEATURE_ARRAY[MAX_NUM_INT_FEATURES]
Definition: intproto.h:155
uinT8 CircBucketFor(FLOAT32 param, FLOAT32 offset, int num_buckets)
Definition: intproto.cpp:455
#define MAX_INT_CHAR_NORM
Definition: float2int.cpp:28
FLOAT32 Params[1]
Definition: ocrfeatures.h:65
FLOAT32 ComputeNormMatch(CLASS_ID ClassId, const FEATURE_STRUCT &feature, BOOL8 DebugMatch)
Definition: normmatch.cpp:88
#define FALSE
Definition: capi.h:29
#define INT_FEAT_RANGE
Definition: float2int.h:27
int size() const
Definition: unicharset.h:297
#define BASELINE_Y_SHIFT
Definition: float2int.h:28
unsigned char uinT8
Definition: host.h:99