tesseract  3.03
/usr/local/google/home/jbreiden/tesseract-ocr-read-only/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     if (i < PreTrainedTemplates->NumClasses) {
00073       int norm_adjust = static_cast<int>(INT_CHAR_NORM_RANGE *
00074         ComputeNormMatch(i, norm_feature, FALSE));
00075       char_norm_array[i] = ClipToRange(norm_adjust, 0, MAX_INT_CHAR_NORM);
00076     } else {
00077       // Classes with no templates (eg. ambigs & ligatures) default
00078       // to worst match.
00079       char_norm_array[i] = MAX_INT_CHAR_NORM;
00080     }
00081   }
00082 }                                /* ComputeIntCharNormArray */
00083 
00084 
00085 /*---------------------------------------------------------------------------*/
00100 void Classify::ComputeIntFeatures(FEATURE_SET Features,
00101                                   INT_FEATURE_ARRAY IntFeatures) {
00102   int Fid;
00103   FEATURE Feature;
00104   FLOAT32 YShift;
00105 
00106   if (classify_norm_method == baseline)
00107     YShift = BASELINE_Y_SHIFT;
00108   else
00109     YShift = Y_SHIFT;
00110 
00111   for (Fid = 0; Fid < Features->NumFeatures; Fid++) {
00112     Feature = Features->Features[Fid];
00113 
00114     IntFeatures[Fid].X = BucketFor (Feature->Params[PicoFeatX],
00115       X_SHIFT, INT_FEAT_RANGE);
00116     IntFeatures[Fid].Y = BucketFor (Feature->Params[PicoFeatY],
00117       YShift, INT_FEAT_RANGE);
00118     IntFeatures[Fid].Theta = CircBucketFor (Feature->Params[PicoFeatDir],
00119       ANGLE_SHIFT, INT_FEAT_RANGE);
00120     IntFeatures[Fid].CP_misses = 0;
00121   }
00122 }                                /* ComputeIntFeatures */
00123 }  // namespace tesseract
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines