Tesseract  3.02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
blobs.h File Reference
#include "clst.h"
#include "rect.h"
#include "vecfuncs.h"

Go to the source code of this file.

Classes

struct  WIDTH_RECORD
 
struct  TPOINT
 
struct  EDGEPT
 
struct  TESSLINE
 
struct  TBLOB
 
struct  TWERD
 

Macros

#define EDGEPTFLAGS   4 /*concavity,length etc. */
 
#define free_widths(w)   if (w) memfree (w)
 

Typedefs

typedef TPOINT VECTOR
 

Functions

 CLISTIZEH (EDGEPT)
 
int count_blobs (TBLOB *blobs)
 
void blob_origin (TBLOB *blob, TPOINT *origin)
 
WIDTH_RECORDblobs_widths (TBLOB *blobs)
 
bool divisible_blob (TBLOB *blob, bool italic_blob, TPOINT *location)
 
void divide_blobs (TBLOB *blob, TBLOB *other_blob, bool italic_blob, const TPOINT &location)
 

Macro Definition Documentation

#define EDGEPTFLAGS   4 /*concavity,length etc. */

Definition at line 45 of file blobs.h.

#define free_widths (   w)    if (w) memfree (w)

Definition at line 287 of file blobs.h.

Typedef Documentation

typedef TPOINT VECTOR

Definition at line 70 of file blobs.h.

Function Documentation

void blob_origin ( TBLOB blob,
TPOINT origin 
)

Definition at line 537 of file blobs.cpp.

538  { /*return value */
539  TBOX bbox = blob->bounding_box();
540  *origin = (bbox.topleft() + bbox.botright()) / 2;
541 }
ICOORD topleft() const
Definition: rect.h:89
Definition: rect.h:29
ICOORD botright() const
Definition: rect.h:85
TBOX bounding_box() const
Definition: blobs.cpp:384
WIDTH_RECORD* blobs_widths ( TBLOB blobs)

Definition at line 549 of file blobs.cpp.

549  { /*blob to compute on */
550  WIDTH_RECORD *width_record;
551  TPOINT topleft; /*bounding box */
552  TPOINT botright;
553  int i = 0;
554  int blob_end;
555  int num_blobs = count_blobs (blobs);
556 
557  /* Get memory */
558  width_record = (WIDTH_RECORD *) memalloc (sizeof (int) * num_blobs * 2);
559  width_record->num_chars = num_blobs;
560 
561  TBOX bbox = blobs->bounding_box();
562  width_record->widths[i++] = bbox.width();
563  /* First width */
564  blob_end = bbox.right();
565 
566  for (TBLOB* blob = blobs->next; blob != NULL; blob = blob->next) {
567  TBOX curbox = blob->bounding_box();
568  width_record->widths[i++] = curbox.left() - blob_end;
569  width_record->widths[i++] = curbox.width();
570  blob_end = curbox.right();
571  }
572  return width_record;
573 }
int * memalloc(int size)
Definition: freelist.cpp:22
#define NULL
Definition: host.h:144
inT16 left() const
Definition: rect.h:67
inT16 width() const
Definition: rect.h:104
Definition: rect.h:29
inT16 right() const
Definition: rect.h:74
int num_chars
Definition: blobs.h:49
Definition: blobs.h:53
Definition: blobs.h:174
int count_blobs(TBLOB *blobs)
Definition: blobs.cpp:581
TBOX bounding_box() const
Definition: blobs.cpp:384
int widths[1]
Definition: blobs.h:50
TBLOB * next
Definition: blobs.h:228
CLISTIZEH ( EDGEPT  )
int count_blobs ( TBLOB blobs)

Definition at line 581 of file blobs.cpp.

581  {
582  int x = 0;
583 
584  for (TBLOB* b = blobs; b != NULL; b = b->next)
585  x++;
586  return x;
587 }
#define NULL
Definition: host.h:144
Definition: blobs.h:174
void divide_blobs ( TBLOB blob,
TBLOB other_blob,
bool  italic_blob,
const TPOINT location 
)

Definition at line 645 of file blobs.cpp.

646  {
647  TPOINT vertical = italic_blob ? kDivisibleVerticalItalic
649  TESSLINE *outline1 = NULL;
650  TESSLINE *outline2 = NULL;
651 
652  TESSLINE *outline = blob->outlines;
653  blob->outlines = NULL;
654  int location_prod = CROSS(location, vertical);
655 
656  while (outline != NULL) {
657  TPOINT mid_pt(
658  static_cast<inT16>((outline->topleft.x + outline->botright.x) / 2),
659  static_cast<inT16>((outline->topleft.y + outline->botright.y) / 2));
660  int mid_prod = CROSS(mid_pt, vertical);
661  if (mid_prod < location_prod) {
662  // Outline is in left blob.
663  if (outline1)
664  outline1->next = outline;
665  else
666  blob->outlines = outline;
667  outline1 = outline;
668  } else {
669  // Outline is in right blob.
670  if (outline2)
671  outline2->next = outline;
672  else
673  other_blob->outlines = outline;
674  outline2 = outline;
675  }
676  outline = outline->next;
677  }
678 
679  if (outline1)
680  outline1->next = NULL;
681  if (outline2)
682  outline2->next = NULL;
683 }
TPOINT topleft
Definition: blobs.h:166
TESSLINE * next
Definition: blobs.h:171
#define NULL
Definition: host.h:144
TESSLINE * outlines
Definition: blobs.h:227
inT16 y
Definition: blobs.h:68
inT16 x
Definition: blobs.h:67
const TPOINT kDivisibleVerticalUpright(0, 1)
Definition: blobs.h:53
const TPOINT kDivisibleVerticalItalic(1, 5)
#define CROSS(a, b)
Definition: vecfuncs.h:54
TPOINT botright
Definition: blobs.h:167
bool divisible_blob ( TBLOB blob,
bool  italic_blob,
TPOINT location 
)

Definition at line 596 of file blobs.cpp.

596  {
597  if (blob->outlines == NULL || blob->outlines->next == NULL)
598  return false; // Need at least 2 outlines for it to be possible.
599  int max_gap = 0;
600  TPOINT vertical = italic_blob ? kDivisibleVerticalItalic
602  for (TESSLINE* outline1 = blob->outlines; outline1 != NULL;
603  outline1 = outline1->next) {
604  if (outline1->is_hole)
605  continue; // Holes do not count as separable.
606  TPOINT mid_pt1(
607  static_cast<inT16>((outline1->topleft.x + outline1->botright.x) / 2),
608  static_cast<inT16>((outline1->topleft.y + outline1->botright.y) / 2));
609  int mid_prod1 = CROSS(mid_pt1, vertical);
610  int min_prod1, max_prod1;
611  outline1->MinMaxCrossProduct(vertical, &min_prod1, &max_prod1);
612  for (TESSLINE* outline2 = outline1->next; outline2 != NULL;
613  outline2 = outline2->next) {
614  if (outline2->is_hole)
615  continue; // Holes do not count as separable.
616  TPOINT mid_pt2(
617  static_cast<inT16>((outline2->topleft.x + outline2->botright.x) / 2),
618  static_cast<inT16>((outline2->topleft.y + outline2->botright.y) / 2));
619  int mid_prod2 = CROSS(mid_pt2, vertical);
620  int min_prod2, max_prod2;
621  outline2->MinMaxCrossProduct(vertical, &min_prod2, &max_prod2);
622  int mid_gap = abs(mid_prod2 - mid_prod1);
623  int overlap = MIN(max_prod1, max_prod2) - MAX(min_prod1, min_prod2);
624  if (mid_gap - overlap / 4 > max_gap) {
625  max_gap = mid_gap - overlap / 4;
626  *location = mid_pt1;
627  *location += mid_pt2;
628  *location /= 2;
629  }
630  }
631  }
632  // Use the y component of the vertical vector as an approximation to its
633  // length.
634  return max_gap > vertical.y;
635 }
TESSLINE * next
Definition: blobs.h:171
#define NULL
Definition: host.h:144
TESSLINE * outlines
Definition: blobs.h:227
inT16 y
Definition: blobs.h:68
const TPOINT kDivisibleVerticalUpright(0, 1)
Definition: blobs.h:53
const TPOINT kDivisibleVerticalItalic(1, 5)
#define CROSS(a, b)
Definition: vecfuncs.h:54
#define MIN(x, y)
Definition: ndminx.h:28
#define MAX(x, y)
Definition: ndminx.h:24