This method returns a new werd constructed using the blobs in the input all_blobs list, which correspond to the blobs in this werd object. The blobs used to construct the new word are consumed and removed from the input all_blobs list. Returns nullptr if the word couldn't be constructed. Returns original blobs for which no matches were found in the output list orphan_blobs (appends).
395 {
396 C_BLOB_LIST current_blob_list;
397 C_BLOB_IT werd_blobs_it(¤t_blob_list);
398
400
401
402 C_BLOB_LIST new_werd_blobs;
403 C_BLOB_IT new_blobs_it(&new_werd_blobs);
404
405
406
407 C_BLOB_LIST not_found_blobs;
408 C_BLOB_IT not_found_it(¬_found_blobs);
409 not_found_it.move_to_last();
410
411 werd_blobs_it.move_to_first();
412 for (werd_blobs_it.mark_cycle_pt(); !werd_blobs_it.cycled_list(); werd_blobs_it.forward()) {
413 C_BLOB *werd_blob = werd_blobs_it.extract();
414 TBOX werd_blob_box = werd_blob->bounding_box();
415 bool found = false;
416
417
418
419 C_BLOB_IT all_blobs_it(all_blobs);
420 for (all_blobs_it.mark_cycle_pt(); !all_blobs_it.cycled_list(); all_blobs_it.forward()) {
421 C_BLOB *a_blob = all_blobs_it.data();
422
423
424 TBOX a_blob_box = a_blob->bounding_box();
425 if (a_blob_box.null_box()) {
426 tprintf(
"Bounding box couldn't be ascertained\n");
427 }
428 if (werd_blob_box.contains(a_blob_box) || werd_blob_box.major_overlap(a_blob_box)) {
429
430
431
432 all_blobs_it.extract();
433 new_blobs_it.add_after_then_move(a_blob);
434 found = true;
435 }
436 }
437 if (!found) {
438 not_found_it.add_after_then_move(werd_blob);
439 } else {
440 delete werd_blob;
441 }
442 }
443
444
445
446 not_found_it.move_to_first();
447 for (not_found_it.mark_cycle_pt(); !not_found_it.cycled_list(); not_found_it.forward()) {
448 C_BLOB *not_found = not_found_it.data();
449 TBOX not_found_box = not_found->bounding_box();
450 C_BLOB_IT existing_blobs_it(new_blobs_it);
451 for (existing_blobs_it.mark_cycle_pt(); !existing_blobs_it.cycled_list();
452 existing_blobs_it.forward()) {
453 C_BLOB *a_blob = existing_blobs_it.data();
454 TBOX a_blob_box = a_blob->bounding_box();
455 if ((not_found_box.major_overlap(a_blob_box) || a_blob_box.major_overlap(not_found_box)) &&
456 not_found_box.y_overlap_fraction(a_blob_box) > 0.8) {
457
458 delete not_found_it.extract();
459 break;
460 }
461 }
462 }
463 if (orphan_blobs) {
464 C_BLOB_IT orphan_blobs_it(orphan_blobs);
465 orphan_blobs_it.move_to_last();
466 orphan_blobs_it.add_list_after(¬_found_blobs);
467 }
468
469
470 WERD *new_werd =
nullptr;
471 if (!new_werd_blobs.empty()) {
472 new_werd =
new WERD(&new_werd_blobs,
this);
473 } else {
474
476 this_list_it.add_list_after(¬_found_blobs);
477 }
478 return new_werd;
479}
void tprintf(const char *format,...)
C_BLOB_LIST * cblob_list()