|
7 | 7 | #include <algorithm> |
8 | 8 | #include <map> |
9 | 9 | #include "Common/Cpp/AbstractLogger.h" |
| 10 | +#include "Common/Cpp/Concurrency/SpinLock.h" |
10 | 11 | #include "Common/Qt/StringToolsQt.h" |
11 | 12 | #include "Kernels/Waterfill/Kernels_Waterfill_Session.h" |
12 | 13 | #include "CommonFramework/Language.h" |
13 | 14 | #include "CommonFramework/ImageTypes/ImageRGB32.h" |
14 | 15 | #include "CommonFramework/ImageTools/ImageBoxes.h" |
| 16 | +#include "CommonFramework/Tools/GlobalThreadPools.h" |
15 | 17 | #include "CommonTools/Images/ImageManip.h" |
16 | 18 | #include "CommonTools/Images/ImageFilter.h" |
17 | 19 | #include "CommonTools/Images/BinaryImage_FilterRgb32.h" |
@@ -218,35 +220,42 @@ int read_number_waterfill_multifilter( |
218 | 220 | line_index_str = "Line " + std::to_string(line_index) + ": "; |
219 | 221 | } |
220 | 222 |
|
| 223 | + SpinLock lock; |
221 | 224 | std::map<int, uint8_t> candidates; |
222 | | - for (std::pair<uint32_t, uint32_t> filter : filters){ |
223 | | - |
224 | | - uint32_t rgb32_min = filter.first; |
225 | | - uint32_t rgb32_max = filter.second; |
226 | | - std::string ocr_text = read_number_waterfill_no_normalization( |
227 | | - logger, |
228 | | - image, |
229 | | - rgb32_min, rgb32_max, |
230 | | - text_inside_range, |
231 | | - width_max, |
232 | | - true |
233 | | - ); |
234 | | - |
235 | | - std::string normalized = run_number_normalization(ocr_text); |
236 | | - if (normalized.empty()){ |
237 | | - // logger.log("OCR Text: \"" + ocr_text + "\" -> \"" + normalized + "\" -> Unable to read.", COLOR_RED); |
238 | | - continue; |
239 | | - } |
| 225 | + GlobalThreadPools::normal_inference().run_in_parallel( |
| 226 | + [&](size_t index){ |
| 227 | + std::pair<uint32_t, uint32_t> filter = filters[index]; |
| 228 | + |
| 229 | + uint32_t rgb32_min = filter.first; |
| 230 | + uint32_t rgb32_max = filter.second; |
| 231 | + std::string ocr_text = read_number_waterfill_no_normalization( |
| 232 | + logger, |
| 233 | + image, |
| 234 | + rgb32_min, rgb32_max, |
| 235 | + text_inside_range, |
| 236 | + width_max, |
| 237 | + true |
| 238 | + ); |
| 239 | + |
| 240 | + std::string normalized = run_number_normalization(ocr_text); |
| 241 | + if (normalized.empty()){ |
| 242 | + // logger.log("OCR Text: \"" + ocr_text + "\" -> \"" + normalized + "\" -> Unable to read.", COLOR_RED); |
| 243 | + return; |
| 244 | + } |
240 | 245 |
|
241 | | - int candidate = std::atoi(normalized.c_str()); |
242 | | - logger.log(line_index_str + "OCR Text: \"" + ocr_text + "\" -> \"" + normalized + "\" -> " + std::to_string(candidate)); |
| 246 | + int candidate = std::atoi(normalized.c_str()); |
| 247 | + logger.log(line_index_str + "OCR Text: \"" + ocr_text + "\" -> \"" + normalized + "\" -> " + std::to_string(candidate)); |
243 | 248 |
|
244 | | - if (prioritize_numeric_only_results && is_digits(ocr_text)){ |
245 | | - candidates[candidate] += 2; |
246 | | - }else{ |
247 | | - candidates[candidate]++; |
248 | | - } |
249 | | - } |
| 249 | + uint8_t weight = prioritize_numeric_only_results && is_digits(ocr_text) |
| 250 | + ? 2 |
| 251 | + : 1; |
| 252 | + |
| 253 | + WriteSpinLock lg(lock); |
| 254 | + candidates[candidate] += weight; |
| 255 | + |
| 256 | + }, |
| 257 | + 0, filters.size(), 1 |
| 258 | + ); |
250 | 259 |
|
251 | 260 | if (candidates.empty()){ |
252 | 261 | logger.log(line_index_str + "No valid OCR candidates. Unable to read number.", COLOR_ORANGE); |
|
0 commit comments