Skip to content

Commit 7537c66

Browse files
committed
update item printer material detector color filters for OCR
1 parent db560e7 commit 7537c66

File tree

4 files changed

+27
-16
lines changed

4 files changed

+27
-16
lines changed

SerialPrograms/Source/CommonTools/OCR/OCR_NumberReader.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ std::string run_number_normalization(const std::string& input){
4848
{'S', '5'},
4949
{'s', '5'},
5050
{'/', '7'},
51+
{'g', '9'},
5152

5253
// Japanese OCR likes to do this.
5354
{U'🄋', '0'},
@@ -115,8 +116,8 @@ int read_number_waterfill(
115116
ImageRGB32 filtered = to_blackwhite_rgb32_range(image, rgb32_min, rgb32_max, text_inside_range);
116117

117118
// static int c = 0;
119+
// filtered.save("zztest-" + std::to_string(c++) + ".png");
118120
// int i = 0;
119-
// filtered.save("test-" + std::to_string(c++) + ".png");
120121

121122
PackedBinaryMatrix matrix = compress_rgb32_to_binary_range(filtered, 0xff000000, 0xff7f7f7f);
122123

@@ -142,7 +143,7 @@ int read_number_waterfill(
142143
filter_by_mask(tmp, cropped, Color(0xffffffff), true);
143144
ImageRGB32 padded = pad_image(cropped, cropped.width(), 0xffffffff);
144145
std::string ocr = OCR::ocr_read(Language::English, padded);
145-
// padded.save("test-cropped" + std::to_string(c) + "-" + std::to_string(i++) + ".png");
146+
// padded.save("zztest-cropped" + std::to_string(c) + "-" + std::to_string(i++) + ".png");
146147
// std::cout << ocr[0] << std::endl;
147148
if (!ocr.empty()){
148149
ocr_text += ocr[0];

SerialPrograms/Source/NintendoSwitch/DevPrograms/TestProgramSwitch.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ TestProgram::TestProgram()
219219
LockMode::LOCK_WHILE_RUNNING,
220220
false
221221
)
222+
, IMAGE_PATH(false, "Path to image for testing", LockMode::UNLOCK_WHILE_RUNNING, "default.png", "default.png")
222223
, STATIC_TEXT("Test text...")
223224
, SELECT("String Select", test_database(), LockMode::LOCK_WHILE_RUNNING, 0)
224225
// , PLAYER_LIST("Test Table", LockMode::UNLOCK_WHILE_RUNNING, "Notes")
@@ -258,6 +259,7 @@ TestProgram::TestProgram()
258259
PA_ADD_OPTION(BUTTON0);
259260
PA_ADD_OPTION(BUTTON1);
260261
PA_ADD_OPTION(LANGUAGE);
262+
PA_ADD_OPTION(IMAGE_PATH);
261263
PA_ADD_OPTION(STATIC_TEXT);
262264
PA_ADD_OPTION(SELECT);
263265
// PA_ADD_OPTION(PLAYER_LIST);
@@ -314,14 +316,14 @@ void TestProgram::program(MultiSwitchProgramEnvironment& env, CancellableScope&
314316
// std::terminate();
315317

316318
#if 1
317-
ImageRGB32 image("720p1.png");
318-
// auto image = feed.snapshot();
319+
// ImageRGB32 image(IMAGE_PATH);
320+
auto image = feed.snapshot();
319321

320322
ItemPrinterMaterialDetector detector(COLOR_RED, Language::English);
321323

322324
std::vector<ImageFloatBox> boxes = {
323-
{0.485,0.176758,0.037,0.05}, {0.485,0.250977,0.037,0.05}, {0.485,0.325196,0.037,0.05}, {0.485,0.399415,0.037,0.05}, {0.485,0.473634,0.037,0.05}, {0.485,0.547853,0.037,0.05}, {0.485,0.622072,0.037,0.05}, {0.485,0.696291,0.037,0.05}, {0.485,0.77051,0.037,0.05}, {0.485,0.844729,0.037,0.05},
324-
// {0.39,0.176758,0.025,0.05}, {0.39,0.250977,0.025,0.05}, {0.39,0.325196,0.025,0.05}, {0.39,0.399415,0.025,0.05}, {0.39,0.473634,0.025,0.05}, {0.39,0.547853,0.025,0.05}, {0.39,0.622072,0.025,0.05}, {0.39,0.696291,0.025,0.05}, {0.39,0.77051,0.025,0.05}, {0.39,0.844729,0.025,0.05},
325+
// {0.485,0.176758,0.037,0.05}, {0.485,0.250977,0.037,0.05}, {0.485,0.325196,0.037,0.05}, {0.485,0.399415,0.037,0.05}, {0.485,0.473634,0.037,0.05}, {0.485,0.547853,0.037,0.05}, {0.485,0.622072,0.037,0.05}, {0.485,0.696291,0.037,0.05}, {0.485,0.77051,0.037,0.05}, {0.485,0.844729,0.037,0.05},
326+
{0.39,0.176758,0.025,0.05}, {0.39,0.250977,0.025,0.05}, {0.39,0.325196,0.025,0.05}, {0.39,0.399415,0.025,0.05}, {0.39,0.473634,0.025,0.05}, {0.39,0.547853,0.025,0.05}, {0.39,0.622072,0.025,0.05}, {0.39,0.696291,0.025,0.05}, {0.39,0.77051,0.025,0.05}, {0.39,0.844729,0.025,0.05},
325327
};
326328
for (ImageFloatBox box : boxes){
327329
detector.read_number(console.logger(), env.inference_dispatcher(), image, box);

SerialPrograms/Source/NintendoSwitch/DevPrograms/TestProgramSwitch.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ class TestProgram : public MultiSwitchProgramInstance, public ButtonListener{
6868

6969
OCR::LanguageOCROption LANGUAGE;
7070

71+
StringOption IMAGE_PATH;
72+
7173
StaticTextOption STATIC_TEXT;
7274

7375
StringSelectOption SELECT;

SerialPrograms/Source/PokemonSV/Inference/ItemPrinter/PokemonSV_ItemPrinterMaterialDetector.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,24 +101,30 @@ int16_t ItemPrinterMaterialDetector::read_number(
101101
int16_t number;
102102
if (is_dark_text_light_background){
103103
const std::vector<std::pair<uint32_t, uint32_t>> filters = {
104+
// {0xff000000, 0xffb0b0b0},
105+
{0xff000000, 0xffa0a0a0},
106+
{0xff000000, 0xff959595},
104107
{0xff000000, 0xff909090},
108+
{0xff000000, 0xff858585},
105109
{0xff000000, 0xff808080},
106-
{0xff000000, 0xff707070},
107-
{0xff000000, 0xff606060},
108-
{0xff000000, 0xff505050},
109-
{0xff000000, 0xff404040},
110-
{0xff000000, 0xff303030},
111-
{0xff000000, 0xff202020},
112-
{0xff000000, 0xff101010},
110+
// {0xff000000, 0xff707070},
111+
// {0xff000000, 0xff606060},
112+
// {0xff000000, 0xff505050},
113+
// {0xff000000, 0xff404040},
114+
// {0xff000000, 0xff303030},
115+
// {0xff000000, 0xff202020},
116+
// {0xff000000, 0xff101010},
113117
};
114118
number = (int16_t)OCR::read_number_waterfill(logger, cropped, filters, 24);
115119
}else{
116120
const std::vector<std::pair<uint32_t, uint32_t>> filters = {
117-
// {0xff808080, 0xffffffff},
121+
{0xff808080, 0xffffffff},
122+
{0xff858585, 0xffffffff},
118123
{0xff909090, 0xffffffff},
124+
{0xff959595, 0xffffffff},
119125
{0xffa0a0a0, 0xffffffff},
120-
{0xffb0b0b0, 0xffffffff},
121-
{0xffc0c0c0, 0xffffffff},
126+
// {0xffb0b0b0, 0xffffffff},
127+
// {0xffc0c0c0, 0xffffffff},
122128
// {0xffd0d0d0, 0xffffffff},
123129
// {0xffe0e0e0, 0xffffffff},
124130
// {0xfff0f0f0, 0xffffffff},

0 commit comments

Comments
 (0)