tesseract  4.0.0-1-g2a2b
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 Files and Type Defines
19 -----------------------------------------------------------------------------*/
20 #include "float2int.h"
21 #include "normmatch.h"
22 #include "mfoutline.h"
23 #include "classify.h"
24 #include "helpers.h"
25 #include "picofeat.h"
26 
27 #define MAX_INT_CHAR_NORM (INT_CHAR_NORM_RANGE - 1)
28 
29 /*-----------------------------------------------------------------------------
30  Public Code
31 -----------------------------------------------------------------------------*/
32 /*---------------------------------------------------------------------------*/
33 namespace tesseract {
34 
44 void Classify::ClearCharNormArray(uint8_t* char_norm_array) {
45  memset(char_norm_array, 0, sizeof(*char_norm_array) * unicharset.size());
46 } /* ClearCharNormArray */
47 
48 
49 /*---------------------------------------------------------------------------*/
63  uint8_t* char_norm_array) {
64  for (int i = 0; i < unicharset.size(); i++) {
65  if (i < PreTrainedTemplates->NumClasses) {
66  int norm_adjust = static_cast<int>(INT_CHAR_NORM_RANGE *
67  ComputeNormMatch(i, norm_feature, false));
68  char_norm_array[i] = ClipToRange(norm_adjust, 0, MAX_INT_CHAR_NORM);
69  } else {
70  // Classes with no templates (eg. ambigs & ligatures) default
71  // to worst match.
72  char_norm_array[i] = MAX_INT_CHAR_NORM;
73  }
74  }
75 } /* ComputeIntCharNormArray */
76 
77 
78 /*---------------------------------------------------------------------------*/
91  INT_FEATURE_ARRAY IntFeatures) {
92  float YShift;
93 
95  YShift = BASELINE_Y_SHIFT;
96  else
97  YShift = Y_SHIFT;
98 
99  for (int Fid = 0; Fid < Features->NumFeatures; Fid++) {
100  FEATURE Feature = Features->Features[Fid];
101 
102  IntFeatures[Fid].X =
104  IntFeatures[Fid].Y =
105  Bucket8For(Feature->Params[PicoFeatY], YShift, INT_FEAT_RANGE);
106  IntFeatures[Fid].Theta = CircBucketFor(Feature->Params[PicoFeatDir],
108  IntFeatures[Fid].CP_misses = 0;
109  }
110 } /* ComputeIntFeatures */
111 } // namespace tesseract
float ComputeNormMatch(CLASS_ID ClassId, const FEATURE_STRUCT &feature, bool DebugMatch)
Definition: normmatch.cpp:83
void ComputeIntFeatures(FEATURE_SET Features, INT_FEATURE_ARRAY IntFeatures)
Definition: float2int.cpp:90
uint8_t CircBucketFor(float param, float offset, int num_buckets)
Definition: intproto.cpp:435
#define BASELINE_Y_SHIFT
Definition: float2int.h:28
#define INT_CHAR_NORM_RANGE
Definition: intproto.h:130
void ClearCharNormArray(uint8_t *char_norm_array)
Definition: float2int.cpp:44
#define Y_SHIFT
Definition: intproto.h:42
float Params[1]
Definition: ocrfeatures.h:62
int size() const
Definition: unicharset.h:336
FEATURE Features[1]
Definition: ocrfeatures.h:69
UNICHARSET unicharset
Definition: ccutil.h:68
uint16_t NumFeatures
Definition: ocrfeatures.h:67
#define MAX_INT_CHAR_NORM
Definition: float2int.cpp:27
#define ANGLE_SHIFT
Definition: intproto.h:40
INT_FEATURE_STRUCT INT_FEATURE_ARRAY[MAX_NUM_INT_FEATURES]
Definition: intproto.h:150
uint8_t Bucket8For(float param, float offset, int num_buckets)
Definition: intproto.cpp:421
#define X_SHIFT
Definition: intproto.h:41
void ComputeIntCharNormArray(const FEATURE_STRUCT &norm_feature, uint8_t *char_norm_array)
Definition: float2int.cpp:62
T ClipToRange(const T &x, const T &lower_bound, const T &upper_bound)
Definition: helpers.h:111
#define INT_FEAT_RANGE
Definition: float2int.h:27