tesseract  5.0.0-alpha-619-ge9db
blobs.cpp File Reference
#include "blobs.h"
#include "ccstruct.h"
#include "clst.h"
#include <tesseract/helpers.h>
#include "linlsq.h"
#include "normalis.h"
#include "ocrblock.h"
#include "ocrrow.h"
#include "points.h"
#include "polyaprx.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 958 of file blobs.cpp.

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

◆ divisible_blob()

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

Definition at line 910 of file blobs.cpp.

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

Variable Documentation

◆ kDivisibleVerticalItalic

const TPOINT kDivisibleVerticalItalic(1, 5)

◆ kDivisibleVerticalUpright

const TPOINT kDivisibleVerticalUpright(0, 1)
kDivisibleVerticalItalic
const TPOINT kDivisibleVerticalItalic(1, 5)
TESSLINE::botright
TPOINT botright
Definition: blobs.h:275
TPOINT
Definition: blobs.h:49
TBLOB::outlines
TESSLINE * outlines
Definition: blobs.h:398
TESSLINE
Definition: blobs.h:201
TESSLINE::topleft
TPOINT topleft
Definition: blobs.h:274
TESSLINE::next
TESSLINE * next
Definition: blobs.h:279
TPOINT::x
int16_t x
Definition: blobs.h:91
TPOINT::y
int16_t y
Definition: blobs.h:92
kDivisibleVerticalUpright
const TPOINT kDivisibleVerticalUpright(0, 1)
TPOINT::cross
int cross(const TPOINT &other) const
Definition: blobs.h:77