tesseract  4.0.0-1-g2a2b
edgloop.h File Reference
#include "scrollview.h"
#include "params.h"
#include "pdblock.h"
#include "coutln.h"
#include "crakedge.h"

Go to the source code of this file.

Macros

#define BUCKETSIZE   16
 

Functions

void complete_edge (CRACKEDGE *start, C_OUTLINE_IT *outline_it)
 
ScrollView::Color check_path_legal (CRACKEDGE *start)
 
int16_t loop_bounding_box (CRACKEDGE *&start, ICOORD &botleft, ICOORD &topright)
 

Variables

int edges_children_per_grandchild = 10
 
int edges_children_count_limit = 45
 
double edges_childarea = 0.5
 
double edges_boxarea = 0.8
 

Macro Definition Documentation

◆ BUCKETSIZE

#define BUCKETSIZE   16

Definition at line 29 of file edgloop.h.

Function Documentation

◆ check_path_legal()

ScrollView::Color check_path_legal ( CRACKEDGE start)

Definition at line 67 of file edgloop.cpp.

69  {
70  int lastchain; //last chain code
71  int chaindiff; //chain code diff
72  int32_t length; //length of loop
73  int32_t chainsum; //sum of chain diffs
74  CRACKEDGE *edgept; //current point
75  const ERRCODE ED_ILLEGAL_SUM = "Illegal sum of chain codes";
76 
77  length = 0;
78  chainsum = 0; //sum of chain codes
79  edgept = start;
80  lastchain = edgept->prev->stepdir; //previous chain code
81  do {
82  length++;
83  if (edgept->stepdir != lastchain) {
84  //chain code difference
85  chaindiff = edgept->stepdir - lastchain;
86  if (chaindiff > 2)
87  chaindiff -= 4;
88  else if (chaindiff < -2)
89  chaindiff += 4;
90  chainsum += chaindiff; //sum differences
91  lastchain = edgept->stepdir;
92  }
93  edgept = edgept->next;
94  }
95  while (edgept != start && length < C_OUTLINE::kMaxOutlineLength);
96 
97  if ((chainsum != 4 && chainsum != -4)
98  || edgept != start || length < MINEDGELENGTH) {
99  if (edgept != start) {
100  return ScrollView::YELLOW;
101  } else if (length < MINEDGELENGTH) {
102  return ScrollView::MAGENTA;
103  } else {
104  ED_ILLEGAL_SUM.error ("check_path_legal", TESSLOG, "chainsum=%d",
105  chainsum);
106  return ScrollView::GREEN;
107  }
108  }
109  //colour on inside
110  return chainsum < 0 ? ScrollView::BLUE : ScrollView::RED;
111 }
CRACKEDGE * prev
Definition: crakedge.h:34
#define MINEDGELENGTH
Definition: edgloop.cpp:29
int8_t stepdir
Definition: crakedge.h:33
CRACKEDGE * next
Definition: crakedge.h:35
static const int kMaxOutlineLength
Definition: coutln.h:273
void error(const char *caller, TessErrorLogCode action, const char *format,...) const
Definition: errcode.cpp:37

◆ complete_edge()

void complete_edge ( CRACKEDGE start,
C_OUTLINE_IT *  outline_it 
)

Definition at line 37 of file edgloop.cpp.

38  {
39  ScrollView::Color colour; //colour to draw in
40  int16_t looplength; //steps in loop
41  ICOORD botleft; //bounding box
42  ICOORD topright;
43  C_OUTLINE *outline; //new outline
44 
45  //check length etc.
46  colour = check_path_legal (start);
47 
48  if (colour == ScrollView::RED || colour == ScrollView::BLUE) {
49  looplength = loop_bounding_box (start, botleft, topright);
50  outline = new C_OUTLINE (start, botleft, topright, looplength);
51  //add to list
52  outline_it->add_after_then_move (outline);
53  }
54 }
int16_t loop_bounding_box(CRACKEDGE *&start, ICOORD &botleft, ICOORD &topright)
Definition: edgloop.cpp:119
integer coordinate
Definition: points.h:32
class DLLSYM C_OUTLINE
Definition: coutln.h:68
ScrollView::Color check_path_legal(CRACKEDGE *start)
Definition: edgloop.cpp:67

◆ loop_bounding_box()

int16_t loop_bounding_box ( CRACKEDGE *&  start,
ICOORD botleft,
ICOORD topright 
)

Definition at line 119 of file edgloop.cpp.

122  {
123  int16_t length; //length of loop
124  int16_t leftmost; //on top row
125  CRACKEDGE *edgept; //current point
126  CRACKEDGE *realstart; //topleft start
127 
128  edgept = start;
129  realstart = start;
130  botleft = topright = ICOORD (edgept->pos.x (), edgept->pos.y ());
131  leftmost = edgept->pos.x ();
132  length = 0; //coutn length
133  do {
134  edgept = edgept->next;
135  if (edgept->pos.x () < botleft.x ())
136  //get bounding box
137  botleft.set_x (edgept->pos.x ());
138  else if (edgept->pos.x () > topright.x ())
139  topright.set_x (edgept->pos.x ());
140  if (edgept->pos.y () < botleft.y ())
141  //get bounding box
142  botleft.set_y (edgept->pos.y ());
143  else if (edgept->pos.y () > topright.y ()) {
144  realstart = edgept;
145  leftmost = edgept->pos.x ();
146  topright.set_y (edgept->pos.y ());
147  }
148  else if (edgept->pos.y () == topright.y ()
149  && edgept->pos.x () < leftmost) {
150  //leftmost on line
151  leftmost = edgept->pos.x ();
152  realstart = edgept;
153  }
154  length++; //count elements
155  }
156  while (edgept != start);
157  start = realstart; //shift it to topleft
158  return length;
159 }
void set_x(int16_t xin)
rewrite function
Definition: points.h:62
int16_t y() const
access_function
Definition: points.h:57
integer coordinate
Definition: points.h:32
int16_t x() const
access function
Definition: points.h:53
ICOORD pos
Definition: crakedge.h:30
CRACKEDGE * next
Definition: crakedge.h:35
void set_y(int16_t yin)
rewrite function
Definition: points.h:66

Variable Documentation

◆ edges_boxarea

double edges_boxarea = 0.8

"Min area fraction of grandchild for box"

Definition at line 60 of file edgblob.cpp.

◆ edges_childarea

double edges_childarea = 0.5

"Max area fraction of child outline"

"Min area fraction of child outline"

Definition at line 58 of file edgblob.cpp.

◆ edges_children_count_limit

int edges_children_count_limit = 45

"Max holes allowed in blob"

Definition at line 50 of file edgblob.cpp.

◆ edges_children_per_grandchild

int edges_children_per_grandchild = 10

"Importance ratio for chucking outlines"

Definition at line 48 of file edgblob.cpp.