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
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,55 @@
* From: https://github.com/PokemonAutomation/
*
*/

#include "Kernels/Waterfill/Kernels_Waterfill_Types.h"
#include "CommonTools/Images/WaterfillUtilities.h"
#include "CommonTools/ImageMatch/WaterfillTemplateMatcher.h"
#include "PokemonLZA_MapDetector.h"
#include "PokemonLZA_MapIconDetector.h"

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

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonLZA{

namespace{

// Matches the cyan "Travel Spots" feather icon shown next to the Y button on the map screen.
class TravelSpotMatcher : public ImageMatch::WaterfillTemplateMatcher{
public:
TravelSpotMatcher()
: WaterfillTemplateMatcher(
"PokemonLZA/MapIcons/TravelSpotIcon.png",
Color(0xff004080),
Color(0xff80ffff),
50
)
{}

static const TravelSpotMatcher& instance(){
static TravelSpotMatcher matcher;
return matcher;
}

virtual bool check_image(Resolution input_resolution, const ImageViewRGB32& image) const override{
size_t min_w = 8 * input_resolution.width / 3840;
size_t min_h = 8 * input_resolution.height / 2160;
return image.width() >= min_w && image.height() >= min_h;
}
};



} // anonymous namespace



MapDetector::MapDetector(Color color, VideoOverlay* overlay)
: m_b_button(
color,
ButtonType::ButtonB,
{0.760730, 0.937023, 0.241416, 0.064885},
overlay
)
: m_color(color)
, m_travel_icon(0.040000, 0.235000, 0.030000, 0.068500)
, m_x_button(
color,
ButtonType::ButtonX,
Expand All @@ -35,13 +67,14 @@ MapDetector::MapDetector(Color color, VideoOverlay* overlay)
{}

void MapDetector::make_overlays(VideoOverlaySet& items) const{
m_b_button.make_overlays(items);
items.add(m_color, m_travel_icon);
m_x_button.make_overlays(items);
m_y_button.make_overlays(items);
}

bool MapDetector::detect(const ImageViewRGB32& screen){
const bool detected = m_b_button.detect(screen)
// cout << "MapDetector::detect()" << endl;
const bool detected = detect_travel_spot(screen)
&& m_x_button.detect(screen)
&& m_y_button.detect(screen);

Expand All @@ -53,6 +86,31 @@ bool MapDetector::detect(const ImageViewRGB32& screen){
return detected;
}


bool MapDetector::detect_travel_spot(const ImageViewRGB32& screen){
// Progressive cyan filters to handle capture-card color variance.
static const std::vector<std::pair<uint32_t, uint32_t>> CYAN_FILTERS{
// Brighter cyan/teal.
{0xff004898, 0xff70ffff},
{0xff003878, 0xff80ffff},
// Darker/desaturated cyan seen in some captures (e.g. 1080p hyperspace_True).
{0xff002860, 0xff90ffff},
{0xff001c50, 0xffa0ffff},
};

double rel = screen.height() / 2160.0;
size_t min_area = size_t(50.0 * rel * rel);

return match_template_by_waterfill(
screen.size(),
extract_box_reference(screen, m_travel_icon),
TravelSpotMatcher::instance(),
CYAN_FILTERS,
{min_area, SIZE_MAX},
100.0,
[](Kernels::Waterfill::WaterfillObject&) -> bool{ return true; }
);
}
std::vector<DetectedBox> MapDetector::detected_map_icons() const{
std::vector<DetectedBox> ret;
for (MapIconDetector* detector : m_map_icon_detectors){
Expand All @@ -64,9 +122,7 @@ std::vector<DetectedBox> MapDetector::detected_map_icons() const{
return ret;
}


void MapDetector::reset_state(){
m_b_button.reset_state();
m_x_button.reset_state();
m_y_button.reset_state();
for (MapIconDetector* detector : m_map_icon_detectors){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ class MapDetector : public StaticScreenDetector{
void reset_state() override;

private:
ButtonDetector m_b_button;
bool detect_travel_spot(const ImageViewRGB32& screen);

private:
Color m_color;
ImageFloatBox m_travel_icon;
ButtonDetector m_x_button;
ButtonDetector m_y_button;
std::vector<MapIconDetector*> m_map_icon_detectors;
Expand Down
Loading