tesseract  4.0.0-1-g2a2b
blobs.cpp File Reference
#include "blobs.h"
#include "ccstruct.h"
#include "clst.h"
#include "emalloc.h"
#include "helpers.h"
#include "linlsq.h"
#include "normalis.h"
#include "ocrblock.h"
#include "ocrrow.h"
#include "points.h"
#include "polyaprx.h"
#include "structures.h"
#include "werd.h"
#include <algorithm>

Go to the source code of this file.

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)
 

Variables

const TPOINT kDivisibleVerticalUpright (0, 1)
 
const TPOINT kDivisibleVerticalItalic (1, 5)
 

Function Documentation

◆ divide_blobs()

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

Definition at line 972 of file blobs.cpp.

973  {
974  TPOINT vertical =
976  TESSLINE* outline1 = nullptr;
977  TESSLINE* outline2 = nullptr;
978 
979  TESSLINE* outline = blob->outlines;
980  blob->outlines = nullptr;
981  int location_prod = CROSS(location, vertical);
982 
983  while (outline != nullptr) {
984  TPOINT mid_pt(
985  static_cast<int16_t>((outline->topleft.x + outline->botright.x) / 2),
986  static_cast<int16_t>((outline->topleft.y + outline->botright.y) / 2));
987  int mid_prod = CROSS(mid_pt, vertical);
988  if (mid_prod < location_prod) {
989  // Outline is in left blob.
990  if (outline1)
991  outline1->next = outline;
992  else
993  blob->outlines = outline;
994  outline1 = outline;
995  } else {
996  // Outline is in right blob.
997  if (outline2)
998  outline2->next = outline;
999  else
1000  other_blob->outlines = outline;
1001  outline2 = outline;
1002  }
1003  outline = outline->next;
1004  }
1005 
1006  if (outline1) outline1->next = nullptr;
1007  if (outline2) outline2->next = nullptr;
1008 }
TESSLINE * next
Definition: blobs.h:265
TPOINT botright
Definition: blobs.h:261
#define CROSS(a, b)
Definition: vecfuncs.h:52
const TPOINT kDivisibleVerticalUpright(0, 1)
const TPOINT kDivisibleVerticalItalic(1, 5)
int16_t x
Definition: blobs.h:78
Definition: blobs.h:57
int16_t y
Definition: blobs.h:79
TPOINT topleft
Definition: blobs.h:260
TESSLINE * outlines
Definition: blobs.h:384

◆ divisible_blob()

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

Definition at line 923 of file blobs.cpp.

923  {
924  if (blob->outlines == nullptr || blob->outlines->next == nullptr)
925  return false; // Need at least 2 outlines for it to be possible.
926  int max_gap = 0;
927  TPOINT vertical =
929  for (TESSLINE* outline1 = blob->outlines; outline1 != nullptr;
930  outline1 = outline1->next) {
931  if (outline1->is_hole) continue; // Holes do not count as separable.
932  TPOINT mid_pt1(
933  static_cast<int16_t>((outline1->topleft.x + outline1->botright.x) / 2),
934  static_cast<int16_t>((outline1->topleft.y + outline1->botright.y) / 2));
935  int mid_prod1 = CROSS(mid_pt1, vertical);
936  int min_prod1, max_prod1;
937  outline1->MinMaxCrossProduct(vertical, &min_prod1, &max_prod1);
938  for (TESSLINE* outline2 = outline1->next; outline2 != nullptr;
939  outline2 = outline2->next) {
940  if (outline2->is_hole) continue; // Holes do not count as separable.
941  TPOINT mid_pt2(static_cast<int16_t>(
942  (outline2->topleft.x + outline2->botright.x) / 2),
943  static_cast<int16_t>(
944  (outline2->topleft.y + outline2->botright.y) / 2));
945  int mid_prod2 = CROSS(mid_pt2, vertical);
946  int min_prod2, max_prod2;
947  outline2->MinMaxCrossProduct(vertical, &min_prod2, &max_prod2);
948  int mid_gap = abs(mid_prod2 - mid_prod1);
949  int overlap =
950  std::min(max_prod1, max_prod2) - std::max(min_prod1, min_prod2);
951  if (mid_gap - overlap / 4 > max_gap) {
952  max_gap = mid_gap - overlap / 4;
953  *location = mid_pt1;
954  *location += mid_pt2;
955  *location /= 2;
956  }
957  }
958  }
959  // Use the y component of the vertical vector as an approximation to its
960  // length.
961  return max_gap > vertical.y;
962 }
TESSLINE * next
Definition: blobs.h:265
#define CROSS(a, b)
Definition: vecfuncs.h:52
const TPOINT kDivisibleVerticalUpright(0, 1)
const TPOINT kDivisibleVerticalItalic(1, 5)
Definition: blobs.h:57
int16_t y
Definition: blobs.h:79
TESSLINE * outlines
Definition: blobs.h:384

Variable Documentation

◆ kDivisibleVerticalItalic

const TPOINT kDivisibleVerticalItalic(1, 5)

◆ kDivisibleVerticalUpright

const TPOINT kDivisibleVerticalUpright(0, 1)