tesseract  3.03
TBLOB Struct Reference

#include <blobs.h>

List of all members.

Public Member Functions

 TBLOB ()
 TBLOB (const TBLOB &src)
 ~TBLOB ()
TBLOBoperator= (const TBLOB &src)
TBLOBClassifyNormalizeIfNeeded () const
void CopyFrom (const TBLOB &src)
void Clear ()
void Normalize (const BLOCK *block, const FCOORD *rotation, const DENORM *predecessor, float x_origin, float y_origin, float x_scale, float y_scale, float final_xshift, float final_yshift, bool inverse, Pix *pix)
void Rotate (const FCOORD rotation)
void Move (const ICOORD vec)
void Scale (float factor)
void ComputeBoundingBoxes ()
int NumOutlines () const
TBOX bounding_box () const
const DENORMdenorm () const
void plot (ScrollView *window, ScrollView::Color color, ScrollView::Color child_color)
int BBArea () const
int ComputeMoments (FCOORD *center, FCOORD *second_moments) const
void GetPreciseBoundingBox (TBOX *precise_box) const
void GetEdgeCoords (const TBOX &box, GenericVector< GenericVector< int > > *x_coords, GenericVector< GenericVector< int > > *y_coords) const

Static Public Member Functions

static TBLOBPolygonalCopy (bool allow_detailed_fx, C_BLOB *src)
static TBLOBShallowCopy (const TBLOB &src)

Public Attributes

TESSLINEoutlines

Detailed Description

Definition at line 193 of file blobs.h.


Constructor & Destructor Documentation

TBLOB::TBLOB ( ) [inline]

Definition at line 194 of file blobs.h.

: outlines(NULL) {}
TBLOB::TBLOB ( const TBLOB src) [inline]

Definition at line 195 of file blobs.h.

                          : outlines(NULL) {
    CopyFrom(src);
  }
TBLOB::~TBLOB ( ) [inline]

Definition at line 198 of file blobs.h.

           {
    Clear();
  }

Member Function Documentation

int TBLOB::BBArea ( ) const [inline]

Definition at line 256 of file blobs.h.

                     {
    int total_area = 0;
    for (TESSLINE* outline = outlines; outline != NULL; outline = outline->next)
      total_area += outline->BBArea();
    return total_area;
  }

Definition at line 446 of file blobs.cpp.

                               {
  if (outlines == NULL)
    return TBOX(0, 0, 0, 0);
  TESSLINE *outline = outlines;
  TBOX box = outline->bounding_box();
  for (outline = outline->next; outline != NULL; outline = outline->next) {
    box += outline->bounding_box();
  }
  return box;
}

Definition at line 327 of file blobs.cpp.

                                              {
  TBLOB* rotated_blob = NULL;
  // If necessary, copy the blob and rotate it. The rotation is always
  // +/- 90 degrees, as 180 was already taken care of.
  if (denorm_.block() != NULL &&
      denorm_.block()->classify_rotation().y() != 0.0) {
    TBOX box = bounding_box();
    int x_middle = (box.left() + box.right()) / 2;
    int y_middle = (box.top() + box.bottom()) / 2;
    rotated_blob = new TBLOB(*this);
    const FCOORD& rotation = denorm_.block()->classify_rotation();
    // Move the rotated blob back to the same y-position so that we
    // can still distinguish similar glyphs with differeny y-position.
    float target_y = kBlnBaselineOffset +
        (rotation.y() > 0 ? x_middle - box.left() : box.right() - x_middle);
    rotated_blob->Normalize(NULL, &rotation, &denorm_, x_middle, y_middle,
                            1.0f, 1.0f, 0.0f, target_y,
                            denorm_.inverse(), denorm_.pix());
  }
  return rotated_blob;
}
void TBLOB::Clear ( )

Definition at line 366 of file blobs.cpp.

                  {
  for (TESSLINE* next_outline = NULL; outlines != NULL;
       outlines = next_outline) {
    next_outline = outlines->next;
    delete outlines;
  }
}

Definition at line 426 of file blobs.cpp.

                                 {
  for (TESSLINE* outline = outlines; outline != NULL; outline = outline->next) {
    outline->ComputeBoundingBox();
  }
}
int TBLOB::ComputeMoments ( FCOORD center,
FCOORD second_moments 
) const

Definition at line 469 of file blobs.cpp.

                                                                      {
  // Compute 1st and 2nd moments of the original outline.
  LLSQ accumulator;
  TBOX box = bounding_box();
  // Iterate the outlines, accumulating edges relative the box.botleft().
  CollectEdges(box, NULL, &accumulator, NULL, NULL);
  *center = accumulator.mean_point() + box.botleft();
  // The 2nd moments are just the standard deviation of the point positions.
  double x2nd = sqrt(accumulator.x_variance());
  double y2nd = sqrt(accumulator.y_variance());
  if (x2nd < 1.0) x2nd = 1.0;
  if (y2nd < 1.0) y2nd = 1.0;
  second_moments->set_x(x2nd);
  second_moments->set_y(y2nd);
  return accumulator.count();
}
void TBLOB::CopyFrom ( const TBLOB src)

Definition at line 350 of file blobs.cpp.

                                     {
  Clear();
  TESSLINE* prev_outline = NULL;
  for (TESSLINE* srcline = src.outlines; srcline != NULL;
       srcline = srcline->next) {
    TESSLINE* new_outline = new TESSLINE(*srcline);
    if (outlines == NULL)
      outlines = new_outline;
    else
      prev_outline->next = new_outline;
    prev_outline = new_outline;
  }
  denorm_ = src.denorm_;
}
const DENORM& TBLOB::denorm ( ) const [inline]

Definition at line 247 of file blobs.h.

                               {
    return denorm_;
  }
void TBLOB::GetEdgeCoords ( const TBOX box,
GenericVector< GenericVector< int > > *  x_coords,
GenericVector< GenericVector< int > > *  y_coords 
) const

Definition at line 504 of file blobs.cpp.

                                                                              {
  GenericVector<int> empty;
  x_coords->init_to_size(box.height(), empty);
  y_coords->init_to_size(box.width(), empty);
  CollectEdges(box, NULL, NULL, x_coords, y_coords);
  // Sort the output vectors.
  for (int i = 0; i < x_coords->size(); ++i)
    (*x_coords)[i].sort();
  for (int i = 0; i < y_coords->size(); ++i)
    (*y_coords)[i].sort();
}
void TBLOB::GetPreciseBoundingBox ( TBOX precise_box) const

Definition at line 488 of file blobs.cpp.

                                                         {
  TBOX box = bounding_box();
  *precise_box = TBOX();
  CollectEdges(box, precise_box, NULL, NULL, NULL);
  precise_box->move(box.botleft());
}
void TBLOB::Move ( const ICOORD  vec)

Definition at line 412 of file blobs.cpp.

                                 {
  for (TESSLINE* outline = outlines; outline != NULL; outline = outline->next) {
    outline->Move(vec);
  }
}
void TBLOB::Normalize ( const BLOCK block,
const FCOORD rotation,
const DENORM predecessor,
float  x_origin,
float  y_origin,
float  x_scale,
float  y_scale,
float  final_xshift,
float  final_yshift,
bool  inverse,
Pix *  pix 
)

Definition at line 377 of file blobs.cpp.

                                              {
  denorm_.SetupNormalization(block, rotation, predecessor, x_origin, y_origin,
                             x_scale, y_scale, final_xshift, final_yshift);
  denorm_.set_inverse(inverse);
  denorm_.set_pix(pix);
  // TODO(rays) outline->Normalize is more accurate, but breaks tests due
  // the changes it makes. Reinstate this code with a retraining.
  // The reason this change is troublesome is that it normalizes for the
  // baseline value computed independently at each x-coord. If the baseline
  // is not horizontal, this introduces shear into the normalized blob, which
  // is useful on the rare occasions that the baseline is really curved, but
  // the baselines need to be stabilized the rest of the time.
#if 0
  for (TESSLINE* outline = outlines; outline != NULL; outline = outline->next) {
    outline->Normalize(denorm_);
  }
#else
  denorm_.LocalNormBlob(this);
#endif
}
int TBLOB::NumOutlines ( ) const

Definition at line 433 of file blobs.cpp.

                             {
  int result = 0;
  for (TESSLINE* outline = outlines; outline != NULL; outline = outline->next)
    ++result;
  return result;
}
TBLOB& TBLOB::operator= ( const TBLOB src) [inline]

Definition at line 201 of file blobs.h.

                                     {
    CopyFrom(src);
    return *this;
  }
void TBLOB::plot ( ScrollView window,
ScrollView::Color  color,
ScrollView::Color  child_color 
)

Definition at line 458 of file blobs.cpp.

                                              {
  for (TESSLINE* outline = outlines; outline != NULL; outline = outline->next)
    outline->plot(window, color, child_color);
}
TBLOB * TBLOB::PolygonalCopy ( bool  allow_detailed_fx,
C_BLOB src 
) [static]

Definition at line 308 of file blobs.cpp.

                                                               {
  TBLOB* tblob = new TBLOB;
  ApproximateOutlineList(allow_detailed_fx, src->out_list(), false,
                         &tblob->outlines);
  return tblob;
}
void TBLOB::Rotate ( const FCOORD  rotation)

Definition at line 405 of file blobs.cpp.

                                        {
  for (TESSLINE* outline = outlines; outline != NULL; outline = outline->next) {
    outline->Rotate(rotation);
  }
}
void TBLOB::Scale ( float  factor)

Definition at line 419 of file blobs.cpp.

                              {
  for (TESSLINE* outline = outlines; outline != NULL; outline = outline->next) {
    outline->Scale(factor);
  }
}
TBLOB * TBLOB::ShallowCopy ( const TBLOB src) [static]

Definition at line 316 of file blobs.cpp.

                                          {
  TBLOB* blob = new TBLOB;
  blob->denorm_ = src.denorm_;
  return blob;
}

Member Data Documentation

Definition at line 284 of file blobs.h.


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