Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions SerialPrograms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,8 @@ file(GLOB MAIN_SOURCES
Source/NintendoSwitch/Inference/NintendoSwitch_DateReader.h
Source/NintendoSwitch/Inference/NintendoSwitch_DetectHome.cpp
Source/NintendoSwitch/Inference/NintendoSwitch_DetectHome.h
Source/NintendoSwitch/Inference/NintendoSwitch_SelectedSettingDetector.cpp
Source/NintendoSwitch/Inference/NintendoSwitch_SelectedSettingDetector.h
Source/NintendoSwitch/NintendoSwitch_ConsoleHandle.cpp
Source/NintendoSwitch/NintendoSwitch_ConsoleHandle.h
Source/NintendoSwitch/NintendoSwitch_MultiSwitchProgram.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
#include "PokemonSwSh/MaxLair/Inference/PokemonSwSh_MaxLair_Detect_PokemonSwapMenu.h"
#include "CommonTools/Images/ImageFilter.h"
#include "NintendoSwitch/Options/NintendoSwitch_ModelType.h"

#include "NintendoSwitch/Programs/NintendoSwitch_Navigation.h"

#include <QPixmap>
#include <QVideoFrame>
Expand Down Expand Up @@ -316,11 +316,18 @@ void TestProgram::program(MultiSwitchProgramEnvironment& env, CancellableScope&
ProControllerContext context(scope, console.pro_controller());
VideoOverlaySet overlays(overlay);


#if 1
home_to_date_time(console, context, false);
#endif

#if 0
// std::terminate();
ImageRGB32 image("20250503-121259857603.png");

image = filter_rgb32_brightness(image, COLOR_RED, false, 0x00ffff01, 0, 200);
image.save("temp.png");
#endif


#if 0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/* Detect Home
*
* From: https://github.com/PokemonAutomation/
*
*/

#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
#include "CommonTools/Images/SolidColorTest.h"
#include "NintendoSwitch_SelectedSettingDetector.h"

#include <iostream>
using std::cout;
using std::endl;

namespace PokemonAutomation{
namespace NintendoSwitch{

SelectedSettingWatcher::~SelectedSettingWatcher() = default;

SelectedSettingWatcher::SelectedSettingWatcher(ImageFloatBox selected_box, ImageFloatBox not_selected_box1, ImageFloatBox not_selected_box2)
: VisualInferenceCallback("SelectedSettingWatcher")
, m_selected_box(selected_box)
, m_not_selected_box1(not_selected_box1)
, m_not_selected_box2(not_selected_box2)
{}

void SelectedSettingWatcher::make_overlays(VideoOverlaySet& items) const{
items.add(COLOR_RED, m_selected_box);
items.add(COLOR_BLUE, m_not_selected_box1);
items.add(COLOR_BLUE, m_not_selected_box2);
}

bool is_white_theme(const ImageViewRGB32& screen){
ImageFloatBox window_top(0.60, 0.02, 0.35, 0.05);
ImageStats stats_window_top = image_stats(extract_box_reference(screen, window_top));
bool white_theme = stats_window_top.average.sum() > 600;
return white_theme;
}

bool SelectedSettingWatcher::process_frame(const ImageViewRGB32& screen, WallClock timestamp){

ImageStats stats_unselected_box1 = image_stats(extract_box_reference(screen, m_not_selected_box1));
double unselected1_average_sum = stats_unselected_box1.average.sum();
cout << "unselected_average_sum1: " << std::to_string(unselected1_average_sum) << endl;

ImageStats stats_unselected_box2 = image_stats(extract_box_reference(screen, m_not_selected_box2));
double unselected2_average_sum = stats_unselected_box2.average.sum();
cout << "unselected_average_sum2: " << std::to_string(unselected2_average_sum) << endl;

double average_sum_unselected_diff = std::abs(unselected1_average_sum - unselected2_average_sum);

ImageStats stats_selected_box = image_stats(extract_box_reference(screen, m_selected_box));
double selected_average_sum = stats_selected_box.average.sum();
cout << "selected_average_sum: " << std::to_string(selected_average_sum) << endl;

bool is_selected = false;
if (is_white_theme(screen)){ // light mode
// unselected should be brighter than selected
is_selected = selected_average_sum < std::min(unselected1_average_sum, unselected2_average_sum) - average_sum_unselected_diff - 20 ;
}else{ // dark mode
// selected should be brighter than unselected
is_selected = selected_average_sum > std::max(unselected1_average_sum, unselected2_average_sum) + average_sum_unselected_diff + 20;
}

return is_selected;
}






}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/* Selected Setting Detector
*
* From: https://github.com/PokemonAutomation/
*
*/

#ifndef PokemonAutomation_NintendoSwitch_SelectedSettingDetector_H
#define PokemonAutomation_NintendoSwitch_SelectedSettingDetector_H

#include "Common/Cpp/Color.h"
#include "CommonFramework/ImageTools/ImageBoxes.h"
#include "CommonTools/InferenceCallbacks/VisualInferenceCallback.h"
#include "CommonTools/VisualDetector.h"

namespace PokemonAutomation{
namespace NintendoSwitch{


class SelectedSettingWatcher : public VisualInferenceCallback{
public:
SelectedSettingWatcher(ImageFloatBox selected_box, ImageFloatBox not_selected_box1, ImageFloatBox not_selected_box2);
virtual ~SelectedSettingWatcher();

virtual void make_overlays(VideoOverlaySet& items) const override;

// return true if the area within the selected_box is highlighted, compared with the area within unselected_box
// This compares the brightness of the selected_box with the unselected_box.
// selected_box: the box where we expect the screen should be highlighted
// not_selected_box 1 and 2: the boxes where we expect the screen should NOT be highlighted. These acts as the control, for comparison.
// the average sum of selected_box should be greater than the absolute difference of average sum between unselected_box 1 and 2.
virtual bool process_frame(const ImageViewRGB32& screen, WallClock timestamp) override;


protected:
ImageFloatBox m_selected_box;
ImageFloatBox m_not_selected_box1;
ImageFloatBox m_not_selected_box2;
};


}
}
#endif

Loading