tesseract  4.1.1
blobs.h File Reference
#include <cstdint>
#include <cstring>
#include "clst.h"
#include "genericvector.h"
#include "normalis.h"
#include "points.h"
#include "publictypes.h"
#include "rect.h"
#include "scrollview.h"

Go to the source code of this file.

Classes

struct  TPOINT
 
struct  EDGEPT
 
struct  TESSLINE
 
struct  TBLOB
 
struct  TWERD
 

Macros

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

Typedefs

using VECTOR = TPOINT
 

Functions

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

◆ EDGEPTFLAGS

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

Definition at line 50 of file blobs.h.

Typedef Documentation

◆ VECTOR

using VECTOR = TPOINT

Definition at line 97 of file blobs.h.

Function Documentation

◆ divide_blobs()

void divide_blobs ( TBLOB blob,
TBLOB other_blob,
bool  italic_blob,
const TPOINT location 
)

Definition at line 962 of file blobs.cpp.

963  {
964  TPOINT vertical =
966  TESSLINE* outline1 = nullptr;
967  TESSLINE* outline2 = nullptr;
968 
969  TESSLINE* outline = blob->outlines;
970  blob->outlines = nullptr;
971  int location_prod = location.cross(vertical);
972 
973  while (outline != nullptr) {
974  TPOINT mid_pt(
975  static_cast<int16_t>((outline->topleft.x + outline->botright.x) / 2),
976  static_cast<int16_t>((outline->topleft.y + outline->botright.y) / 2));
977  int mid_prod = mid_pt.cross(vertical);
978  if (mid_prod < location_prod) {
979  // Outline is in left blob.
980  if (outline1)
981  outline1->next = outline;
982  else
983  blob->outlines = outline;
984  outline1 = outline;
985  } else {
986  // Outline is in right blob.
987  if (outline2)
988  outline2->next = outline;
989  else
990  other_blob->outlines = outline;
991  outline2 = outline;
992  }
993  outline = outline->next;
994  }
995 
996  if (outline1) outline1->next = nullptr;
997  if (outline2) outline2->next = nullptr;
998 }

◆ divisible_blob()

bool divisible_blob ( TBLOB blob,
bool  italic_blob,
TPOINT location 
)

Definition at line 913 of file blobs.cpp.

913  {
914  if (blob->outlines == nullptr || blob->outlines->next == nullptr)
915  return false; // Need at least 2 outlines for it to be possible.
916  int max_gap = 0;
917  TPOINT vertical =
919  for (TESSLINE* outline1 = blob->outlines; outline1 != nullptr;
920  outline1 = outline1->next) {
921  if (outline1->is_hole) continue; // Holes do not count as separable.
922  TPOINT mid_pt1(
923  static_cast<int16_t>((outline1->topleft.x + outline1->botright.x) / 2),
924  static_cast<int16_t>((outline1->topleft.y + outline1->botright.y) / 2));
925  int mid_prod1 = mid_pt1.cross(vertical);
926  int min_prod1, max_prod1;
927  outline1->MinMaxCrossProduct(vertical, &min_prod1, &max_prod1);
928  for (TESSLINE* outline2 = outline1->next; outline2 != nullptr;
929  outline2 = outline2->next) {
930  if (outline2->is_hole) continue; // Holes do not count as separable.
931  TPOINT mid_pt2(static_cast<int16_t>(
932  (outline2->topleft.x + outline2->botright.x) / 2),
933  static_cast<int16_t>(
934  (outline2->topleft.y + outline2->botright.y) / 2));
935  int mid_prod2 = mid_pt2.cross(vertical);
936  int min_prod2, max_prod2;
937  outline2->MinMaxCrossProduct(vertical, &min_prod2, &max_prod2);
938  int mid_gap = abs(mid_prod2 - mid_prod1);
939  int overlap =
940  std::min(max_prod1, max_prod2) - std::max(min_prod1, min_prod2);
941  if (mid_gap - overlap / 4 > max_gap) {
942  max_gap = mid_gap - overlap / 4;
943  *location = mid_pt1;
944  *location += mid_pt2;
945  *location /= 2;
946  }
947  }
948  }
949  // Use the y component of the vertical vector as an approximation to its
950  // length.
951  return max_gap > vertical.y;
952 }
TPOINT::y
int16_t y
Definition: blobs.h:94
TPOINT::cross
int cross(const TPOINT &other) const
Definition: blobs.h:79
kDivisibleVerticalUpright
const TPOINT kDivisibleVerticalUpright(0, 1)
TPOINT
Definition: blobs.h:51
TESSLINE::next
TESSLINE * next
Definition: blobs.h:281
TPOINT::x
int16_t x
Definition: blobs.h:93
TESSLINE::topleft
TPOINT topleft
Definition: blobs.h:276
kDivisibleVerticalItalic
const TPOINT kDivisibleVerticalItalic(1, 5)
TBLOB::outlines
TESSLINE * outlines
Definition: blobs.h:400
TESSLINE::botright
TPOINT botright
Definition: blobs.h:277
TESSLINE
Definition: blobs.h:203