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 @@ -1710,6 +1710,8 @@ file(GLOB MAIN_SOURCES
Source/PokemonSV/Inference/PokemonSV_TutorialDetector.h
Source/PokemonSV/Inference/PokemonSV_WhiteButtonDetector.cpp
Source/PokemonSV/Inference/PokemonSV_WhiteButtonDetector.h
Source/PokemonSV/Inference/PokemonSV_WhiteTriangleDetector.cpp
Source/PokemonSV/Inference/PokemonSV_WhiteTriangleDetector.h
Source/PokemonSV/Inference/PokemonSV_ZeroGateWarpPromptDetector.cpp
Source/PokemonSV/Inference/PokemonSV_ZeroGateWarpPromptDetector.h
Source/PokemonSV/Inference/Tera/PokemonSV_TeraCardDetector.cpp
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/* White Triangle Detector
*
* From: https://github.com/PokemonAutomation/
*
*/

#include "Common/Cpp/Containers/FixedLimitVector.tpp"
#include "CommonFramework/ImageTypes/ImageViewRGB32.h"
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
#include "CommonTools/Images/WaterfillUtilities.h"
#include "CommonTools/ImageMatch/WaterfillTemplateMatcher.h"
#include "Kernels/Waterfill/Kernels_Waterfill_Types.h"
#include "PokemonSV_WhiteTriangleDetector.h"

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

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonSV{


class WhiteTriangleMatcher : public ImageMatch::WaterfillTemplateMatcher{
public:

WhiteTriangleMatcher() : WaterfillTemplateMatcher(
"PokemonSV/WhiteTriangleIcon-Template.png", Color(200,200,200), Color(255, 255, 255), 50
){
m_aspect_ratio_lower = 0.8;
m_aspect_ratio_upper = 1.2;
m_area_ratio_lower = 0.9;
m_area_ratio_upper = 1.4;

}

static const ImageMatch::WaterfillTemplateMatcher& instance(){
static WhiteTriangleMatcher matcher;
return matcher;
}
};


WhiteTriangleDetector::~WhiteTriangleDetector() = default;

WhiteTriangleDetector::WhiteTriangleDetector(Color color, const ImageFloatBox& box)
: m_color(color)
, m_box(box)
{}

void WhiteTriangleDetector::make_overlays(VideoOverlaySet& items) const{
items.add(m_color, m_box);
}


bool WhiteTriangleDetector::detect(const ImageViewRGB32& screen) {
const std::vector<std::pair<uint32_t, uint32_t>> filters = {
{combine_rgb(240, 240, 240), combine_rgb(255, 255, 255)},
{combine_rgb(220, 220, 220), combine_rgb(240, 240, 240)},
{combine_rgb(200, 200, 200), combine_rgb(220, 220, 220)},
{combine_rgb(190, 190, 190), combine_rgb(210, 210, 210)},

};

const double rmsd_threshold = 50.0;

const double min_object_size = 100.0;

const double screen_rel_size = (screen.height() / 1080.0);
const size_t min_size = size_t(screen_rel_size * screen_rel_size * min_object_size);

bool is_found = false;
match_template_by_waterfill(
extract_box_reference(screen, m_box),
WhiteTriangleMatcher::instance(),
filters,
{min_size, SIZE_MAX},
rmsd_threshold,
[&](Kernels::Waterfill::WaterfillObject& object) -> bool {
is_found = true;
return true;
}
);

return is_found;
}



// WhiteTriangleWatcher::~WhiteTriangleWatcher() = default;

// WhiteTriangleWatcher::WhiteTriangleWatcher(Color color, const ImageFloatBox& box)
// : VisualInferenceCallback("WhiteTriangleWatcher")
// , m_detector(color, box)
// {}

// void WhiteTriangleWatcher::make_overlays(VideoOverlaySet& items) const{
// m_detector.make_overlays(items);
// }

// bool WhiteTriangleWatcher::process_frame(const ImageViewRGB32& screen, WallClock timestamp){
// return m_detector.detect(screen);
// }








}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/* White Triangle Detector

* From: https://github.com/PokemonAutomation/
*
*/

#ifndef PokemonAutomation_PokemonSV_WhiteTriangleDetector_H
#define PokemonAutomation_PokemonSV_WhiteTriangleDetector_H

#include <vector>
#include "Common/Cpp/Color.h"
#include "Common/Cpp/Containers/FixedLimitVector.h"
#include "CommonFramework/ImageTools/ImageBoxes.h"
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
#include "CommonTools/InferenceCallbacks/VisualInferenceCallback.h"
#include "CommonTools/VisualDetector.h"

namespace PokemonAutomation{

class VideoOverlaySet;
class VideoOverlay;
class OverlayBoxScope;

namespace NintendoSwitch{
namespace PokemonSV{

class WhiteTriangleDetector : public StaticScreenDetector{
public:
WhiteTriangleDetector(Color color, const ImageFloatBox& box);
virtual ~WhiteTriangleDetector();

virtual void make_overlays(VideoOverlaySet& items) const override;
virtual bool detect(const ImageViewRGB32& screen) override;

protected:
Color m_color;
ImageFloatBox m_box;
};



class WhiteTriangleWatcher : public DetectorToFinder<WhiteTriangleDetector>{
public:
WhiteTriangleWatcher(
Color color,
const ImageFloatBox& box,
std::chrono::milliseconds hold_duration = std::chrono::milliseconds(250)
)
: DetectorToFinder("WhiteTriangleDetector", hold_duration, color, box)
{}
};





}
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
* From: https://github.com/PokemonAutomation/
*
*/
#include "CommonFramework/Exceptions/OperationFailedException.h"
#include "CommonTools/Async/InferenceRoutines.h"


#include "CommonFramework/GlobalSettingsPanel.h"
#include "CommonFramework/Notifications/ProgramNotifications.h"
Expand Down Expand Up @@ -84,7 +87,7 @@ std::vector<std::unique_ptr<AutoStory_Segment>> make_autoStory_segment_list(){
segment_list.emplace_back(std::make_unique<AutoStory_Segment_19>());
segment_list.emplace_back(std::make_unique<AutoStory_Segment_20>());
segment_list.emplace_back(std::make_unique<AutoStory_Segment_21>());
// segment_list.emplace_back(std::make_unique<AutoStory_Segment_22>());
segment_list.emplace_back(std::make_unique<AutoStory_Segment_22>());
// segment_list.emplace_back(std::make_unique<AutoStory_Segment_23>());
// segment_list.emplace_back(std::make_unique<AutoStory_Segment_24>());

Expand Down Expand Up @@ -638,6 +641,11 @@ void AutoStory::test_checkpoints(
checkpoint_list.push_back([&](){checkpoint_53(env, context, notif_status_update, stats);});
checkpoint_list.push_back([&](){checkpoint_54(env, context, notif_status_update, stats);});
checkpoint_list.push_back([&](){checkpoint_55(env, context, notif_status_update, stats);});
checkpoint_list.push_back([&](){checkpoint_56(env, context, notif_status_update, stats);});
checkpoint_list.push_back([&](){checkpoint_57(env, context, notif_status_update, stats);});
checkpoint_list.push_back([&](){checkpoint_58(env, context, notif_status_update, stats);});
checkpoint_list.push_back([&](){checkpoint_59(env, context, notif_status_update, stats);});
checkpoint_list.push_back([&](){checkpoint_60(env, context, notif_status_update, stats);});


for (int checkpoint = start; checkpoint <= end; checkpoint++){
Expand Down Expand Up @@ -798,7 +806,8 @@ void AutoStory::test_code(SingleSwitchProgramEnvironment& env, ProControllerCont
// 128, 0, 60, 10, false);

DirectionDetector direction;



return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@
#include "CommonTools/Async/InferenceRoutines.h"

#include "CommonFramework/Exceptions/OperationFailedException.h"
#include "CommonFramework/VideoPipeline/VideoOverlay.h"
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
#include "PokemonSV/Inference/Overworld/PokemonSV_DirectionDetector.h"
#include "PokemonSV/Programs/PokemonSV_GameEntry.h"
#include "PokemonSV/Programs/PokemonSV_SaveGame.h"
#include "PokemonSV/Programs/PokemonSV_MenuNavigation.h"
#include "PokemonSV/Programs/PokemonSV_WorldNavigation.h"
#include "PokemonSV_AutoStoryTools.h"
Expand Down
Loading