Skip to content

Commit fa2b359

Browse files
committed
read_number_waterfill: try different filter if OCR results in empty string
1 parent a176349 commit fa2b359

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

SerialPrograms/Source/CommonTools/OCR/OCR_NumberReader.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ std::string run_number_normalization(const std::string& input){
3939
{'9', '9'},
4040

4141
// Common misreads.
42+
{'|', '1'},
4243
{']', '1'},
4344
{'l', '1'},
4445
{'i', '1'},
@@ -173,7 +174,7 @@ int read_number_waterfill(
173174
ImageRGB32 filtered = to_blackwhite_rgb32_range(image, rgb32_min, rgb32_max, text_inside_range);
174175

175176
// static int c = 0;
176-
// static int i = 0;
177+
// int i = 0;
177178
// filtered.save("test-" + std::to_string(c++) + ".png");
178179

179180
PackedBinaryMatrix matrix = compress_rgb32_to_binary_range(filtered, 0xff000000, 0xff7f7f7f);
@@ -198,6 +199,7 @@ int read_number_waterfill(
198199
}
199200

200201
std::string ocr_text;
202+
bool empty_char = false;
201203
for (const auto& item : map){
202204
const WaterfillObject& object = item.second;
203205
ImageRGB32 cropped = extract_box_reference(filtered, object).copy();
@@ -206,11 +208,18 @@ int read_number_waterfill(
206208
ImageRGB32 padded = pad_image(cropped, cropped.width(), 0xffffffff);
207209
std::string ocr = OCR::ocr_read(Language::English, padded);
208210
// padded.save("test-cropped" + std::to_string(c) + "-" + std::to_string(i++) + ".png");
209-
// std::cout << ocr << std::endl;
211+
// std::cout << ocr[0] << std::endl;
210212
if (!ocr.empty()){
211213
ocr_text += ocr[0];
214+
}else{
215+
empty_char = true;
216+
break;
212217
}
213218
}
219+
if (empty_char){
220+
// try the next color filter
221+
continue;
222+
}
214223

215224
std::string normalized = run_number_normalization(ocr_text);
216225

0 commit comments

Comments
 (0)