#include <edgblob.h>
See edgblob.cpp
Definition at line 39 of file edgblob.h.
Construct an array of buckets for associating outlines into blobs.
Definition at line 53 of file edgblob.cpp.
References buckets, BUCKETSIZE, bxdim, bydim, index, and ICOORD::y().
00055 : bl (bleft), tr (tright) { 00056 00057 bxdim = (tright.x () - bleft.x ()) / BUCKETSIZE + 1; 00058 bydim = (tright.y () - bleft.y ()) / BUCKETSIZE + 1; 00059 //make array 00060 buckets = new C_OUTLINE_LIST[bxdim * bydim]; 00061 index = 0; 00062 }
OL_BUCKETS::~OL_BUCKETS | ( | ) | [inline] |
Recursive count.
outline | Parent outline | |
max_count | Max output |
For example, the INNER outline of "O" or "B" finds ZERO descendants. Conversely, the OUTER outline of "O" finds ONE descendant while the OUTER outline of "B" finds TWO descendants.
The xindex & yindex are "normalized" to BUCKETSIZE (which "must be the same size as an INT16"(??) and is #defined 16) such that the parent outline and its children have the SAME coordinates - both OUTER and INNER outlines of "O" have the same xindex and yindex.
Notes:
Definition at line 104 of file edgblob.cpp.
References bl, BOX::bottom(), ROW::bounding_box(), buckets, BUCKETSIZE, bxdim, cprintf(), FALSE, BOX::left(), BOX::right(), BOX::top(), TRUE, ICOORD::y(), ymax, and ymin.
Referenced by capture_children().
00107 { 00108 BOOL8 parent_box; //could it be boxy 00109 INT16 xmin, xmax; //coord limits 00110 INT16 ymin, ymax; 00111 INT16 xindex, yindex; //current bucket 00112 C_OUTLINE *child; //current child 00113 INT32 child_count; //no of children 00114 INT32 grandchild_count; //no of grandchildren 00115 INT32 parent_area; //potential box 00116 FLOAT32 max_parent_area; //potential box 00117 INT32 child_area; //current child 00118 INT32 child_length; //current child 00119 BOX olbox; 00120 C_OUTLINE_IT child_it; //search iterator 00121 00122 olbox = outline->bounding_box (); 00123 xmin = (olbox.left () - bl.x ()) / BUCKETSIZE; 00124 xmax = (olbox.right () - bl.x ()) / BUCKETSIZE; 00125 ymin = (olbox.bottom () - bl.y ()) / BUCKETSIZE; 00126 ymax = (olbox.top () - bl.y ()) / BUCKETSIZE; 00127 00128 child_count = 0; 00129 grandchild_count = 0; 00130 parent_area = 0; 00131 max_parent_area = 0; 00132 parent_box = TRUE; 00133 #if defined(TEXT_VERBOSE) && defined(TV_FOCUSG) 00134 cprintf("\n1(bb=%d,%d,%d,%d)",xmin,ymin,xmax,ymax); // , see ccmain/tessvars.h 00135 #endif 00136 00137 for (yindex = ymin; yindex <= ymax; yindex++) { 00138 for (xindex = xmin; xindex <= xmax; xindex++) { 00139 child_it.set_to_list (&buckets[yindex * bxdim + xindex]); 00140 if (child_it.empty ()) 00141 continue; 00142 for (child_it.mark_cycle_pt (); !child_it.cycled_list (); 00143 child_it.forward ()) { 00144 child = child_it.data (); 00145 if (child != outline && *child < *outline) { 00146 child_count++; 00147 if (child_count <= max_count) 00148 grandchild_count += count_children (child, 00149 (max_count - 00150 child_count) / 00151 edges_children_per_grandchild) 00152 * edges_children_per_grandchild; 00153 if (child_count + grandchild_count > max_count) { 00154 /* err.log(RESULT_OKAY,E_LOC,ERR_OCR, 00155 ERR_SCROLLING,ERR_CONTINUE,ERR_DEBUG, 00156 "Discarding parent with child count=%d, gc=%d", 00157 child_count,grandchild_count);*/ 00158 #if defined(TEXT_VERBOSE) && defined(TV_FOCUSG) 00159 cprintf("2(%d,%d)",child_count,grandchild_count); // , see ccmain/tessvars.h 00160 #endif 00161 return child_count + grandchild_count; 00162 } 00163 if (parent_area == 0) { 00164 parent_area = outline->outer_area (); 00165 if (parent_area < 0) 00166 parent_area = -parent_area; 00167 max_parent_area = outline->bounding_box ().width () 00168 * outline->bounding_box ().height () * edges_boxarea; 00169 if (parent_area < max_parent_area) 00170 parent_box = FALSE; 00171 } 00172 if (parent_box 00173 && (!edges_children_fix 00174 || child->bounding_box ().height () > 00175 edges_min_nonhole) ) { 00176 child_area = child->outer_area (); 00177 if (child_area < 0) 00178 child_area = -child_area; 00179 if (edges_children_fix) { 00180 if (parent_area - child_area < max_parent_area) { 00181 parent_box = FALSE; 00182 continue; 00183 } 00184 if (grandchild_count > 0) { 00185 /* 00186 err.log(RESULT_OKAY,E_LOC,ERR_OCR, 00187 ERR_SCROLLING,ERR_CONTINUE,ERR_DEBUG, 00188 "Discarding parent of area %d, child area=%d, max%g with gc=%d", 00189 parent_area,child_area,max_parent_area,grandchild_count); 00190 */ 00191 #if defined(TEXT_VERBOSE) && defined(TV_FOCUSG) 00192 cprintf("5(%d)",max_count+1); // , see ccmain/tessvars.h 00193 #endif 00194 return max_count + 1; 00195 } 00196 child_length = child->pathlength (); 00197 if (child_length * child_length > 00198 child_area * edges_patharea_ratio) { 00199 /* 00200 err.log(RESULT_OKAY,E_LOC,ERR_OCR, 00201 ERR_SCROLLING,ERR_CONTINUE,ERR_DEBUG, 00202 "Discarding parent of area %d, child area=%d, max%g with child length=%d", 00203 parent_area,child_area,max_parent_area,child_length); 00204 */ 00205 #if defined(TEXT_VERBOSE) && defined(TV_FOCUSG) 00206 cprintf("6(%d)",max_count+1); // , see ccmain/tessvars.h 00207 #endif 00208 return max_count + 1; 00209 } 00210 } 00211 if (child_area < child->bounding_box ().width () 00212 * child->bounding_box ().height () * 00213 edges_childarea) { 00214 /* 00215 err.log(RESULT_OKAY,E_LOC,ERR_OCR, 00216 ERR_SCROLLING,ERR_CONTINUE,ERR_DEBUG, 00217 "Discarding parent of area %d, child area=%d, max%g with child rect=%d", 00218 parent_area,child_area,max_parent_area,child->bounding_box().width() 00219 *child->bounding_box().height()); 00220 */ 00221 #if defined(TEXT_VERBOSE) && defined(TV_FOCUSG) 00222 cprintf("7(%d)",max_count+1); // , see ccmain/tessvars.h 00223 #endif 00224 return max_count + 1; 00225 } 00226 } 00227 } 00228 } 00229 } 00230 } 00231 #if defined(TEXT_VERBOSE) && defined(TV_FOCUSG) 00232 cprintf("8[%d,%d=%d|%d,%d,%d]",xindex,yindex,child_count,parent_area,grandchild_count,child_length); 00233 #endif 00234 return child_count + grandchild_count; 00235 }
void OL_BUCKETS::extract_children | ( | C_OUTLINE * | outline, | |
C_OUTLINE_IT * | it | |||
) |
Recursive count.
outline | Parent outline | |
it | Destination iterator |
Definition at line 250 of file edgblob.cpp.
References bl, BOX::bottom(), buckets, BUCKETSIZE, bxdim, BOX::left(), BOX::right(), BOX::top(), ICOORD::y(), ymax, and ymin.
Referenced by capture_children().
00253 { 00254 INT16 xmin, xmax; //coord limits 00255 INT16 ymin, ymax; 00256 INT16 xindex, yindex; //current bucket 00257 BOX olbox; 00258 C_OUTLINE_IT child_it; //search iterator 00259 00260 olbox = outline->bounding_box (); 00261 xmin = (olbox.left () - bl.x ()) / BUCKETSIZE; 00262 xmax = (olbox.right () - bl.x ()) / BUCKETSIZE; 00263 ymin = (olbox.bottom () - bl.y ()) / BUCKETSIZE; 00264 ymax = (olbox.top () - bl.y ()) / BUCKETSIZE; 00265 for (yindex = ymin; yindex <= ymax; yindex++) { 00266 for (xindex = xmin; xindex <= xmax; xindex++) { 00267 child_it.set_to_list (&buckets[yindex * bxdim + xindex]); 00268 for (child_it.mark_cycle_pt (); !child_it.cycled_list (); 00269 child_it.forward ()) { 00270 if (*child_it.data () < *outline) { 00271 it->add_after_then_move (child_it.extract ()); 00272 } 00273 } 00274 } 00275 } 00276 }
Convert coordinates to C_OUTLINE.
x | X coord of image | |
y | Y coord of image |
Definition at line 74 of file edgblob.cpp.
References bl, buckets, BUCKETSIZE, bxdim, and ICOORD::y().
00076 { 00077 return &buckets[(y - bl.y ()) / BUCKETSIZE * bxdim + 00078 (x - bl.x ()) / BUCKETSIZE]; 00079 }
C_OUTLINE_LIST* OL_BUCKETS::scan_next | ( | ) | [inline] |
C_OUTLINE_LIST* OL_BUCKETS::start_scan | ( | ) | [inline] |
ICOORD OL_BUCKETS::bl [private] |
Definition at line 74 of file edgblob.h.
Referenced by count_children(), extract_children(), and operator()().
C_OUTLINE_LIST* OL_BUCKETS::buckets [private] |
Definition at line 71 of file edgblob.h.
Referenced by count_children(), extract_children(), OL_BUCKETS(), operator()(), scan_next(), start_scan(), and ~OL_BUCKETS().
INT16 OL_BUCKETS::bxdim [private] |
Definition at line 72 of file edgblob.h.
Referenced by count_children(), extract_children(), OL_BUCKETS(), operator()(), scan_next(), and start_scan().
INT16 OL_BUCKETS::bydim [private] |
INT32 OL_BUCKETS::index [private] |
ICOORD OL_BUCKETS::tr [private] |