From 54845150da97d0e0e587ecfcc3e0b54ef815008b Mon Sep 17 00:00:00 2001 From: Mysticial Date: Tue, 3 Oct 2023 13:02:04 -0700 Subject: [PATCH] Fix summary detector for certain shades of green. --- .../DevPrograms/TestProgramComputer.cpp | 10 ++++++++++ .../DevPrograms/TestProgramSwitch.cpp | 9 ++++++++- .../Inference/PokemonSV_BagDetector.cpp | 6 ++---- .../PokemonSV_PokemonSummaryReader.cpp | 18 +++++++++++++----- .../Inference/PokemonSV_PokemonSummaryReader.h | 4 ++++ 5 files changed, 37 insertions(+), 10 deletions(-) diff --git a/SerialPrograms/Source/NintendoSwitch/DevPrograms/TestProgramComputer.cpp b/SerialPrograms/Source/NintendoSwitch/DevPrograms/TestProgramComputer.cpp index 7125576c6..7a920e815 100644 --- a/SerialPrograms/Source/NintendoSwitch/DevPrograms/TestProgramComputer.cpp +++ b/SerialPrograms/Source/NintendoSwitch/DevPrograms/TestProgramComputer.cpp @@ -235,6 +235,16 @@ void TestProgramComputer::program(ProgramEnvironment& env, CancellableScope& sco // using namespace NintendoSwitch::PokemonSwSh::MaxLairInternal; + + + ImageRGB32 image("screenshot-20231003-202430049819.png"); + PokemonSummaryDetector detector; + cout << detector.detect(image) << endl; + + + + + #if 0 uint8_t low_iv; uint8_t high_iv; diff --git a/SerialPrograms/Source/NintendoSwitch/DevPrograms/TestProgramSwitch.cpp b/SerialPrograms/Source/NintendoSwitch/DevPrograms/TestProgramSwitch.cpp index b4807734f..ce4f21bd5 100644 --- a/SerialPrograms/Source/NintendoSwitch/DevPrograms/TestProgramSwitch.cpp +++ b/SerialPrograms/Source/NintendoSwitch/DevPrograms/TestProgramSwitch.cpp @@ -237,12 +237,19 @@ void TestProgram::program(MultiSwitchProgramEnvironment& env, CancellableScope& VideoOverlaySet overlays(overlay); +// ImageRGB32 image("screenshot-20231003-202430049819.png"); + auto snapshot = console.video().snapshot(); + + PokemonSummaryDetector detector; + cout << detector.detect(snapshot) << endl; + + +#if 0 SummaryStatsReader reader; reader.make_overlays(overlays); auto snapshot = console.video().snapshot(); -#if 1 NatureAdjustments nature = reader.read_nature(logger, snapshot); cout << "attack = " << (int)nature.attack << endl; cout << "defense = " << (int)nature.defense << endl; diff --git a/SerialPrograms/Source/PokemonSV/Inference/PokemonSV_BagDetector.cpp b/SerialPrograms/Source/PokemonSV/Inference/PokemonSV_BagDetector.cpp index aca826f10..ab8751af9 100644 --- a/SerialPrograms/Source/PokemonSV/Inference/PokemonSV_BagDetector.cpp +++ b/SerialPrograms/Source/PokemonSV/Inference/PokemonSV_BagDetector.cpp @@ -6,6 +6,7 @@ #include "CommonFramework/ImageTools/SolidColorTest.h" #include "CommonFramework/VideoPipeline/VideoOverlayScopes.h" +#include "PokemonSV_PokemonSummaryReader.h" #include "PokemonSV_BagDetector.h" //#include @@ -49,10 +50,7 @@ bool BagDetector::detect(const ImageViewRGB32& screen) const{ return false; } #else - if (!is_solid(bottom, {0.648549, 0.286158, 0.0652928}, 0.15, 20) && // Scarlet - !is_solid(bottom, {0.367816, 0.0746615, 0.557523}, 0.15, 20) && // Violet - !is_solid(bottom, {0.137949, 0.708023, 0.154028}, 0.15, 20) // DLC Green - ){ + if (!is_summary_color(bottom)){ return false; } #endif diff --git a/SerialPrograms/Source/PokemonSV/Inference/PokemonSV_PokemonSummaryReader.cpp b/SerialPrograms/Source/PokemonSV/Inference/PokemonSV_PokemonSummaryReader.cpp index 80e318f7b..25a117026 100644 --- a/SerialPrograms/Source/PokemonSV/Inference/PokemonSV_PokemonSummaryReader.cpp +++ b/SerialPrograms/Source/PokemonSV/Inference/PokemonSV_PokemonSummaryReader.cpp @@ -8,6 +8,7 @@ #include "CommonFramework/VideoPipeline/VideoOverlayScopes.h" #include "PokemonSV_PokemonSummaryReader.h" +// REMOVE #include using std::cout; using std::endl; @@ -18,6 +19,14 @@ namespace PokemonSV{ +bool is_summary_color(const ImageStats& stats){ + return is_solid(stats, {0.648549, 0.2861580, 0.0652928}, 0.15, 20) // Scarlet + || is_solid(stats, {0.367816, 0.0746615, 0.5575230}, 0.15, 20) // Violet + || is_solid(stats, {0.196536, 0.5933000, 0.2101630}, 0.18, 20); // DLC Green +} + + + PokemonSummaryDetector::PokemonSummaryDetector(Color color) : m_color(color) , m_top_blue_left(0.30, 0.09, 0.10, 0.05) @@ -35,26 +44,25 @@ bool PokemonSummaryDetector::detect(const ImageViewRGB32& screen) const{ ImageStats top_blue_left = image_stats(extract_box_reference(screen, m_top_blue_left)); // cout << top_blue_left.average << top_blue_left.stddev << endl; if (!is_solid(top_blue_left, {0.0745162, 0.311321, 0.614163}, 0.30, 10)){ +// cout << "bad: blue left" << endl; return false; } ImageStats top_blue_right = image_stats(extract_box_reference(screen, m_top_blue_right)); // cout << top_blue_right.average << top_blue_right.stddev << endl; if (!is_solid(top_blue_right, {0.0745162, 0.311321, 0.614163}, 0.30, 10)){ +// cout << "bad: blue right" << endl; return false; } ImageStats bottom = image_stats(extract_box_reference(screen, m_bottom)); -// cout << bottom.average << bottom.stddev << endl; + cout << bottom.average << bottom.stddev << endl; #if 0 if (bottom.stddev.sum() > 20){ return false; } #else - if (!is_solid(bottom, {0.648549, 0.286158, 0.0652928}, 0.15, 20) && // Scarlet - !is_solid(bottom, {0.367816, 0.0746615, 0.557523}, 0.15, 20) && // Violet - !is_solid(bottom, {0.137949, 0.708023, 0.154028}, 0.15, 20) // DLC Green - ){ + if (!is_summary_color(bottom)){ return false; } #endif diff --git a/SerialPrograms/Source/PokemonSV/Inference/PokemonSV_PokemonSummaryReader.h b/SerialPrograms/Source/PokemonSV/Inference/PokemonSV_PokemonSummaryReader.h index 64f6bfd30..c2d96a3d9 100644 --- a/SerialPrograms/Source/PokemonSV/Inference/PokemonSV_PokemonSummaryReader.h +++ b/SerialPrograms/Source/PokemonSV/Inference/PokemonSV_PokemonSummaryReader.h @@ -12,10 +12,14 @@ #include "CommonFramework/Inference/VisualDetector.h" namespace PokemonAutomation{ + struct ImageStats; namespace NintendoSwitch{ namespace PokemonSV{ +bool is_summary_color(const ImageStats& stats); + + class PokemonSummaryDetector : public StaticScreenDetector{ public: