Tesseract  3.02
tesseract-ocr/classify/float2int.cpp
Go to the documentation of this file.
00001 /******************************************************************************
00002  **     Filename:    float2int.c
00003  **     Purpose:     Routines for converting float features to int features
00004  **     Author:      Dan Johnson
00005  **     History:     Wed Mar 13 07:47:48 1991, DSJ, Created.
00006  **
00007  **     (c) Copyright Hewlett-Packard Company, 1988.
00008  ** Licensed under the Apache License, Version 2.0 (the "License");
00009  ** you may not use this file except in compliance with the License.
00010  ** You may obtain a copy of the License at
00011  ** http://www.apache.org/licenses/LICENSE-2.0
00012  ** Unless required by applicable law or agreed to in writing, software
00013  ** distributed under the License is distributed on an "AS IS" BASIS,
00014  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015  ** See the License for the specific language governing permissions and
00016  ** limitations under the License.
00017  ******************************************************************************/
00018 /*-----------------------------------------------------------------------------
00019           Include Files and Type Defines
00020 -----------------------------------------------------------------------------*/
00021 #include "float2int.h"
00022 #include "normmatch.h"
00023 #include "mfoutline.h"
00024 #include "classify.h"
00025 #include "helpers.h"
00026 #include "picofeat.h"
00027 
00028 #define MAX_INT_CHAR_NORM (INT_CHAR_NORM_RANGE - 1)
00029 
00030 /*-----------------------------------------------------------------------------
00031               Public Code
00032 -----------------------------------------------------------------------------*/
00033 /*---------------------------------------------------------------------------*/
00034 namespace tesseract {
00035 
00048 void Classify::ClearCharNormArray(uinT8* char_norm_array) {
00049   memset(char_norm_array, 0, sizeof(*char_norm_array) * unicharset.size());
00050 }                                /* ClearCharNormArray */
00051 
00052 
00053 /*---------------------------------------------------------------------------*/
00069 void Classify::ComputeIntCharNormArray(const FEATURE_STRUCT& norm_feature,
00070                                        uinT8* char_norm_array) {
00071   for (int i = 0; i < unicharset.size(); i++) {
00072     int norm_adjust = static_cast<int>(INT_CHAR_NORM_RANGE *
00073       ComputeNormMatch(i, norm_feature, FALSE));
00074     char_norm_array[i] = ClipToRange(norm_adjust, 0, MAX_INT_CHAR_NORM);
00075   }
00076 }                                /* ComputeIntCharNormArray */
00077 
00078 
00079 /*---------------------------------------------------------------------------*/
00094 void Classify::ComputeIntFeatures(FEATURE_SET Features,
00095                                   INT_FEATURE_ARRAY IntFeatures) {
00096   int Fid;
00097   FEATURE Feature;
00098   FLOAT32 YShift;
00099 
00100   if (classify_norm_method == baseline)
00101     YShift = BASELINE_Y_SHIFT;
00102   else
00103     YShift = Y_SHIFT;
00104 
00105   for (Fid = 0; Fid < Features->NumFeatures; Fid++) {
00106     Feature = Features->Features[Fid];
00107 
00108     IntFeatures[Fid].X = BucketFor (Feature->Params[PicoFeatX],
00109       X_SHIFT, INT_FEAT_RANGE);
00110     IntFeatures[Fid].Y = BucketFor (Feature->Params[PicoFeatY],
00111       YShift, INT_FEAT_RANGE);
00112     IntFeatures[Fid].Theta = CircBucketFor (Feature->Params[PicoFeatDir],
00113       ANGLE_SHIFT, INT_FEAT_RANGE);
00114     IntFeatures[Fid].CP_misses = 0;
00115   }
00116 }                                /* ComputeIntFeatures */
00117 }  // namespace tesseract