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

Method SplitBundle

deps/tesseract/ccstruct/blamer.cpp:169–222  ·  view source on GitHub ↗

Splits *this into two pieces in bundle1 and bundle2 (preallocated, empty bundles) where the right edge/ of the left-hand word is word1_right, and the left edge of the right-hand word is word2_left.

Source from the content-addressed store, hash-verified

167// bundles) where the right edge/ of the left-hand word is word1_right,
168// and the left edge of the right-hand word is word2_left.
169void BlamerBundle::SplitBundle(int word1_right, int word2_left, bool debug,
170 BlamerBundle* bundle1,
171 BlamerBundle* bundle2) const {
172 STRING debug_str;
173 // Find truth boxes that correspond to the split in the blobs.
174 int b;
175 int begin2_truth_index = -1;
176 if (incorrect_result_reason_ != IRR_NO_TRUTH &&
177 truth_has_char_boxes_) {
178 debug_str = "Looking for truth split at";
179 debug_str.add_str_int(" end1_x ", word1_right);
180 debug_str.add_str_int(" begin2_x ", word2_left);
181 debug_str += "\nnorm_truth_word boxes:\n";
182 if (norm_truth_word_.length() > 1) {
183 norm_truth_word_.BlobBox(0).print_to_str(&debug_str);
184 for (b = 1; b < norm_truth_word_.length(); ++b) {
185 norm_truth_word_.BlobBox(b).print_to_str(&debug_str);
186 if ((abs(word1_right - norm_truth_word_.BlobBox(b - 1).right()) <
187 norm_box_tolerance_) &&
188 (abs(word2_left - norm_truth_word_.BlobBox(b).left()) <
189 norm_box_tolerance_)) {
190 begin2_truth_index = b;
191 debug_str += "Split found";
192 break;
193 }
194 }
195 debug_str += '\n';
196 }
197 }
198 // Populate truth information in word and word2 with the first and second
199 // part of the original truth.
200 if (begin2_truth_index > 0) {
201 bundle1->truth_has_char_boxes_ = true;
202 bundle1->norm_box_tolerance_ = norm_box_tolerance_;
203 bundle2->truth_has_char_boxes_ = true;
204 bundle2->norm_box_tolerance_ = norm_box_tolerance_;
205 BlamerBundle *curr_bb = bundle1;
206 for (b = 0; b < norm_truth_word_.length(); ++b) {
207 if (b == begin2_truth_index) curr_bb = bundle2;
208 curr_bb->norm_truth_word_.InsertBox(b, norm_truth_word_.BlobBox(b));
209 curr_bb->truth_word_.InsertBox(b, truth_word_.BlobBox(b));
210 curr_bb->truth_text_.push_back(truth_text_[b]);
211 }
212 } else if (incorrect_result_reason_ == IRR_NO_TRUTH) {
213 bundle1->incorrect_result_reason_ = IRR_NO_TRUTH;
214 bundle2->incorrect_result_reason_ = IRR_NO_TRUTH;
215 } else {
216 debug_str += "Truth split not found";
217 debug_str += truth_has_char_boxes_ ?
218 "\n" : " (no truth char boxes)\n";
219 bundle1->SetBlame(IRR_NO_TRUTH_SPLIT, debug_str, NULL, debug);
220 bundle2->SetBlame(IRR_NO_TRUTH_SPLIT, debug_str, NULL, debug);
221 }
222}
223
224// "Joins" the blames from bundle1 and bundle2 into *this.
225void BlamerBundle::JoinBlames(const BlamerBundle& bundle1,

Callers 1

split_wordMethod · 0.80

Calls 7

add_str_intMethod · 0.80
print_to_strMethod · 0.80
SetBlameMethod · 0.80
absFunction · 0.50
lengthMethod · 0.45
InsertBoxMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected