Tesseract
3.02
|
00001 00002 // File: params_training_featdef.h 00003 // Description: Feature definitions for params training. 00004 // Author: Rika Antonova 00005 // Created: Mon Nov 28 11:26:42 PDT 2011 00006 // 00007 // (C) Copyright 2011, Google Inc. 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 // 00019 00020 #ifndef TESSERACT_WORDREC_PARAMS_TRAINING_FEATDEF_H_ 00021 #define TESSERACT_WORDREC_PARAMS_TRAINING_FEATDEF_H_ 00022 00023 #include "genericvector.h" 00024 #include "strngs.h" 00025 00026 namespace tesseract { 00027 00028 // Raw features extracted from a single OCR hypothesis. 00029 // The features are non-normalized real-valued quantities with 00030 // unbounded range and unknown distribution. 00031 // Normalization / binarization of these features is done at a later stage. 00032 // Note: when adding new fields to this enum make sure to modify 00033 // kParamsTrainingRawFeatureTypeName enum accordingly. 00034 enum ParamsTrainingRawFeatureType { 00035 // What dictionary (if any) was this hypothesis found in. 00036 // See PermuterType enum in ccstruct/ratngs.h for interpretation. 00037 PTRAIN_RAW_FEATURE_DICT_MATCH_TYPE, // 0 00038 // Boolean indicator of whether this hypothesis is ambiguous to a known 00039 // dictionary word (or a valid number pattern). 00040 PTRAIN_RAW_FEATURE_UNAMBIG_DICT_MATCH, // 1 00041 // Shape cost of the segmentation path for this hypothesis. 00042 PTRAIN_RAW_FEATURE_SHAPE_COST, // 2 00043 // Character ngram probability of the string of unichars of this hypothesis. 00044 PTRAIN_RAW_FEATURE_NGRAM_PROB, // 3 00045 // Number of bad/inconsistent spots in this hypothesis. 00046 PTRAIN_RAW_FEATURE_NUM_BAD_PUNC, // 4 00047 PTRAIN_RAW_FEATURE_NUM_BAD_CASE, // 5 00048 PTRAIN_RAW_FEATURE_NUM_BAD_CHAR_TYPE, // 6 00049 PTRAIN_RAW_FEATURE_NUM_BAD_SPACING, // 7 00050 PTRAIN_RAW_FEATURE_NUM_BAD_SCRIPT, // 8 00051 PTRAIN_RAW_FEATURE_NUM_BAD_FONT, // 9 00052 // Classifier-related features. 00053 PTRAIN_RAW_FEATURE_WORST_CERT, // 10 00054 PTRAIN_RAW_FEATURE_RATING, // 11 00055 // Number of classifier results that came from adapted templates. 00056 PTRAIN_RAW_FEATURE_ADAPTED, // 12 00057 // Features potentially useful for normalization. 00058 PTRAIN_RAW_FEATURE_NUM_UNICHARS, // 13 00059 PTRAIN_RAW_FEATURE_OUTLINE_LEN, // 14 00060 00061 PTRAIN_NUM_RAW_FEATURE_TYPES 00062 }; 00063 00064 static const char * const kParamsTrainingRawFeatureTypeName[] = { 00065 "DICT_MATCH_TYPE", // 0 00066 "UNAMBIG_DICT_MATCH", // 1 00067 "SHAPE_COST", // 2 00068 "NGRAM_PROB", // 3 00069 "NUM_BAD_PUNC", // 4 00070 "NUM_BAD_CASE", // 5 00071 "NUM_BAD_CHAR_TYPE", // 6 00072 "NUM_BAD_SPACING", // 7 00073 "NUM_BAD_SCRIPT", // 8 00074 "NUM_BAD_FONT", // 9 00075 "WORST_CERT", // 10 00076 "RATING", // 11 00077 "ADAPTED", // 12 00078 "NUM_UNICHARS", // 13 00079 "OUTLINE_LEN", // 14 00080 }; 00081 00082 // Entry with features extracted from a single OCR hypothesis for a word. 00083 struct ParamsTrainingHypothesis { 00084 ParamsTrainingHypothesis() { 00085 for (int i = 0; i < PTRAIN_NUM_RAW_FEATURE_TYPES; ++i) features[i] = 0.0; 00086 } 00087 float features[PTRAIN_NUM_RAW_FEATURE_TYPES]; 00088 STRING str; // string corresponding to word hypothesis (for debugging) 00089 }; 00090 00091 // A list of hypotheses explored during one run of segmentation search. 00092 typedef GenericVector<ParamsTrainingHypothesis> ParamsTrainingHypothesisList; 00093 00094 // A bundle that accumulates all of the hypothesis lists explored during all 00095 // of the runs of segmentation search on a word (e.g. a list of hypotheses 00096 // explored on PASS1, PASS2, fix xheight pass, etc). 00097 class ParamsTrainingBundle { 00098 public: 00099 ParamsTrainingBundle() {}; 00100 // Starts a new hypothesis list. 00101 // Should be called at the beginning of a new run of the segmentation search. 00102 void StartHypothesisList() { 00103 hyp_list_vec.push_back(ParamsTrainingHypothesisList()); 00104 } 00105 // Adds a new ParamsTrainingHypothesis to the current hypothesis list 00106 // and returns the reference to the newly added entry. 00107 ParamsTrainingHypothesis &AddHypothesis() { 00108 if (hyp_list_vec.empty()) StartHypothesisList(); 00109 hyp_list_vec.back().push_back(ParamsTrainingHypothesis()); 00110 return hyp_list_vec.back().back(); 00111 } 00112 00113 GenericVector<ParamsTrainingHypothesisList> hyp_list_vec; 00114 }; 00115 00116 } // namespace tesseract 00117 00118 #endif // TESSERACT_WORDREC_PARAMS_TRAINING_FEATDEF_H_