Tesseract  3.02
tesseract::CubeObject Class Reference

#include <cube_object.h>

List of all members.

Public Member Functions

 CubeObject (CubeRecoContext *cntxt, CharSamp *char_samp)
 CubeObject (CubeRecoContext *cntxt, IMAGE *img, int left, int top, int wid, int hgt)
 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 91 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.

                                                                  {
  Init();
  char_samp_ = char_samp;
  cntxt_ = cntxt;
}
tesseract::CubeObject::CubeObject ( CubeRecoContext cntxt,
IMAGE img,
int  left,
int  top,
int  wid,
int  hgt 
)

Definition at line 32 of file cube_object.cpp.

                                                            {
  Init();
  char_samp_ = CubeUtils::CharSampleFromImg(img, left, top, wid, hgt);
  own_char_samp_ = true;
  cntxt_ = cntxt;
}
tesseract::CubeObject::CubeObject ( CubeRecoContext cntxt,
Pix *  pix,
int  left,
int  top,
int  wid,
int  hgt 
)

Definition at line 40 of file cube_object.cpp.

                                                            {
  Init();
  char_samp_ = CubeUtils::CharSampleFromPix(pix, left, top, wid, hgt);
  own_char_samp_ = true;
  cntxt_ = cntxt;
}
tesseract::CubeObject::~CubeObject ( )

Definition at line 76 of file cube_object.cpp.

                        {
  if (char_samp_ != NULL && own_char_samp_ == true) {
    delete char_samp_;
    char_samp_ = NULL;
  }

  if (srch_obj_ != NULL) {
    delete srch_obj_;
    srch_obj_ = NULL;
  }

  if (deslanted_srch_obj_ != NULL) {
    delete deslanted_srch_obj_;
    deslanted_srch_obj_ = NULL;
  }

  if (beam_obj_ != NULL) {
    delete beam_obj_;
    beam_obj_ = NULL;
  }

  if (deslanted_beam_obj_ != NULL) {
    delete deslanted_beam_obj_;
    deslanted_beam_obj_ = NULL;
  }

  if (deslanted_char_samp_ != NULL) {
    delete deslanted_char_samp_;
    deslanted_char_samp_ = NULL;
  }

  Cleanup();
}

Member Function Documentation

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

Definition at line 122 of file cube_object.h.

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

Definition at line 117 of file cube_object.h.

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

Definition at line 133 of file cube_object.h.

                                      {
    return (deslanted_ == true ? deslanted_char_samp_ : char_samp_);
  }
bool tesseract::CubeObject::Normalize ( ) [protected]

Definition at line 256 of file cube_object.cpp.

                           {
  // create a cube search object
  CubeSearchObject *srch_obj = new CubeSearchObject(cntxt_, char_samp_);
  if (srch_obj == NULL) {
    return false;
  }
  // Perform over-segmentation
  int seg_cnt = srch_obj->SegPtCnt();
  // Only perform normalization if segment count is large enough
  if (seg_cnt < kMinNormalizationSegmentCnt) {
    delete srch_obj;
    return true;
  }
  // compute the mean AR of the segments
  double ar_mean = 0.0;
  for (int seg_idx = 0; seg_idx <= seg_cnt; seg_idx++) {
    CharSamp *seg_samp = srch_obj->CharSample(seg_idx - 1, seg_idx);
    if (seg_samp != NULL && seg_samp->Width() > 0) {
      ar_mean += (1.0 * seg_samp->Height() / seg_samp->Width());
    }
  }
  ar_mean /= (seg_cnt + 1);
  // perform normalization if segment AR is too high
  if (ar_mean > kMinNormalizationAspectRatio) {
    // scale down the image in the y-direction to attain AR
    CharSamp *new_samp = char_samp_->Scale(char_samp_->Width(),
                                           2.0 * char_samp_->Height() / ar_mean,
                                           false);
    if (new_samp != NULL) {
      // free existing char samp if owned
      if (own_char_samp_) {
        delete char_samp_;
      }
      // update with new scaled charsamp and set ownership flag
      char_samp_ = new_samp;
      own_char_samp_ = true;
    }
  }
  delete srch_obj;
  return true;
}
CharAltList * tesseract::CubeObject::RecognizeChar ( )

Definition at line 246 of file cube_object.cpp.

                                       {
  if (char_samp_ == NULL) return NULL;
  CharAltList* alt_list = NULL;
  CharClassifier *char_classifier = cntxt_->Classifier();
  ASSERT_HOST(char_classifier != NULL);
  alt_list = char_classifier->Classify(char_samp_);
  return alt_list;
}
WordAltList * tesseract::CubeObject::RecognizePhrase ( LangModel lang_mod = NULL)

Definition at line 214 of file cube_object.cpp.

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

Definition at line 209 of file cube_object.cpp.

                                                          {
  return Recognize(lang_mod, true);
}
void tesseract::CubeObject::SetCharSampOwnership ( bool  own_char_samp) [inline]

Definition at line 138 of file cube_object.h.

                                                       {
    own_char_samp_ = own_char_samp;
  }
CubeSearchObject* tesseract::CubeObject::SrchObj ( ) const [inline]

Definition at line 127 of file cube_object.h.

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

Definition at line 220 of file cube_object.cpp.

                                        {
  WordListLangModel *lang_mod = new WordListLangModel(cntxt_);
  if (lang_mod == NULL) {
    return WORST_COST;
  }

  if (lang_mod->AddString(str) == false) {
    delete lang_mod;
    return WORST_COST;
  }

  // run a beam search against the single string wordlist model
  WordAltList *alt_list = RecognizeWord(lang_mod);
  delete lang_mod;

  int cost = WORST_COST;
  if (alt_list != NULL) {
    if (alt_list->AltCount() > 0) {
      cost = alt_list->AltCost(0);
    }
  }

  return cost;
}

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