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,122 @@
/* Party Dialog Detectors
*
* From: https://github.com/PokemonAutomation/
*
*/

#include "CommonTools/Images/SolidColorTest.h"
#include "CommonTools/Images/ImageFilter.h"
#include "PokemonFRLG/PokemonFRLG_Settings.h"
#include "PokemonFRLG_PartyDialogs.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonFRLG{


PartySelectionDetector::PartySelectionDetector(Color color)
: m_dialog_right_box(0.955, 0.648, 0.010, 0.303)
, m_page_background_box(0.028, 0.500, 0.010, 0.250)
{}
void PartySelectionDetector::make_overlays(VideoOverlaySet& items) const{
const BoxOption& GAME_BOX = GameSettings::instance().GAME_BOX;
items.add(COLOR_RED, GAME_BOX.inner_to_outer(m_dialog_right_box));
items.add(COLOR_RED, GAME_BOX.inner_to_outer(m_page_background_box));
}
bool PartySelectionDetector::detect(const ImageViewRGB32& screen){
ImageViewRGB32 game_screen = extract_box_reference(screen, GameSettings::instance().GAME_BOX);

//Dialog is white
ImageViewRGB32 dialog_right_image = extract_box_reference(game_screen, m_dialog_right_box);

//Menu background is teal
ImageViewRGB32 menu_background_image = extract_box_reference(game_screen, m_page_background_box);

if (is_white(dialog_right_image)
&& is_solid(menu_background_image, { 0.020, 0.424, 0.412 }, 0.25, 20) //5, 108, 105 teal
){
return true;
}
return false;
}


PartyLevelUpDetector::PartyLevelUpDetector(Color color, PartyLevelUpDialog dialog_type)
: dialog_type(dialog_type)
, m_border_top_box(0.619231, 0.023038, 0.362179, 0.001923) // gray (120, 115, 140)
, m_border_right_box(0.982692, 0.025923, 0.001923, 0.597115)
, m_dialog_top_box(0.626282, 0.042492, 0.341026, 0.006175) // white
, m_dialog_right_box(0.967949, 0.050923, 0.003846, 0.550962)
, m_plus_box(0.862663, 0.051852, 0.034267, 0.553560)
{}
void PartyLevelUpDetector::make_overlays(VideoOverlaySet& items) const{
const BoxOption& GAME_BOX = GameSettings::instance().GAME_BOX;
items.add(COLOR_RED, GAME_BOX.inner_to_outer(m_border_top_box));
items.add(COLOR_RED, GAME_BOX.inner_to_outer(m_border_right_box));
items.add(COLOR_RED, GAME_BOX.inner_to_outer(m_dialog_top_box));
items.add(COLOR_RED, GAME_BOX.inner_to_outer(m_dialog_right_box));
}
bool PartyLevelUpDetector::detect(const ImageViewRGB32& screen){
ImageViewRGB32 game_screen = extract_box_reference(screen, GameSettings::instance().GAME_BOX);

ImageViewRGB32 border_top_image = extract_box_reference(game_screen, m_border_top_box);
ImageViewRGB32 border_right_image = extract_box_reference(game_screen, m_border_right_box);

ImageViewRGB32 dialog_top_image = extract_box_reference(game_screen, m_dialog_top_box);
ImageViewRGB32 dialog_right_image = extract_box_reference(game_screen, m_dialog_right_box);

//Plus box is not solid white on the first screen, but is white on the second one
ImageViewRGB32 plus_image = extract_box_reference(game_screen, m_plus_box);
bool good_plus_image = (
dialog_type == PartyLevelUpDialog::either
|| (dialog_type == PartyLevelUpDialog::plus && !is_white(plus_image))
|| (dialog_type == PartyLevelUpDialog::stats && is_white(plus_image))
);

if (is_solid(border_top_image, { 0.320, 0.307, 0.373 }, 0.25, 20)
&& is_solid(border_right_image, { 0.320, 0.307, 0.373 }, 0.25, 20)
&& is_white(dialog_top_image)
&& is_white(dialog_right_image)
&& good_plus_image
){
return true;
}
return false;
}

PartyMoveLearnDetector::PartyMoveLearnDetector(Color color)
: m_border_top_box(0.685096, 0.422836, 0.229327, 0.002163) // gray (120, 115, 140)
, m_border_right_box(0.916346, 0.426442, 0.001442, 0.245913)
, m_dialog_top_box(0.699038, 0.445913, 0.200000, 0.006490) // white
, m_dialog_right_box(0.899519, 0.454567, 0.004327, 0.194712)
{}
void PartyMoveLearnDetector::make_overlays(VideoOverlaySet& items) const{
const BoxOption& GAME_BOX = GameSettings::instance().GAME_BOX;
items.add(COLOR_RED, GAME_BOX.inner_to_outer(m_border_top_box));
items.add(COLOR_RED, GAME_BOX.inner_to_outer(m_border_right_box));
items.add(COLOR_RED, GAME_BOX.inner_to_outer(m_dialog_top_box));
items.add(COLOR_RED, GAME_BOX.inner_to_outer(m_dialog_right_box));
}
bool PartyMoveLearnDetector::detect(const ImageViewRGB32& screen){
ImageViewRGB32 game_screen = extract_box_reference(screen, GameSettings::instance().GAME_BOX);

ImageViewRGB32 border_top_image = extract_box_reference(game_screen, m_border_top_box);
ImageViewRGB32 border_right_image = extract_box_reference(game_screen, m_border_right_box);

ImageViewRGB32 dialog_top_image = extract_box_reference(game_screen, m_dialog_top_box);
ImageViewRGB32 dialog_right_image = extract_box_reference(game_screen, m_dialog_right_box);

if (is_solid(border_top_image, { 0.320, 0.307, 0.373 }, 0.25, 20)
&& is_solid(border_right_image, { 0.320, 0.307, 0.373 }, 0.25, 20)
&& is_white(dialog_top_image)
&& is_white(dialog_right_image)
){
return true;
}
return false;
}


}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/* Party Dialog Detectors
*
* From: https://github.com/PokemonAutomation/
*
*/

#ifndef PokemonAutomation_PokemonFRLG_PartyDialogs_H
#define PokemonAutomation_PokemonFRLG_PartyDialogs_H

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

namespace PokemonAutomation{
class CancellableScope;
class VideoFeed;
namespace NintendoSwitch{
namespace PokemonFRLG{


// The Party menu has a white box in the bottom right corner when a Pokemon is selected
// The background around the edges is dark teal/navy
class PartySelectionDetector : public StaticScreenDetector{
public:
PartySelectionDetector(Color color);

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

private:
ImageFloatBox m_dialog_right_box;
ImageFloatBox m_page_background_box;
};
class PartySelectionWatcher : public DetectorToFinder<PartySelectionDetector>{
public:
PartySelectionWatcher(Color color)
: DetectorToFinder("PartySelectionWatcher", std::chrono::milliseconds(250), color)
{}
};

enum class PartyLevelUpDialog{
plus,
stats,
either
};

class PartyLevelUpDetector : public StaticScreenDetector{
public:
PartyLevelUpDetector(Color color, PartyLevelUpDialog dialog_type);

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

private:
PartyLevelUpDialog dialog_type;
ImageFloatBox m_border_top_box;
ImageFloatBox m_border_right_box;
ImageFloatBox m_dialog_top_box;
ImageFloatBox m_dialog_right_box;
ImageFloatBox m_plus_box;
};
class PartyLevelUpWatcher : public DetectorToFinder<PartyLevelUpDetector>{
public:
PartyLevelUpWatcher(Color color, PartyLevelUpDialog dialog_type)
: DetectorToFinder("BattleLevelUpWatcher", std::chrono::milliseconds(250), color, dialog_type)
{}
};


class PartyMoveLearnDetector : public StaticScreenDetector{
public:
PartyMoveLearnDetector(Color color);

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

private:
ImageFloatBox m_border_top_box;
ImageFloatBox m_border_right_box;
ImageFloatBox m_dialog_top_box;
ImageFloatBox m_dialog_right_box;
};
class PartyMoveLearnWatcher : public DetectorToFinder<PartyMoveLearnDetector>{
public:
PartyMoveLearnWatcher(Color color)
: DetectorToFinder("PartyMoveLearnWatcher", std::chrono::milliseconds(250), color)
{}
};



}
}
}

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

#include "Common/Cpp/Exceptions.h"
#include "CommonFramework/ImageTools/ImageBoxes.h"
#include "CommonFramework/ImageTypes/ImageRGB32.h"
#include "CommonFramework/ImageTools/ImageStats.h"
#include "CommonFramework/ImageTypes/ImageViewRGB32.h"
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
#include "CommonTools/Images/SolidColorTest.h"
#include "CommonTools/Images/ImageFilter.h"
#include "CommonTools/Images/WaterfillUtilities.h"
#include "PokemonFRLG_BagDetector.h"


namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonFRLG{


BagDetector::BagDetector(Color color)
: m_bag_shadow_box(0.130769, 0.594471, 0.070192, 0.015865)
, m_pocket_underline_box(0.043269, 0.137259, 0.279808, 0.005769)
, m_menu_top_box(0.029808, 0.029086, 0.947115, 0.003606)
, m_menu_right_box(0.977404, 0.034134, 0.005288, 0.597837)
{}
void BagDetector::make_overlays(VideoOverlaySet& items) const{
const BoxOption& GAME_BOX = GameSettings::instance().GAME_BOX;
items.add(COLOR_RED, GAME_BOX.inner_to_outer(m_bag_shadow_box)); // Gray RGB(159, 159, 159)
items.add(COLOR_RED, GAME_BOX.inner_to_outer(m_pocket_underline_box)); // Orange RGB(255, 152, 50)
items.add(COLOR_RED, GAME_BOX.inner_to_outer(m_menu_top_box)); // Yellow RGB(255, 225, 93)
items.add(COLOR_RED, GAME_BOX.inner_to_outer(m_menu_right_box)); // Yellow

}
bool BagDetector::detect(const ImageViewRGB32& screen){
ImageViewRGB32 game_screen = extract_box_reference(screen, GameSettings::instance().GAME_BOX);

ImageViewRGB32 bag_shadow_image = extract_box_reference(game_screen, m_bag_shadow_box);
ImageViewRGB32 pocket_underline_image = extract_box_reference(game_screen, m_pocket_underline_box);
ImageViewRGB32 menu_top_image = extract_box_reference(game_screen, m_menu_top_box);
ImageViewRGB32 menu_right_image = extract_box_reference(game_screen, m_menu_right_box);


if ( is_solid(bag_shadow_image, { 0.333, 0.333, 0.333 }, 0.25, 20)
&& is_solid(pocket_underline_image, { 0.558, 0.333, 0.109 }, 0.25, 20)
&& is_solid(menu_top_image, { 0.445, 0.393, 0.162 }, 0.25, 20)
&& is_solid(menu_right_image, { 0.445, 0.393, 0.162 }, 0.25, 20)
){
return true;
}
return false;
}



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

#ifndef PokemonAutomation_PokemonFRLG_BagDetector_H
#define PokemonAutomation_PokemonFRLG_BagDetector_H

#include <chrono>
#include "Common/Cpp/Color.h"
#include "CommonFramework/ImageTools/ImageBoxes.h"
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
#include "CommonTools/VisualDetector.h"
#include "CommonTools/InferenceCallbacks/VisualInferenceCallback.h"
#include "PokemonFRLG/PokemonFRLG_Settings.h"

namespace PokemonAutomation{
class CancellableScope;
class VideoFeed;
namespace NintendoSwitch{
namespace PokemonFRLG{

class BagDetector : public StaticScreenDetector{
public:
BagDetector(Color color);

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

private:
ImageFloatBox m_bag_shadow_box;
ImageFloatBox m_pocket_underline_box;
ImageFloatBox m_menu_top_box;
ImageFloatBox m_menu_right_box;
};
class BagWatcher : public DetectorToFinder<BagDetector>{
public:
BagWatcher(Color color)
: DetectorToFinder("BagWatcher", std::chrono::milliseconds(250), color)
{}
};



}
}
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -47,31 +47,6 @@ bool PartyMenuDetector::detect(const ImageViewRGB32& screen){
return false;
}

PartySelectionDetector::PartySelectionDetector(Color color)
: m_dialog_right_box(0.955, 0.648, 0.010, 0.303)
, m_page_background_box(0.028, 0.500, 0.010, 0.250)
{}
void PartySelectionDetector::make_overlays(VideoOverlaySet& items) const{
const BoxOption& GAME_BOX = GameSettings::instance().GAME_BOX;
items.add(COLOR_RED, GAME_BOX.inner_to_outer(m_dialog_right_box));
items.add(COLOR_RED, GAME_BOX.inner_to_outer(m_page_background_box));
}
bool PartySelectionDetector::detect(const ImageViewRGB32& screen){
ImageViewRGB32 game_screen = extract_box_reference(screen, GameSettings::instance().GAME_BOX);

//Dialog is white
ImageViewRGB32 dialog_right_image = extract_box_reference(game_screen, m_dialog_right_box);

//Menu background is teal
ImageViewRGB32 menu_background_image = extract_box_reference(game_screen, m_page_background_box);

if (is_white(dialog_right_image)
&& is_solid(menu_background_image, { 0.020, 0.424, 0.412 }, 0.25, 20) //5, 108, 105 teal
){
return true;
}
return false;
}

ImageFloatBox PartySlotDetector::party_slot_boxes(PartySlot position){
switch (position){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,6 @@ class PartyMenuWatcher : public DetectorToFinder<PartyMenuDetector>{
{}
};

// The Party menu has a white box in the bottom right corner when a Pokemon is selected
// The background around the edges is dark teal/navy
class PartySelectionDetector : public StaticScreenDetector{
public:
PartySelectionDetector(Color color);

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

private:
ImageFloatBox m_dialog_right_box;
ImageFloatBox m_page_background_box;
};
class PartySelectionWatcher : public DetectorToFinder<PartySelectionDetector>{
public:
PartySelectionWatcher(Color color)
: DetectorToFinder("PartySelectionWatcher", std::chrono::milliseconds(250), color)
{}
};


class PartySlotDetector : public StaticScreenDetector{
public:
Expand Down
Loading