tesseract  5.0.0-alpha-619-ge9db
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 <tesseract/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
ClipToRange
T ClipToRange(const T &x, const T &lower_bound, const T &upper_bound)
Definition: helpers.h:106
picofeat.h
tesseract::Classify::ClearCharNormArray
void ClearCharNormArray(uint8_t *char_norm_array)
Definition: float2int.cpp:44
MAX_INT_CHAR_NORM
#define MAX_INT_CHAR_NORM
Definition: float2int.cpp:27
tesseract::Classify::classify_norm_method
int classify_norm_method
Definition: classify.h:434
Bucket8For
uint8_t Bucket8For(float param, float offset, int num_buckets)
Definition: intproto.cpp:417
BASELINE_Y_SHIFT
#define BASELINE_Y_SHIFT
Definition: float2int.h:27
baseline
Definition: mfoutline.h:62
INT_FEAT_RANGE
#define INT_FEAT_RANGE
Definition: float2int.h:26
mfoutline.h
tesseract::Classify::ComputeNormMatch
float ComputeNormMatch(CLASS_ID ClassId, const FEATURE_STRUCT &feature, bool DebugMatch)
Definition: normmatch.cpp:93
INT_CHAR_NORM_RANGE
#define INT_CHAR_NORM_RANGE
Definition: intproto.h:129
FEATURE_STRUCT
Definition: ocrfeatures.h:58
PicoFeatY
Definition: picofeat.h:43
CircBucketFor
uint8_t CircBucketFor(float param, float offset, int num_buckets)
Definition: intproto.cpp:431
tesseract::Classify::ComputeIntFeatures
void ComputeIntFeatures(FEATURE_SET Features, INT_FEATURE_ARRAY IntFeatures)
Definition: float2int.cpp:90
PicoFeatX
Definition: picofeat.h:43
tesseract::CCUtil::unicharset
UNICHARSET unicharset
Definition: ccutil.h:57
PicoFeatDir
Definition: picofeat.h:43
Y_SHIFT
#define Y_SHIFT
Definition: intproto.h:41
ANGLE_SHIFT
#define ANGLE_SHIFT
Definition: intproto.h:39
FEATURE_SET_STRUCT::Features
FEATURE Features[1]
Definition: ocrfeatures.h:67
helpers.h
float2int.h
tesseract
Definition: baseapi.h:65
FEATURE_STRUCT::Params
float Params[1]
Definition: ocrfeatures.h:60
normmatch.h
INT_FEATURE_ARRAY
INT_FEATURE_STRUCT INT_FEATURE_ARRAY[MAX_NUM_INT_FEATURES]
Definition: intproto.h:151
FEATURE_SET_STRUCT
Definition: ocrfeatures.h:64
tesseract::Classify::ComputeIntCharNormArray
void ComputeIntCharNormArray(const FEATURE_STRUCT &norm_feature, uint8_t *char_norm_array)
Definition: float2int.cpp:62
X_SHIFT
#define X_SHIFT
Definition: intproto.h:40
classify.h
FEATURE_SET_STRUCT::NumFeatures
uint16_t NumFeatures
Definition: ocrfeatures.h:65
UNICHARSET::size
int size() const
Definition: unicharset.h:341