All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
tesseract::CubeObject Class Reference

#include <cube_object.h>

Public Member Functions

 CubeObject (CubeRecoContext *cntxt, CharSamp *char_samp)
 
 CubeObject (CubeRecoContext *cntxt, Pix *pix, int left, int top, int wid, int hgt)
 
 ~CubeObject ()
 
WordAltListRecognizeWord (LangModel *lang_mod=NULL)
 
WordAltListRecognizePhrase (LangModel *lang_mod=NULL)
 
int WordCost (const char *str)
 
CharAltListRecognizeChar ()
 
BeamSearchBeamObj () const
 
WordAltListAlternateList () const
 
CubeSearchObjectSrchObj () const
 
CharSampCharSample () const
 
void SetCharSampOwnership (bool own_char_samp)
 

Protected Member Functions

bool Normalize ()
 

Detailed Description

Definition at line 90 of file cube_object.h.

Constructor & Destructor Documentation

tesseract::CubeObject::CubeObject ( CubeRecoContext cntxt,
CharSamp char_samp 
)

Definition at line 26 of file cube_object.cpp.

26  {
27  Init();
28  char_samp_ = char_samp;
29  cntxt_ = cntxt;
30 }
tesseract::CubeObject::CubeObject ( CubeRecoContext cntxt,
Pix *  pix,
int  left,
int  top,
int  wid,
int  hgt 
)

Definition at line 32 of file cube_object.cpp.

33  {
34  Init();
35  char_samp_ = CubeUtils::CharSampleFromPix(pix, left, top, wid, hgt);
36  own_char_samp_ = true;
37  cntxt_ = cntxt;
38 }
static CharSamp * CharSampleFromPix(Pix *pix, int left, int top, int wid, int hgt)
Definition: cube_utils.cpp:104
tesseract::CubeObject::~CubeObject ( )

Definition at line 68 of file cube_object.cpp.

68  {
69  if (char_samp_ != NULL && own_char_samp_ == true) {
70  delete char_samp_;
71  char_samp_ = NULL;
72  }
73 
74  if (srch_obj_ != NULL) {
75  delete srch_obj_;
76  srch_obj_ = NULL;
77  }
78 
79  if (deslanted_srch_obj_ != NULL) {
80  delete deslanted_srch_obj_;
81  deslanted_srch_obj_ = NULL;
82  }
83 
84  if (beam_obj_ != NULL) {
85  delete beam_obj_;
86  beam_obj_ = NULL;
87  }
88 
89  if (deslanted_beam_obj_ != NULL) {
90  delete deslanted_beam_obj_;
91  deslanted_beam_obj_ = NULL;
92  }
93 
94  if (deslanted_char_samp_ != NULL) {
95  delete deslanted_char_samp_;
96  deslanted_char_samp_ = NULL;
97  }
98 
99  Cleanup();
100 }
#define NULL
Definition: host.h:144

Member Function Documentation

WordAltList* tesseract::CubeObject::AlternateList ( ) const
inline

Definition at line 119 of file cube_object.h.

119  {
120  return (deslanted_ == true ? deslanted_alt_list_ : alt_list_);
121  }
BeamSearch* tesseract::CubeObject::BeamObj ( ) const
inline

Definition at line 114 of file cube_object.h.

114  {
115  return (deslanted_ == true ? deslanted_beam_obj_ : beam_obj_);
116  }
CharSamp* tesseract::CubeObject::CharSample ( ) const
inline

Definition at line 130 of file cube_object.h.

130  {
131  return (deslanted_ == true ? deslanted_char_samp_ : char_samp_);
132  }
bool tesseract::CubeObject::Normalize ( )
protected

Definition at line 256 of file cube_object.cpp.

256  {
257  // create a cube search object
258  CubeSearchObject *srch_obj = new CubeSearchObject(cntxt_, char_samp_);
259  if (srch_obj == NULL) {
260  return false;
261  }
262  // Perform over-segmentation
263  int seg_cnt = srch_obj->SegPtCnt();
264  // Only perform normalization if segment count is large enough
265  if (seg_cnt < kMinNormalizationSegmentCnt) {
266  delete srch_obj;
267  return true;
268  }
269  // compute the mean AR of the segments
270  double ar_mean = 0.0;
271  for (int seg_idx = 0; seg_idx <= seg_cnt; seg_idx++) {
272  CharSamp *seg_samp = srch_obj->CharSample(seg_idx - 1, seg_idx);
273  if (seg_samp != NULL && seg_samp->Width() > 0) {
274  ar_mean += (1.0 * seg_samp->Height() / seg_samp->Width());
275  }
276  }
277  ar_mean /= (seg_cnt + 1);
278  // perform normalization if segment AR is too high
279  if (ar_mean > kMinNormalizationAspectRatio) {
280  // scale down the image in the y-direction to attain AR
281  CharSamp *new_samp = char_samp_->Scale(char_samp_->Width(),
282  2.0 * char_samp_->Height() / ar_mean,
283  false);
284  if (new_samp != NULL) {
285  // free existing char samp if owned
286  if (own_char_samp_) {
287  delete char_samp_;
288  }
289  // update with new scaled charsamp and set ownership flag
290  char_samp_ = new_samp;
291  own_char_samp_ = true;
292  }
293  }
294  delete srch_obj;
295  return true;
296 }
unsigned short Width() const
Definition: bmp_8.h:48
CharSamp * Scale(int wid, int hgt, bool isotropic=true)
Definition: char_samp.cpp:251
unsigned short Height() const
Definition: bmp_8.h:50
#define NULL
Definition: host.h:144
CharAltList * tesseract::CubeObject::RecognizeChar ( )

Definition at line 246 of file cube_object.cpp.

246  {
247  if (char_samp_ == NULL) return NULL;
248  CharAltList* alt_list = NULL;
249  CharClassifier *char_classifier = cntxt_->Classifier();
250  ASSERT_HOST(char_classifier != NULL);
251  alt_list = char_classifier->Classify(char_samp_);
252  return alt_list;
253 }
#define ASSERT_HOST(x)
Definition: errcode.h:84
CharClassifier * Classifier() const
#define NULL
Definition: host.h:144
WordAltList * tesseract::CubeObject::RecognizePhrase ( LangModel lang_mod = NULL)

Recognize the member char sample as a phrase

Definition at line 212 of file cube_object.cpp.

212  {
213  return Recognize(lang_mod, false);
214 }
WordAltList * tesseract::CubeObject::RecognizeWord ( LangModel lang_mod = NULL)

Recognize the member char sample as a word

Definition at line 205 of file cube_object.cpp.

205  {
206  return Recognize(lang_mod, true);
207 }
void tesseract::CubeObject::SetCharSampOwnership ( bool  own_char_samp)
inline

Definition at line 135 of file cube_object.h.

135  {
136  own_char_samp_ = own_char_samp;
137  }
CubeSearchObject* tesseract::CubeObject::SrchObj ( ) const
inline

Definition at line 124 of file cube_object.h.

124  {
125  return (deslanted_ == true ? deslanted_srch_obj_ : srch_obj_);
126  }
int tesseract::CubeObject::WordCost ( const char *  str)

Computes the cost of a specific string. This is done by performing recognition of a language model that allows only the specified word

Definition at line 220 of file cube_object.cpp.

220  {
221  WordListLangModel *lang_mod = new WordListLangModel(cntxt_);
222  if (lang_mod == NULL) {
223  return WORST_COST;
224  }
225 
226  if (lang_mod->AddString(str) == false) {
227  delete lang_mod;
228  return WORST_COST;
229  }
230 
231  // run a beam search against the single string wordlist model
232  WordAltList *alt_list = RecognizeWord(lang_mod);
233  delete lang_mod;
234 
235  int cost = WORST_COST;
236  if (alt_list != NULL) {
237  if (alt_list->AltCount() > 0) {
238  cost = alt_list->AltCost(0);
239  }
240  }
241 
242  return cost;
243 }
#define WORST_COST
Definition: cube_const.h:30
WordAltList * RecognizeWord(LangModel *lang_mod=NULL)
#define NULL
Definition: host.h:144

The documentation for this class was generated from the following files: