Tesseract
3.02
|
00001 /********************************************************************** 00002 * File: alt_list.h 00003 * Description: Class to abstarct a list of alternate results 00004 * Author: Ahmad Abdulkader 00005 * Created: 2007 00006 * 00007 * (C) Copyright 2008, 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 * 00018 **********************************************************************/ 00019 00020 // The AltList class is the base class for the list of alternate recognition 00021 // results. Each alternate has a cost an an optional tag associated with it 00022 00023 #ifndef ALT_LIST_H 00024 #define ALT_LIST_H 00025 00026 #include <math.h> 00027 #include "cube_utils.h" 00028 00029 namespace tesseract { 00030 class AltList { 00031 public: 00032 explicit AltList(int max_alt); 00033 virtual ~AltList(); 00034 // sort the list of alternates based 00035 virtual void Sort() = 0; 00036 // return the best possible cost and index of corresponding alternate 00037 int BestCost (int *best_alt) const; 00038 // return the count of alternates 00039 inline int AltCount() const { return alt_cnt_; } 00040 // returns the cost (-ve log prob) of an alternate 00041 inline int AltCost(int alt_idx) const { return alt_cost_[alt_idx]; } 00042 // returns the prob of an alternate 00043 inline double AltProb(int alt_idx) const { 00044 return CubeUtils::Cost2Prob(AltCost(alt_idx)); 00045 } 00046 // returns the alternate tag 00047 inline void *AltTag(int alt_idx) const { return alt_tag_[alt_idx]; } 00048 00049 protected: 00050 // max number of alternates the list can hold 00051 int max_alt_; 00052 // actual alternate count 00053 int alt_cnt_; 00054 // array of alternate costs 00055 int *alt_cost_; 00056 // array of alternate tags 00057 void **alt_tag_; 00058 }; 00059 } 00060 00061 #endif // ALT_LIST_H