-
Notifications
You must be signed in to change notification settings - Fork 83
close_game_from_home: updated to handle the case where the game is not selected. #819
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_CloseGameDetector.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| /* Close Game Detector | ||
| * | ||
| * From: https://github.com/PokemonAutomation/ | ||
| * | ||
| */ | ||
|
|
||
| #include "CommonFramework/VideoPipeline/VideoOverlayScopes.h" | ||
| #include "CommonTools/Images/SolidColorTest.h" | ||
| #include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" | ||
| #include "NintendoSwitch_CloseGameDetector.h" | ||
|
|
||
| #include <iostream> | ||
| using std::cout; | ||
| using std::endl; | ||
|
|
||
| namespace PokemonAutomation{ | ||
| namespace NintendoSwitch{ | ||
|
|
||
|
|
||
|
|
||
| CloseGameDetector::CloseGameDetector(ConsoleHandle& console, Color color) | ||
| : m_color(color) | ||
| , m_top_box(0.226358, 0.272648, 0.407445, 0.033989) | ||
| , m_left_box(0.225, 0.275, 0.01995, 0.350) | ||
| , m_close_game_text_row(0.330986, 0.649052, 0.342052, 0.051878) | ||
| {} | ||
| void CloseGameDetector::make_overlays(VideoOverlaySet& items) const{ | ||
| items.add(m_color, m_top_box); | ||
| items.add(m_color, m_left_box); | ||
| items.add(m_color, m_close_game_text_row); | ||
| } | ||
|
|
||
|
|
||
| bool CloseGameDetector::detect(const ImageViewRGB32& screen){ | ||
|
|
||
| ImageStats stats_top = image_stats(extract_box_reference(screen, m_top_box)); // the top portion of the Close game popup | ||
| ImageStats stats_left = image_stats(extract_box_reference(screen, m_left_box)); // the left portion of the Close game popup | ||
| ImageStats stats_close_game_text = image_stats(extract_box_reference(screen, m_close_game_text_row)); // the bottom portion of the Close game popup. overlapping with the close game text. | ||
|
|
||
| // cout << "stats_close_game_text.stddev.sum()" << stats_close_game_text.stddev.sum() << endl; | ||
| bool white; | ||
| // cout << "stats_top.average.sum() = " << stats_top.average.sum() << endl; | ||
| if (stats_top.average.sum() < 300){ | ||
| white = false; | ||
| }else if (stats_top.average.sum() > 500){ | ||
| white = true; | ||
| }else{ | ||
| return false; | ||
| } | ||
|
|
||
| // cout << "stats_top.stddev.sum() = " << stats_top.stddev.sum() << endl; | ||
|
|
||
| // ensure top is uniform in color | ||
| if (stats_top.stddev.sum() > 20){ | ||
| return false; | ||
| } | ||
|
|
||
| // cout << "stats_left.stddev.sum() = " << stats_left.stddev.sum() << endl; | ||
| // ensure left is uniform in color | ||
| if (stats_left.stddev.sum() > 20){ | ||
| return false; | ||
| } | ||
|
|
||
| // ensure bottom is NOT uniform in color | ||
| if (stats_close_game_text.stddev.sum() < 50){ | ||
| return false; | ||
| } | ||
|
|
||
| if (white){ // if top is white, ensure left is also white | ||
| if (!is_white(stats_top) || !is_white(stats_left)){ | ||
| // cout << "asdf" << endl; | ||
| return false; | ||
| } | ||
| }else{ | ||
| if (!is_grey(stats_top, 0, 300) || !is_grey(stats_left, 0, 300)){ | ||
| // cout << "qwer" << endl; | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| // ensure top and left are the same color. | ||
| if (euclidean_distance(stats_top.average, stats_left.average) > 20){ | ||
| // cout << "qwer = " << euclidean_distance(stats_bottom_row.average, stats_bottom_row.average) << endl; | ||
| return false; | ||
| } | ||
|
|
||
|
|
||
| return true; | ||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| } | ||
| } |
48 changes: 48 additions & 0 deletions
48
SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_CloseGameDetector.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| /* Close Game Detector | ||
| * | ||
| * From: https://github.com/PokemonAutomation/ | ||
| * | ||
| */ | ||
|
|
||
| #ifndef PokemonAutomation_NintendoSwitch_CloseGameDetector_H | ||
| #define PokemonAutomation_NintendoSwitch_CloseGameDetector_H | ||
|
|
||
| #include "Common/Cpp/Color.h" | ||
| #include "CommonFramework/ImageTools/ImageBoxes.h" | ||
| #include "CommonTools/VisualDetector.h" | ||
|
|
||
| namespace PokemonAutomation{ | ||
| namespace NintendoSwitch{ | ||
|
|
||
|
|
||
|
|
||
| class CloseGameDetector : public StaticScreenDetector{ | ||
| public: | ||
| CloseGameDetector(ConsoleHandle& console, Color color = COLOR_RED); | ||
|
|
||
| virtual void make_overlays(VideoOverlaySet& items) const override; | ||
| virtual bool detect(const ImageViewRGB32& screen) override; | ||
|
|
||
| private: | ||
| Color m_color; | ||
| ImageFloatBox m_top_box; | ||
| ImageFloatBox m_left_box; | ||
| ImageFloatBox m_close_game_text_row; | ||
|
|
||
| }; | ||
| class CloseGameWatcher : public DetectorToFinder<CloseGameDetector>{ | ||
| public: | ||
| CloseGameWatcher( | ||
| ConsoleHandle& console, | ||
| std::chrono::milliseconds hold_duration = std::chrono::milliseconds(250) | ||
| ) | ||
| : DetectorToFinder("CloseGameWatcher", hold_duration, console) | ||
| {} | ||
| }; | ||
|
|
||
|
|
||
|
|
||
|
|
||
| } | ||
| } | ||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we're now using visual inference, mashing X and B are no longer necessary, right? Should we remove them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yes. Commented below without seeing this one on top (on the otherwise identical code).