tesseract  5.0.0
float2int.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  ** Filename: float2int.cpp
3  ** Purpose: Routines for converting float features to int features
4  ** Author: Dan Johnson
5  **
6  ** (c) Copyright Hewlett-Packard Company, 1988.
7  ** Licensed under the Apache License, Version 2.0 (the "License");
8  ** you may not use this file except in compliance with the License.
9  ** You may obtain a copy of the License at
10  ** http://www.apache.org/licenses/LICENSE-2.0
11  ** Unless required by applicable law or agreed to in writing, software
12  ** distributed under the License is distributed on an "AS IS" BASIS,
13  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  ** See the License for the specific language governing permissions and
15  ** limitations under the License.
16  ******************************************************************************/
17 
18 #include "float2int.h"
19 
20 #include "classify.h"
21 #include "mfoutline.h"
22 #include "normmatch.h"
23 #include "picofeat.h"
24 
25 #include "helpers.h"
26 
27 #define MAX_INT_CHAR_NORM (INT_CHAR_NORM_RANGE - 1)
28 
29 /*---------------------------------------------------------------------------*/
30 namespace tesseract {
31 
41 void Classify::ClearCharNormArray(uint8_t *char_norm_array) {
42  memset(char_norm_array, 0, sizeof(*char_norm_array) * unicharset.size());
43 } /* ClearCharNormArray */
44 
45 /*---------------------------------------------------------------------------*/
59  uint8_t *char_norm_array) {
60  for (unsigned i = 0; i < unicharset.size(); i++) {
61  if (i < PreTrainedTemplates->NumClasses) {
62  int norm_adjust =
63  static_cast<int>(INT_CHAR_NORM_RANGE * ComputeNormMatch(i, norm_feature, false));
64  char_norm_array[i] = ClipToRange(norm_adjust, 0, MAX_INT_CHAR_NORM);
65  } else {
66  // Classes with no templates (eg. ambigs & ligatures) default
67  // to worst match.
68  char_norm_array[i] = MAX_INT_CHAR_NORM;
69  }
70  }
71 } /* ComputeIntCharNormArray */
72 
73 /*---------------------------------------------------------------------------*/
86  float YShift;
87 
88  if (classify_norm_method == baseline) {
89  YShift = BASELINE_Y_SHIFT;
90  } else {
91  YShift = Y_SHIFT;
92  }
93 
94  for (int Fid = 0; Fid < Features->NumFeatures; Fid++) {
95  FEATURE Feature = Features->Features[Fid];
96 
97  IntFeatures[Fid].X = Bucket8For(Feature->Params[PicoFeatX], X_SHIFT, INT_FEAT_RANGE);
98  IntFeatures[Fid].Y = Bucket8For(Feature->Params[PicoFeatY], YShift, INT_FEAT_RANGE);
99  IntFeatures[Fid].Theta =
101  IntFeatures[Fid].CP_misses = 0;
102  }
103 } /* ComputeIntFeatures */
104 
105 } // namespace tesseract
#define MAX_INT_CHAR_NORM
Definition: float2int.cpp:27
#define BASELINE_Y_SHIFT
Definition: float2int.h:28
#define INT_FEAT_RANGE
Definition: float2int.h:27
#define ANGLE_SHIFT
Definition: intproto.h:40
#define INT_CHAR_NORM_RANGE
Definition: intproto.h:117
#define X_SHIFT
Definition: intproto.h:41
#define Y_SHIFT
Definition: intproto.h:42
uint8_t Bucket8For(float param, float offset, int num_buckets)
Definition: intproto.cpp:385
@ PicoFeatDir
Definition: picofeat.h:43
@ PicoFeatX
Definition: picofeat.h:43
@ PicoFeatY
Definition: picofeat.h:43
@ baseline
Definition: mfoutline.h:53
uint8_t CircBucketFor(float param, float offset, int num_buckets)
Definition: intproto.cpp:399
T ClipToRange(const T &x, const T &lower_bound, const T &upper_bound)
Definition: helpers.h:110
INT_FEATURE_STRUCT INT_FEATURE_ARRAY[MAX_NUM_INT_FEATURES]
Definition: intproto.h:137
UNICHARSET unicharset
Definition: ccutil.h:61
size_t size() const
Definition: unicharset.h:355
void ClearCharNormArray(uint8_t *char_norm_array)
Definition: float2int.cpp:41
float ComputeNormMatch(CLASS_ID ClassId, const FEATURE_STRUCT &feature, bool DebugMatch)
Definition: normmatch.cpp:94
void ComputeIntCharNormArray(const FEATURE_STRUCT &norm_feature, uint8_t *char_norm_array)
Definition: float2int.cpp:58
void ComputeIntFeatures(FEATURE_SET Features, INT_FEATURE_ARRAY IntFeatures)
Definition: float2int.cpp:85
std::vector< float > Params
Definition: ocrfeatures.h:66
std::vector< FEATURE_STRUCT * > Features
Definition: ocrfeatures.h:85