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
@@ -0,0 +1,65 @@
/* Alpha Detector
*
* From: https://github.com/PokemonAutomation/
*
*/

#include "CommonFramework/ImageTools/ImageStats.h"
#include "CommonFramework/GlobalAutoPaths.h"
#include "CommonFramework/ImageTypes/ImageRGB32.h"
#include "Tests/TestUtils.h"
#include "PokemonHome_AlphaDetector.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonHome{


AlphaDetector::AlphaDetector(Color color, VideoOverlay* overlay)
: m_color(color)
, m_overlay(overlay)
, m_box(0.787, 0.095, 0.024, 0.046)
{}

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

bool AlphaDetector::detect(const ImageViewRGB32& screen){
const bool found = image_stddev(extract_box_reference(screen, m_box)).sum() > 40;
if (m_overlay){
if (found){
m_last_detected_box.emplace(*m_overlay, m_box, COLOR_GREEN);
}else{
m_last_detected_box.reset();
}
}
return found;
}

class Test_AlphaDetector : public UnitTest{
public:
Test_AlphaDetector(const std::string& image, bool expected)
: UnitTest("PokemonHome::AlphaDetector - " + image)
, m_image(UNIT_TEST_RESOURCE_PATH() + image)
, m_expected(expected)
{}

virtual UnitTestResult run(Logger& logger, CancellableScope& scope) const override{
ImageRGB32 image(m_image);
AlphaDetector detector;
return detector.detect(image) == m_expected;
}

private:
std::string m_image;
bool m_expected;
};

void add_tests_AlphaDetector(UnitTestDatabase& database){
}


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

#ifndef PokemonAutomation_PokemonHome_AlphaDetector_H
#define PokemonAutomation_PokemonHome_AlphaDetector_H

#include <optional>
#include "Common/Cpp/TestRunners/UnitTestDatabase.h"
#include "CommonFramework/ImageTools/ImageBoxes.h"
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
#include "CommonTools/VisualDetector.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonHome{


class AlphaDetector : public StaticScreenDetector{
public:
AlphaDetector(Color color = COLOR_RED, VideoOverlay* overlay = nullptr);

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

private:
Color m_color;
VideoOverlay* m_overlay;
ImageFloatBox m_box;
std::optional<OverlayBoxScope> m_last_detected_box;
};

void add_tests_AlphaDetector(UnitTestDatabase& database);


}
}
}
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/* Shiny Detector
*
* From: https://github.com/PokemonAutomation/
*
*/

#include "CommonFramework/ImageTools/ImageStats.h"
#include "CommonFramework/GlobalAutoPaths.h"
#include "CommonFramework/ImageTypes/ImageRGB32.h"
#include "Tests/TestUtils.h"
#include "PokemonHome_ShinyDetector.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonHome{


ShinyDetector::ShinyDetector(Color color, VideoOverlay* overlay)
: m_color(color)
, m_overlay(overlay)
, m_box(0.702, 0.09, 0.04, 0.06)
{}

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

bool ShinyDetector::detect(const ImageViewRGB32& screen){
const bool found = image_stddev(extract_box_reference(screen, m_box)).sum() > 30;
if (m_overlay){
if (found){
m_last_detected_box.emplace(*m_overlay, m_box, COLOR_GREEN);
}else{
m_last_detected_box.reset();
}
}
return found;
}

class Test_ShinyDetector : public UnitTest{
public:
Test_ShinyDetector(const std::string& image, bool expected)
: UnitTest("PokemonHome::ShinyDetector - " + image)
, m_image(UNIT_TEST_RESOURCE_PATH() + image)
, m_expected(expected)
{}

virtual UnitTestResult run(Logger& logger, CancellableScope& scope) const override{
ImageRGB32 image(m_image);
ShinyDetector detector;
return detector.detect(image) == m_expected;
}

private:
std::string m_image;
bool m_expected;
};

void add_tests_ShinyDetector(UnitTestDatabase& database){
}


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

#ifndef PokemonAutomation_PokemonHome_ShinyDetector_H
#define PokemonAutomation_PokemonHome_ShinyDetector_H

#include <optional>
#include "Common/Cpp/TestRunners/UnitTestDatabase.h"
#include "CommonFramework/ImageTools/ImageBoxes.h"
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
#include "CommonTools/VisualDetector.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonHome{


class ShinyDetector : public StaticScreenDetector{
public:
ShinyDetector(Color color = COLOR_RED, VideoOverlay* overlay = nullptr);

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

private:
Color m_color;
VideoOverlay* m_overlay;
ImageFloatBox m_box;
std::optional<OverlayBoxScope> m_last_detected_box;
};

void add_tests_ShinyDetector(UnitTestDatabase& database);


}
}
}
#endif
Loading
Loading