MCPcopy Create free account
hub / github.com/creatale/node-dv / SelectGoodDiacriticOutlines

Method SelectGoodDiacriticOutlines

deps/tesseract/ccmain/control.cpp:1111–1192  ·  view source on GitHub ↗

Starting with ok_outlines set to indicate which outlines overlap the blob, chooses the optimal set (approximately) and returns true if any outlines are desired, in which case ok_outlines indicates which ones.

Source from the content-addressed store, hash-verified

1109// chooses the optimal set (approximately) and returns true if any outlines
1110// are desired, in which case ok_outlines indicates which ones.
1111bool Tesseract::SelectGoodDiacriticOutlines(
1112 int pass, float certainty_threshold, PAGE_RES_IT* pr_it, C_BLOB* blob,
1113 const GenericVector<C_OUTLINE*>& outlines, int num_outlines,
1114 GenericVector<bool>* ok_outlines) {
1115 STRING best_str;
1116 float target_cert = certainty_threshold;
1117 if (blob != NULL) {
1118 float target_c2;
1119 target_cert = ClassifyBlobAsWord(pass, pr_it, blob, &best_str, &target_c2);
1120 if (debug_noise_removal) {
1121 tprintf("No Noise blob classified as %s=%g(%g) at:", best_str.string(),
1122 target_cert, target_c2);
1123 blob->bounding_box().print();
1124 }
1125 target_cert -= (target_cert - certainty_threshold) * noise_cert_factor;
1126 }
1127 GenericVector<bool> test_outlines = *ok_outlines;
1128 // Start with all the outlines in.
1129 STRING all_str;
1130 GenericVector<bool> best_outlines = *ok_outlines;
1131 float best_cert = ClassifyBlobPlusOutlines(test_outlines, outlines, pass,
1132 pr_it, blob, &all_str);
1133 if (debug_noise_removal) {
1134 TBOX ol_box;
1135 for (int i = 0; i < test_outlines.size(); ++i) {
1136 if (test_outlines[i]) ol_box += outlines[i]->bounding_box();
1137 }
1138 tprintf("All Noise blob classified as %s=%g, delta=%g at:",
1139 all_str.string(), best_cert, best_cert - target_cert);
1140 ol_box.print();
1141 }
1142 // Iteratively zero out the bit that improves the certainty the most, until
1143 // we get past the threshold, have zero bits, or fail to improve.
1144 int best_index = 0; // To zero out.
1145 while (num_outlines > 1 && best_index >= 0 &&
1146 (blob == NULL || best_cert < target_cert || blob != NULL)) {
1147 // Find the best bit to zero out.
1148 best_index = -1;
1149 for (int i = 0; i < outlines.size(); ++i) {
1150 if (test_outlines[i]) {
1151 test_outlines[i] = false;
1152 STRING str;
1153 float cert = ClassifyBlobPlusOutlines(test_outlines, outlines, pass,
1154 pr_it, blob, &str);
1155 if (debug_noise_removal) {
1156 TBOX ol_box;
1157 for (int j = 0; j < outlines.size(); ++j) {
1158 if (test_outlines[j]) ol_box += outlines[j]->bounding_box();
1159 tprintf("%d", test_outlines[j]);
1160 }
1161 tprintf(" blob classified as %s=%g, delta=%g) at:", str.string(),
1162 cert, cert - target_cert);
1163 ol_box.print();
1164 }
1165 if (cert > best_cert) {
1166 best_cert = cert;
1167 best_index = i;
1168 best_outlines = test_outlines;

Callers

nothing calls this directly

Calls 4

stringMethod · 0.45
printMethod · 0.45
bounding_boxMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected