tesseract 3.04.01

tesseract::ImageData Class Reference

#include <imagedata.h>

List of all members.

Public Member Functions

 ImageData ()
 ImageData (bool vertical, Pix *pix)
 ~ImageData ()
bool Serialize (TFile *fp) const
bool DeSerialize (bool swap, TFile *fp)
const STRINGimagefilename () const
void set_imagefilename (const STRING &name)
int page_number () const
void set_page_number (int num)
const GenericVector< char > & image_data () const
const STRINGlanguage () const
void set_language (const STRING &lang)
const STRINGtranscription () const
const GenericVector< TBOX > & boxes () const
const GenericVector< STRING > & box_texts () const
const STRINGbox_text (int index) const
void SetPix (Pix *pix)
Pix * GetPix () const
float PreScale (int target_height, Pix **pix, int *scaled_width, int *scaled_height, GenericVector< TBOX > *boxes) const
int MemoryUsed () const
void Display () const
void AddBoxes (const GenericVector< TBOX > &boxes, const GenericVector< STRING > &texts, const GenericVector< int > &box_pages)

Static Public Member Functions

static ImageDataBuild (const char *name, int page_number, const char *lang, const char *imagedata, int imagedatasize, const char *truth_text, const char *box_text)

Detailed Description

Definition at line 88 of file imagedata.h.


Constructor & Destructor Documentation

tesseract::ImageData::ImageData ( )

Definition at line 113 of file imagedata.cpp.

tesseract::ImageData::ImageData ( bool  vertical,
Pix *  pix 
)

Definition at line 116 of file imagedata.cpp.

  : page_number_(0), vertical_text_(vertical) {
  SetPix(pix);
}
ImageData::~ImageData() {
tesseract::ImageData::~ImageData ( )

Definition at line 120 of file imagedata.cpp.


Member Function Documentation

void tesseract::ImageData::AddBoxes ( const GenericVector< TBOX > &  boxes,
const GenericVector< STRING > &  texts,
const GenericVector< int > &  box_pages 
)

Definition at line 290 of file imagedata.cpp.

                                                              {
  // Copy the boxes and make the transcription.
  for (int i = 0; i < box_pages.size(); ++i) {
    if (page_number_ >= 0 && box_pages[i] != page_number_) continue;
    transcription_ += texts[i];
    boxes_.push_back(boxes[i]);
    box_texts_.push_back(texts[i]);
  }
}

const STRING& tesseract::ImageData::box_text ( int  index) const [inline]

Definition at line 138 of file imagedata.h.

                                          {
    return box_texts_[index];
  }
const GenericVector<STRING>& tesseract::ImageData::box_texts ( ) const [inline]

Definition at line 135 of file imagedata.h.

                                                 {
    return box_texts_;
  }
const GenericVector<TBOX>& tesseract::ImageData::boxes ( ) const [inline]

Definition at line 132 of file imagedata.h.

                                           {
    return boxes_;
  }
ImageData * tesseract::ImageData::Build ( const char *  name,
int  page_number,
const char *  lang,
const char *  imagedata,
int  imagedatasize,
const char *  truth_text,
const char *  box_text 
) [static]

Definition at line 125 of file imagedata.cpp.

                                                                          {
  ImageData* image_data = new ImageData();
  image_data->imagefilename_ = name;
  image_data->page_number_ = page_number;
  image_data->language_ = lang;
  // Save the imagedata.
  image_data->image_data_.init_to_size(imagedatasize, 0);
  memcpy(&image_data->image_data_[0], imagedata, imagedatasize);
  if (!image_data->AddBoxes(box_text)) {
    if (truth_text == NULL || truth_text[0] == '\0') {
      tprintf("Error: No text corresponding to page %d from image %s!\n",
              page_number, name);
      delete image_data;
      return NULL;
    }
    image_data->transcription_ = truth_text;
    // If we have no boxes, the transcription is in the 0th box_texts_.
    image_data->box_texts_.push_back(truth_text);
    // We will create a box for the whole image on PreScale, to save unpacking
    // the image now.
  } else if (truth_text != NULL && truth_text[0] != '\0' &&
             image_data->transcription_ != truth_text) {
    // Save the truth text as it is present and disagrees with the box text.
    image_data->transcription_ = truth_text;
  }
  return image_data;
}

bool tesseract::ImageData::DeSerialize ( bool  swap,
TFile fp 
)

Definition at line 171 of file imagedata.cpp.

void tesseract::ImageData::Display ( ) const

Definition at line 253 of file imagedata.cpp.

                                          {
    boxes_[b].plot(win);
    win->Text(boxes_[b].left(), height + kTextSize, box_texts_[b].string());
    TBOX scaled(boxes_[b]);
    scaled.scale(256.0 / height);
    scaled.plot(win);
  }
  // The full transcription.
  win->Pen(ScrollView::CYAN);
  win->Text(0, height + kTextSize * 2, transcription_.string());
  // Add the features.
  win->Pen(ScrollView::GREEN);
  win->Update();
  window_wait(win);
#endif
}

Pix * tesseract::ImageData::GetPix ( ) const

Definition at line 192 of file imagedata.cpp.

const GenericVector<char>& tesseract::ImageData::image_data ( ) const [inline]

Definition at line 120 of file imagedata.h.

                                                {
    return image_data_;
  }
const STRING& tesseract::ImageData::imagefilename ( ) const [inline]

Definition at line 108 of file imagedata.h.

                                      {
    return imagefilename_;
  }
const STRING& tesseract::ImageData::language ( ) const [inline]

Definition at line 123 of file imagedata.h.

                                 {
    return language_;
  }
int tesseract::ImageData::MemoryUsed ( ) const

Definition at line 248 of file imagedata.cpp.

int tesseract::ImageData::page_number ( ) const [inline]

Definition at line 114 of file imagedata.h.

                          {
    return page_number_;
  }
float tesseract::ImageData::PreScale ( int  target_height,
Pix **  pix,
int *  scaled_width,
int *  scaled_height,
GenericVector< TBOX > *  boxes 
) const

Definition at line 201 of file imagedata.cpp.

                                                            {
  int input_width = 0;
  int input_height = 0;
  Pix* src_pix = GetPix();
  ASSERT_HOST(src_pix != NULL);
  input_width = pixGetWidth(src_pix);
  input_height = pixGetHeight(src_pix);
  if (target_height == 0)
    target_height = input_height;
  float im_factor = static_cast<float>(target_height) / input_height;
  if (scaled_width != NULL)
    *scaled_width = IntCastRounded(im_factor * input_width);
  if (scaled_height != NULL)
    *scaled_height = target_height;
  if (pix != NULL) {
    // Get the scaled image.
    pixDestroy(pix);
    *pix = pixScale(src_pix, im_factor, im_factor);
    if (*pix == NULL) {
      tprintf("Scaling pix of size %d, %d by factor %g made null pix!!\n",
              input_width, input_height, im_factor);
    }
    if (scaled_width != NULL)
      *scaled_width = pixGetWidth(*pix);
    if (scaled_height != NULL)
      *scaled_height = pixGetHeight(*pix);
  }
  pixDestroy(&src_pix);
  if (boxes != NULL) {
    // Get the boxes.
    boxes->truncate(0);
    for (int b = 0; b < boxes_.size(); ++b) {
      TBOX box = boxes_[b];
      box.scale(im_factor);
      boxes->push_back(box);
    }
    if (boxes->empty()) {
      // Make a single box for the whole image.
      TBOX box(0, 0, im_factor * input_width, target_height);
      boxes->push_back(box);
    }
  }
  return im_factor;
}

bool tesseract::ImageData::Serialize ( TFile fp) const

Definition at line 156 of file imagedata.cpp.

void tesseract::ImageData::set_imagefilename ( const STRING name) [inline]

Definition at line 111 of file imagedata.h.

                                             {
    imagefilename_ = name;
  }
void tesseract::ImageData::set_language ( const STRING lang) [inline]

Definition at line 126 of file imagedata.h.

                                        {
    language_ = lang;
  }
void tesseract::ImageData::set_page_number ( int  num) [inline]

Definition at line 117 of file imagedata.h.

                                {
    page_number_ = num;
  }
void tesseract::ImageData::SetPix ( Pix *  pix)

Definition at line 187 of file imagedata.cpp.

const STRING& tesseract::ImageData::transcription ( ) const [inline]

Definition at line 129 of file imagedata.h.

                                      {
    return transcription_;
  }

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines