Tesseract  3.02
tesseract-ocr/ccstruct/blobbox.cpp File Reference
#include "mfcpch.h"
#include "blobbox.h"
#include "helpers.h"

Go to the source code of this file.

Defines

#define PROJECTION_MARGIN   10
#define EXTERN

Functions

 ELISTIZE (BLOBNBOX) ELIST2IZE(TO_ROW) ELISTIZE(TO_BLOCK) const double kCosSmallAngle=0.866
void find_cblob_limits (C_BLOB *blob, float leftx, float rightx, FCOORD rotation, float &ymin, float &ymax)
void find_cblob_vlimits (C_BLOB *blob, float leftx, float rightx, float &ymin, float &ymax)
void find_cblob_hlimits (C_BLOB *blob, float bottomy, float topy, float &xmin, float &xmax)
C_BLOBcrotate_cblob (C_BLOB *blob, FCOORD rotation)
TBOX box_next (BLOBNBOX_IT *it)
TBOX box_next_pre_chopped (BLOBNBOX_IT *it)
void vertical_cblob_projection (C_BLOB *blob, STATS *stats)
void vertical_coutline_projection (C_OUTLINE *outline, STATS *stats)
void plot_blob_list (ScrollView *win, BLOBNBOX_LIST *list, ScrollView::Color body_colour, ScrollView::Color child_colour)

Variables

const double kDefiniteAspectRatio = 2.0
const double kComplexShapePerimeterRatio = 1.5
const double kMinMediumSizeRatio = 0.25
const double kMaxMediumSizeRatio = 4.0

Define Documentation

#define EXTERN

Definition at line 25 of file blobbox.cpp.

#define PROJECTION_MARGIN   10

Definition at line 24 of file blobbox.cpp.


Function Documentation

TBOX box_next ( BLOBNBOX_IT *  it)

Definition at line 573 of file blobbox.cpp.

              {
  BLOBNBOX *blob;                //current blob
  TBOX result;                    //total box

  blob = it->data ();
  result = blob->bounding_box ();
  do {
    it->forward ();
    blob = it->data ();
    if (blob->cblob() == NULL)
                                 //was pre-chopped
      result += blob->bounding_box ();
  }
                                 //until next real blob
  while ((blob->cblob() == NULL) || blob->joined_to_prev());
  return result;
}
TBOX box_next_pre_chopped ( BLOBNBOX_IT *  it)

Definition at line 602 of file blobbox.cpp.

                          {
  BLOBNBOX *blob;                //current blob
  TBOX result;                    //total box

  blob = it->data ();
  result = blob->bounding_box ();
  do {
    it->forward ();
    blob = it->data ();
  }
                                 //until next real blob
  while (blob->joined_to_prev ());
  return result;
}
C_BLOB* crotate_cblob ( C_BLOB blob,
FCOORD  rotation 
)

Definition at line 548 of file blobbox.cpp.

                       {
  C_OUTLINE_LIST out_list;       //output outlines
                                 //input outlines
  C_OUTLINE_IT in_it = blob->out_list ();
                                 //output outlines
  C_OUTLINE_IT out_it = &out_list;

  for (in_it.mark_cycle_pt (); !in_it.cycled_list (); in_it.forward ()) {
    out_it.add_after_then_move (new C_OUTLINE (in_it.data (), rotation));
  }
  return new C_BLOB (&out_list);
}
ELISTIZE ( BLOBNBOX  ) const [pure virtual]
void find_cblob_hlimits ( C_BLOB blob,
float  bottomy,
float  topy,
float &  xmin,
float &  xmax 
)

Definition at line 513 of file blobbox.cpp.

                                     {
  inT16 stepindex;               //current point
  ICOORD pos;                    //current coords
  ICOORD vec;                    //rotated step
  C_OUTLINE *outline;            //current outline
                                 //outlines
  C_OUTLINE_IT out_it = blob->out_list ();

  xmin = (float) MAX_INT32;
  xmax = (float) -MAX_INT32;
  for (out_it.mark_cycle_pt (); !out_it.cycled_list (); out_it.forward ()) {
    outline = out_it.data ();
    pos = outline->start_pos (); //get coords
    for (stepindex = 0; stepindex < outline->pathlength (); stepindex++) {
                                 //inside
      if (pos.y () >= bottomy && pos.y () <= topy) {
        UpdateRange(pos.x(), &xmin, &xmax);
      }
      vec = outline->step (stepindex);
      pos += vec;                //move to next
    }
  }
}
void find_cblob_limits ( C_BLOB blob,
float  leftx,
float  rightx,
FCOORD  rotation,
float &  ymin,
float &  ymax 
)

Definition at line 436 of file blobbox.cpp.

                                    {
  inT16 stepindex;               //current point
  ICOORD pos;                    //current coords
  ICOORD vec;                    //rotated step
  C_OUTLINE *outline;            //current outline
                                 //outlines
  C_OUTLINE_IT out_it = blob->out_list ();

  ymin = (float) MAX_INT32;
  ymax = (float) -MAX_INT32;
  for (out_it.mark_cycle_pt (); !out_it.cycled_list (); out_it.forward ()) {
    outline = out_it.data ();
    pos = outline->start_pos (); //get coords
    pos.rotate (rotation);
    for (stepindex = 0; stepindex < outline->pathlength (); stepindex++) {
                                 //inside
      if (pos.x () >= leftx && pos.x () <= rightx) {
        UpdateRange(pos.y(), &ymin, &ymax);
      }
      vec = outline->step (stepindex);
      vec.rotate (rotation);
      pos += vec;                //move to next
    }
  }
}
void find_cblob_vlimits ( C_BLOB blob,
float  leftx,
float  rightx,
float &  ymin,
float &  ymax 
)

Definition at line 476 of file blobbox.cpp.

                                     {
  inT16 stepindex;               //current point
  ICOORD pos;                    //current coords
  ICOORD vec;                    //rotated step
  C_OUTLINE *outline;            //current outline
                                 //outlines
  C_OUTLINE_IT out_it = blob->out_list ();

  ymin = (float) MAX_INT32;
  ymax = (float) -MAX_INT32;
  for (out_it.mark_cycle_pt (); !out_it.cycled_list (); out_it.forward ()) {
    outline = out_it.data ();
    pos = outline->start_pos (); //get coords
    for (stepindex = 0; stepindex < outline->pathlength (); stepindex++) {
                                 //inside
      if (pos.x () >= leftx && pos.x () <= rightx) {
        UpdateRange(pos.y(), &ymin, &ymax);
      }
      vec = outline->step (stepindex);
      pos += vec;                //move to next
    }
  }
}
void plot_blob_list ( ScrollView win,
BLOBNBOX_LIST *  list,
ScrollView::Color  body_colour,
ScrollView::Color  child_colour 
)

Definition at line 1002 of file blobbox.cpp.

                                                  {  // colour of child
  BLOBNBOX_IT it = list;
  for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
    it.data()->plot(win, body_colour, child_colour);
  }
}
void vertical_cblob_projection ( C_BLOB blob,
STATS stats 
)

Definition at line 796 of file blobbox.cpp.

                                {
                                 //outlines of blob
  C_OUTLINE_IT out_it = blob->out_list ();

  for (out_it.mark_cycle_pt (); !out_it.cycled_list (); out_it.forward ()) {
    vertical_coutline_projection (out_it.data (), stats);
  }
}
void vertical_coutline_projection ( C_OUTLINE outline,
STATS stats 
)

Definition at line 816 of file blobbox.cpp.

                                   {
  ICOORD pos;                    //current point
  ICOORD step;                   //edge step
  inT32 length;                  //of outline
  inT16 stepindex;               //current step
  C_OUTLINE_IT out_it = outline->child ();

  pos = outline->start_pos ();
  length = outline->pathlength ();
  for (stepindex = 0; stepindex < length; stepindex++) {
    step = outline->step (stepindex);
    if (step.x () > 0) {
     stats->add (pos.x (), -pos.y ());
    } else if (step.x () < 0) {
      stats->add (pos.x () - 1, pos.y ());
    }
    pos += step;
  }

  for (out_it.mark_cycle_pt (); !out_it.cycled_list (); out_it.forward ()) {
    vertical_coutline_projection (out_it.data (), stats);
  }
}

Variable Documentation

const double kComplexShapePerimeterRatio = 1.5

Definition at line 34 of file blobbox.cpp.

const double kDefiniteAspectRatio = 2.0

Definition at line 32 of file blobbox.cpp.

const double kMaxMediumSizeRatio = 4.0

Definition at line 38 of file blobbox.cpp.

const double kMinMediumSizeRatio = 0.25

Definition at line 36 of file blobbox.cpp.