Skip to content

Commit 581748d

Browse files
committed
Improve reliability of Y-COMM detector.
1 parent bf5ba86 commit 581748d

5 files changed

Lines changed: 21 additions & 17 deletions

File tree

SerialPrograms/Source/NintendoSwitch/DevPrograms/TestProgramSwitch.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,11 @@ void TestProgram::program(MultiSwitchProgramEnvironment& env, CancellableScope&
335335

336336

337337
auto snapshot = feed.snapshot();
338+
YCommMenuDetector detector(true);
339+
detector.make_overlays(overlays);
340+
cout << detector.detect(snapshot) << endl;
338341

342+
#if 0
339343
SelectionArrowFinder arrow(overlay, {0.462377, 0.332039, 0.388222, 0.640777});
340344

341345
cout << arrow.detect(snapshot) << endl;
@@ -344,6 +348,7 @@ void TestProgram::program(MultiSwitchProgramEnvironment& env, CancellableScope&
344348
if (!arrows.empty()){
345349
cout << arrows[0].y << endl;
346350
}
351+
#endif
347352

348353
// WhiteDialogBoxDetector detector;
349354
// detector.make_overlays(overlays);

SerialPrograms/Source/PokemonSwSh/Inference/PokemonSwSh_YCommDetector.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ namespace PokemonSwSh{
2323

2424

2525
YCommMenuDetector::YCommMenuDetector(bool is_on)
26-
: VisualInferenceCallback("YCommMenuDetector")
27-
, m_is_on(is_on)
26+
: m_is_on(is_on)
2827
, m_top(0.600, 0.020, 0.100, 0.040)
2928
, m_bottom(0.100, 0.970, 0.400, 0.020)
3029
{}
@@ -37,20 +36,16 @@ bool YCommMenuDetector::detect(const ImageViewRGB32& screen){
3736
ImageStats bottom = image_stats(extract_box_reference(screen, m_bottom));
3837
// cout << bottom.average << bottom.stddev << endl;
3938
if (!is_black(bottom)){
40-
return false;
39+
return !m_is_on;
4140
}
4241

4342
ImageStats top = image_stats(extract_box_reference(screen, m_top));
4443
// cout << top.average << top.stddev << endl;
45-
if (!is_solid(top, {0.0819777, 0.124031, 0.793991}, 0.25)){
46-
return false;
44+
if (!is_solid(top, {0.0819777, 0.124031, 0.793991}, 0.30)){
45+
return !m_is_on;
4746
}
4847

49-
return true;
50-
}
51-
52-
bool YCommMenuDetector::process_frame(const ImageViewRGB32& frame, WallClock timestamp){
53-
return m_is_on ? detect(frame) : !detect(frame);
48+
return m_is_on;
5449
}
5550

5651

SerialPrograms/Source/PokemonSwSh/Inference/PokemonSwSh_YCommDetector.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,24 @@ namespace NintendoSwitch{
2020
namespace PokemonSwSh{
2121

2222

23-
class YCommMenuDetector : public VisualInferenceCallback{
23+
class YCommMenuDetector : public StaticScreenDetector{
2424
public:
2525
YCommMenuDetector(bool is_on);
2626

27-
bool detect(const ImageViewRGB32& screen);
28-
2927
virtual void make_overlays(VideoOverlaySet& items) const override;
30-
virtual bool process_frame(const ImageViewRGB32& frame, WallClock timestamp) override final;
28+
virtual bool detect(const ImageViewRGB32& screen) override;
3129

3230
private:
3331
bool m_is_on;
3432
ImageFloatBox m_top;
3533
ImageFloatBox m_bottom;
3634
};
35+
class YCommMenuWatcher : public DetectorToFinder<YCommMenuDetector>{
36+
public:
37+
YCommMenuWatcher(bool is_on)
38+
: DetectorToFinder("YCommMenuWatcher", std::chrono::milliseconds(250), is_on)
39+
{}
40+
};
3741

3842
// Detect the blue Y letter as the Y Comm symbol in the lower left corner of the screen on the
3943
// overworld, when Y Comm is active.

SerialPrograms/Source/PokemonSwSh/Programs/PokemonSwSh_Internet.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ bool connect_to_internet_with_inference(
2828
bool ok = true;
2929
// cout << "Waiting for Y-COMM to open..." << endl;
3030
for (size_t attempts = 0;;){
31-
YCommMenuDetector detector(true);
31+
YCommMenuWatcher detector(true);
3232
if (detector.detect(stream.video().snapshot())){
3333
stream.log("Y-COMM detected.");
3434
break;
@@ -69,7 +69,7 @@ bool connect_to_internet_with_inference(
6969
// cout << "Waiting for Y-COMM to close..." << endl;
7070
// Mash B until you leave Y-COMM.
7171
{
72-
YCommMenuDetector detector(false);
72+
YCommMenuWatcher detector(false);
7373
int result = run_until<ProControllerContext>(
7474
stream, context,
7575
[&](ProControllerContext& context){

SerialPrograms/Source/Tests/PokemonSwSh_Tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ std::vector<ImagePixelBox> find_selection_arrows(const ImageViewRGB32& image, si
3939
using namespace NintendoSwitch::PokemonSwSh;
4040

4141
int test_pokemonSwSh_YCommMenuDetector(const ImageViewRGB32& image, bool target){
42-
YCommMenuDetector detector(true);
42+
YCommMenuWatcher detector(true);
4343

4444
bool result = detector.process_frame(image, current_time());
4545
TEST_RESULT_EQUAL(result, target);

0 commit comments

Comments
 (0)