Skip to content

Commit

Permalink
clean up old code
Browse files Browse the repository at this point in the history
  • Loading branch information
jw098 committed Jul 9, 2024
1 parent 36dd97b commit 1b11bc4
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ void TestProgram::program(MultiSwitchProgramEnvironment& env, CancellableScope&
// PokemonLA::ButtonDetector detector(logger, PokemonLA::ButtonType::ButtonA,);


#if 1
#if 0
ItemPrinterMaterialDetector detector(COLOR_RED, LANGUAGE);
detector.make_overlays(overlays);
// cout << (int)detector.find_happiny_dust_row_index(env.inference_dispatcher(), console, context) << endl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,113 +107,8 @@ int16_t ItemPrinterMaterialDetector::read_number(
number = -1;
}
return (int16_t)number;

// return read_number_black_or_white_text(logger, dispatcher, screen, box, true);


// if (!is_dark_text_light_background){
// filtered = to_blackwhite_rgb32_range(
// extract_box_reference(screen, box),
// 0xff808080, 0xffffffff,
// true
// );
// filtered.save("DebugDumps/test-one-filter-2.png");
// }

// ImageRGB32 scaled_image = filtered.scale_to(600, 200);
// scaled_image.save("DebugDumps/test-one-scaled-1.png");
// int value = OCR::read_number(logger, scaled_image);

// return (int16_t)value;


}

int16_t ItemPrinterMaterialDetector::read_number_black_or_white_text(
Logger& logger, AsyncDispatcher& dispatcher,
const ImageViewRGB32& screen, const ImageFloatBox& box,
bool is_white_text
) const{
ImageViewRGB32 cropped = extract_box_reference(screen, box);

std::vector<BlackWhiteRgb32Range> filters;
if (is_white_text){
filters =
{
// white text filters
{0xff808080, 0xffffffff, true},
{0xff909090, 0xffffffff, true},
{0xffa0a0a0, 0xffffffff, true},
{0xffb0b0b0, 0xffffffff, true},
{0xffc0c0c0, 0xffffffff, true},
{0xffd0d0d0, 0xffffffff, true},
{0xffe0e0e0, 0xffffffff, true},
{0xfff0f0f0, 0xffffffff, true},
};
}else{
filters =
{
// black text filters
// {0xff000000, 0xff101010, true},
// {0xff000000, 0xff202020, true},
{0xff000000, 0xff303030, true},
{0xff000000, 0xff404040, true},
{0xff000000, 0xff505050, true},
{0xff000000, 0xff606060, true},
{0xff000000, 0xff707070, true},
{0xff000000, 0xff808080, true},
};
}

std::vector<std::pair<ImageRGB32, size_t>> filtered = to_blackwhite_rgb32_range(
cropped,
filters
);

SpinLock lock;
std::map<int16_t, int8_t> candidates;
std::vector<std::unique_ptr<AsyncTask>> tasks(filtered.size());
// for (size_t c = 0; c < filtered.size(); c++){
// filtered[c].first.save("DebugDumps/test-" + std::to_string(c) + ".png");
// }
for (size_t c = 0; c < filtered.size(); c++){
tasks[c] = dispatcher.dispatch([&, c]{
filtered[c].first.save("DebugDumps/test-" + std::to_string(c) + ".png");
int num = OCR::read_number(logger, filtered[c].first);
WriteSpinLock lg(lock);
candidates[(int16_t)num]++;
});
}

// Wait for everything.
for (auto& task : tasks){
task->wait_and_rethrow_exceptions();
}

std::pair<int16_t, int8_t> best;
std::pair<int16_t, int8_t> second_best;
for (const auto& item : candidates){
logger.log("Candidate OCR: " + std::to_string(item.first) + "; x" + std::to_string(item.second));
if (item.second >= best.second){
second_best = best;
best = item;
}
// std::cout << "Best: " << std::to_string(best.first) << "; x" << std::to_string(best.second) << std::endl;
// std::cout << "Second Best: " << std::to_string(second_best.first) << "; x" << std::to_string(second_best.second) << std::endl;
}

if (best.second > second_best.second + 3){
return best.first;
}else{
logger.log("Ambiguous or multiple results with normal number OCR. Use Waterfill number OCR.");
if(is_white_text){
return (int16_t)OCR::read_number_waterfill(logger, cropped, 0xff808080, 0xffffffff);
}else{
return (int16_t)OCR::read_number_waterfill(logger, cropped, 0xff000000, 0xff808080);
}
}

}

// return row number where Happiny dust is located on screen
// keep pressing DPAD_RIGHT until Happiny dust is on screen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,6 @@ class ItemPrinterMaterialDetector{
const ImageViewRGB32& screen, const ImageFloatBox& box
) const;

int16_t read_number_black_or_white_text(
Logger& logger, AsyncDispatcher& dispatcher,
const ImageViewRGB32& screen, const ImageFloatBox& box,
bool is_white_text
) const;


private:
Color m_color;
Expand Down

0 comments on commit 1b11bc4

Please sign in to comment.