59 TBOX all_together = bounds[start];
60 for (
int x = start + 1; x <= end; x++) {
61 all_together += bounds[x];
81 BLOB_CHOICE_LIST *choices;
86 for (blob = pieces, x = 0; x < start; x++) {
92 #ifndef GRAPHICS_DISABLED
107 template<
class BLOB_CHOICE>
115 template<
class BLOB_CHOICE>
139 BLOB_CHOICE_LIST *filtered_choices) {
140 BLOB_CHOICE_IT filtered_choices_it(filtered_choices);
141 BLOB_CHOICE_IT choices_it(choices);
143 for (choices_it.mark_cycle_pt(); !choices_it.cycled_list();
144 choices_it.forward()) {
145 UNICHAR_ID choice_unichar_id = choices_it.data()->unichar_id();
148 if (frag !=
NULL && frag->
get_pos() == fragment_pos &&
155 filtered_choices_it.add_to_end(b);
159 filtered_choices->sort(SortByUnicharID<BLOB_CHOICE>);
170 inT16 num_frag_parts,
171 BLOB_CHOICE_LIST *choice_lists,
173 BLOB_CHOICE_IT *choice_lists_it =
new BLOB_CHOICE_IT[num_frag_parts];
175 for (
int i = 0; i < num_frag_parts; i++) {
176 choice_lists_it[i].set_to_list(&choice_lists[i]);
177 choice_lists_it[i].mark_cycle_pt();
180 BLOB_CHOICE_LIST *merged_choice = ratings->
get(row, column);
181 if (merged_choice ==
NULL)
182 merged_choice =
new BLOB_CHOICE_LIST;
184 bool end_of_list =
false;
185 BLOB_CHOICE_IT merged_choice_it(merged_choice);
186 while (!end_of_list) {
189 UNICHAR_ID max_unichar_id = choice_lists_it[0].data()->unichar_id();
191 for (
int i = 0; i < num_frag_parts; i++) {
192 UNICHAR_ID unichar_id = choice_lists_it[i].data()->unichar_id();
193 if (max_unichar_id < unichar_id) {
194 max_unichar_id = unichar_id;
201 for (
int i = 0; i < num_frag_parts; i++) {
202 UNICHAR_ID unichar_id = choice_lists_it[i].data()->unichar_id();
203 while (!choice_lists_it[i].cycled_list() &&
204 unichar_id < max_unichar_id) {
205 choice_lists_it[i].forward();
206 unichar_id = choice_lists_it[i].data()->unichar_id();
208 if (choice_lists_it[i].cycled_list()) {
218 UNICHAR_ID first_unichar_id = choice_lists_it[0].data()->unichar_id();
219 bool same_unichar =
true;
220 for (
int i = 1; i < num_frag_parts; i++) {
221 UNICHAR_ID unichar_id = choice_lists_it[i].data()->unichar_id();
222 if (unichar_id != first_unichar_id) {
223 same_unichar =
false;
230 UNICHAR_ID merged_unichar_id = first_unichar_id;
231 inT16 merged_fontinfo_id = choice_lists_it[0].data()->fontinfo_id();
232 inT16 merged_fontinfo_id2 = choice_lists_it[0].data()->fontinfo_id2();
233 inT16 merged_min_xheight = choice_lists_it[0].data()->min_xheight();
234 inT16 merged_max_xheight = choice_lists_it[0].data()->max_xheight();
235 int merged_script_id = choice_lists_it[0].data()->script_id();
236 bool merged_adapted = choice_lists_it[0].data()->adapted();
238 float merged_rating = 0, merged_certainty = 0;
239 for (
int i = 0; i < num_frag_parts; i++) {
240 float rating = choice_lists_it[i].data()->rating();
241 float certainty = choice_lists_it[i].data()->certainty();
243 if (i == 0 || certainty < merged_certainty)
244 merged_certainty = certainty;
245 merged_rating += rating;
247 choice_lists_it[i].forward();
248 if (choice_lists_it[i].cycled_list())
251 choice_lists_it[i].data()->max_xheight(),
252 &merged_min_xheight, &merged_max_xheight);
255 merged_choice_it.add_to_end(
new BLOB_CHOICE(merged_unichar_id,
271 if (merged_choice->empty())
272 delete merged_choice;
274 ratings->
put(row, column, merged_choice);
276 delete [] choice_lists_it;
295 BLOB_CHOICE_LIST *choice_lists) {
296 if (current_frag == num_frag_parts) {
298 choice_lists, ratings);
302 for (
inT16 x = current_row; x < num_blobs; x++) {
303 BLOB_CHOICE_LIST *choices = ratings->
get(current_row, x);
308 &choice_lists[current_frag]);
309 if (!choice_lists[current_frag].empty()) {
311 num_blobs, ratings, choice_lists);
312 choice_lists[current_frag].clear();
326 for (
inT16 start = 0; start < num_blobs; start++) {
330 ratings, choice_lists);
335 for (
inT16 x = 0; x < num_blobs; x++) {
336 for (
inT16 y = x; y < num_blobs; y++) {
337 BLOB_CHOICE_LIST *choices = ratings->
get(x, y);
338 if (choices !=
NULL) {
339 BLOB_CHOICE_IT choices_it(choices);
340 for (choices_it.mark_cycle_pt(); !choices_it.cycled_list();
341 choices_it.forward()) {
342 UNICHAR_ID choice_unichar_id = choices_it.data()->unichar_id();
346 delete choices_it.extract();
369 BLOB_CHOICE_LIST *choices = ratings->
get(start, end);
377 ratings->
put(start, end, choices);
379 tprintf(
"get_piece_rating(): updated ratings matrix\n");
398 for (
TBLOB* blob = blobs; blob !=
NULL; blob = blob->next) {
399 bboxes[x] = blob->bounding_box();
419 for (
int x = 0; x < num_blobs; x++) {
420 for (
int y = x; y < num_blobs; y++) {
423 if (choices !=
NULL) {
424 ratings->
put(x, y, choices);
int SortByUnicharID(const void *void1, const void *void2)
const UNICHAR_ID unichar_to_id(const char *const unichar_repr) const
void merge_and_put_fragment_lists(inT16 row, inT16 column, inT16 num_frag_parts, BLOB_CHOICE_LIST *choice_lists, MATRIX *ratings)
void IntersectRange(const T &lower1, const T &upper1, T *lower2, T *upper2)
void memfree(void *element)
BLOB_CHOICE_LIST * get_piece_rating(MATRIX *ratings, TBLOB *blobs, const DENORM &denorm, SEAMS seams, inT16 start, inT16 end, BlamerBundle *blamer_bundle)
void break_pieces(TBLOB *blobs, SEAMS seams, inT16 start, inT16 end)
BlobMatchTable blob_match_table
void merge_fragments(MATRIX *ratings, inT16 num_blobs)
T get(int column, int row) const
int wordrec_display_segmentations
UNICHAR_ID unichar_id() const
MATRIX * record_piece_ratings(TBLOB *blobs)
char window_wait(ScrollView *win)
void join_pieces(TBLOB *piece_blobs, SEAMS seams, inT16 start, inT16 end)
SEARCH_STATE bin_to_chunks(STATE *state, int num_joints)
void set_n_ones(STATE *state, int n)
static const int kMaxChunks
void display_segmentation(TBLOB *chunks, SEARCH_STATE segmentation)
void put(int column, int row, const T &thing)
int SortByRating(const void *void1, const void *void2)
void print_ratings_list(const char *msg, BLOB_CHOICE_LIST *ratings, const UNICHARSET ¤t_unicharset)
void fill_filtered_fragment_list(BLOB_CHOICE_LIST *choices, int fragment_pos, int num_frag_parts, BLOB_CHOICE_LIST *filtered_choices)
const CHAR_FRAGMENT * get_fragment(UNICHAR_ID unichar_id) const
TBOX * record_blob_bounds(TBLOB *blobs)
DLLSYM void tprintf(const char *format,...)
int count_blobs(TBLOB *blobs)
void print(const UNICHARSET &unicharset) const
virtual BLOB_CHOICE_LIST * classify_piece(TBLOB *pieces, const DENORM &denorm, SEAMS seams, inT16 start, inT16 end, BlamerBundle *blamer_bundle)
TBOX bounds_of_piece(TBOX *bounds, inT16 start, inT16 end)
const char * get_unichar() const
BLOB_CHOICE_LIST * get_match_by_box(const TBOX &box)
void get_fragment_lists(inT16 current_frag, inT16 current_row, inT16 start, inT16 num_frag_parts, inT16 num_blobs, MATRIX *ratings, BLOB_CHOICE_LIST *choice_lists)
void set_unichar_id(UNICHAR_ID newunichar_id)
BLOB_CHOICE_LIST * classify_blob(TBLOB *blob, const DENORM &denorm, const char *string, C_COL color, BlamerBundle *blamer_bundle)
bool merge_fragments_in_matrix