tesseract 4.1.1
Loading...
Searching...
No Matches
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/*---------------------------------------------------------------------------*/
33namespace tesseract {
34
44void 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
T ClipToRange(const T &x, const T &lower_bound, const T &upper_bound)
Definition: helpers.h:108
#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
uint8_t Bucket8For(float param, float offset, int num_buckets)
Definition: intproto.cpp:418
uint8_t CircBucketFor(float param, float offset, int num_buckets)
Definition: intproto.cpp:432
#define ANGLE_SHIFT
Definition: intproto.h:40
INT_FEATURE_STRUCT INT_FEATURE_ARRAY[MAX_NUM_INT_FEATURES]
Definition: intproto.h:152
#define INT_CHAR_NORM_RANGE
Definition: intproto.h:130
#define X_SHIFT
Definition: intproto.h:41
#define Y_SHIFT
Definition: intproto.h:42
@ baseline
Definition: mfoutline.h:63
@ PicoFeatY
Definition: picofeat.h:44
@ PicoFeatDir
Definition: picofeat.h:44
@ PicoFeatX
Definition: picofeat.h:44
UNICHARSET unicharset
Definition: ccutil.h:73
int size() const
Definition: unicharset.h:341
void ClearCharNormArray(uint8_t *char_norm_array)
Definition: float2int.cpp:44
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:62
void ComputeIntFeatures(FEATURE_SET Features, INT_FEATURE_ARRAY IntFeatures)
Definition: float2int.cpp:90
float Params[1]
Definition: ocrfeatures.h:61
FEATURE Features[1]
Definition: ocrfeatures.h:68
uint16_t NumFeatures
Definition: ocrfeatures.h:66