Skip to content

Commit f093997

Browse files
committed
Shiny detection should not be sensitive to resolution.
1 parent e6f9318 commit f093997

File tree

11 files changed

+21
-16
lines changed

11 files changed

+21
-16
lines changed

SerialPrograms/Source/CommonFramework/Globals.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace PokemonAutomation{
2626
const bool IS_BETA_VERSION = true;
2727
const int PROGRAM_VERSION_MAJOR = 0;
2828
const int PROGRAM_VERSION_MINOR = 54;
29-
const int PROGRAM_VERSION_PATCH = 7;
29+
const int PROGRAM_VERSION_PATCH = 8;
3030

3131
const std::string PROGRAM_VERSION_BASE =
3232
"v" + std::to_string(PROGRAM_VERSION_MAJOR) +

SerialPrograms/Source/CommonFramework/ImageTypes/ImageViewPlanar32.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class ImageViewPlanar32{
3535
PA_FORCE_INLINE size_t bytes_per_row () const{ return m_bytes_per_row; }
3636
PA_FORCE_INLINE size_t width () const{ return m_width; }
3737
PA_FORCE_INLINE size_t height () const{ return m_height; }
38+
PA_FORCE_INLINE size_t total_pixels () const{ return m_width * m_height; }
3839

3940
// Direct Pixel Access
4041
PA_FORCE_INLINE uint32_t pixel(size_t x, size_t y) const{

SerialPrograms/Source/CommonFramework/ImageTypes/ImageViewRGB32.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class ImageViewRGB32 : public ImageViewPlanar32{
3333
using ImageViewPlanar32::bytes_per_row;
3434
using ImageViewPlanar32::width;
3535
using ImageViewPlanar32::height;
36+
using ImageViewPlanar32::total_pixels;
3637

3738
// Direct Pixel Access
3839
PA_FORCE_INLINE uint32_t pixel(size_t x, size_t y) const{

SerialPrograms/Source/Pokemon/Pokemon_ShinySparkleSet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ void ShinySparkleTracker::make_overlays(VideoOverlaySet& items) const{
3131
}
3232
bool ShinySparkleTracker::process_frame(const ImageViewRGB32& frame, WallClock timestamp){
3333
ImageViewRGB32 image = extract_box_reference(frame, m_box);
34-
m_current_sparkles.read_from_image(image);
34+
m_current_sparkles.read_from_image(frame.total_pixels(), image);
3535
m_overlays.clear();
3636
m_current_sparkles.draw_boxes(m_overlays, frame, m_box);
3737
std::string log_str = m_current_sparkles.to_str();

SerialPrograms/Source/Pokemon/Pokemon_ShinySparkleSet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class ShinySparkleSet{
2323

2424
virtual std::string to_str() const = 0;
2525

26-
virtual void read_from_image(const ImageViewRGB32& image) = 0;
26+
virtual void read_from_image(size_t screen_area, const ImageViewRGB32& image) = 0;
2727
virtual void draw_boxes(
2828
VideoOverlaySet& overlays,
2929
const ImageViewRGB32& frame,

SerialPrograms/Source/PokemonBDSP/Inference/ShinyDetection/PokemonBDSP_ShinySparkleSet.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,12 @@ void ShinySparkleSetBDSP::update_alphas(){
8484

8585

8686

87-
ShinySparkleSetBDSP find_sparkles(WaterfillSession& session){
87+
ShinySparkleSetBDSP find_sparkles(size_t screen_area, WaterfillSession& session){
8888
ShinySparkleSetBDSP sparkles;
8989
auto finder = session.make_iterator(20);
9090
WaterfillObject object;
9191
while (finder->find_next(object, true)){
92-
PokemonSwSh::RadialSparkleDetector radial_sparkle(object);
92+
PokemonSwSh::RadialSparkleDetector radial_sparkle(screen_area, object);
9393
if (radial_sparkle.is_ball()){
9494
sparkles.balls.emplace_back(object.min_x, object.min_y, object.max_x, object.max_y);
9595
continue;
@@ -101,7 +101,7 @@ ShinySparkleSetBDSP find_sparkles(WaterfillSession& session){
101101
}
102102
return sparkles;
103103
}
104-
void ShinySparkleSetBDSP::read_from_image(const ImageViewRGB32& image){
104+
void ShinySparkleSetBDSP::read_from_image(size_t screen_area, const ImageViewRGB32& image){
105105
clear();
106106
if (!image){
107107
return;
@@ -121,7 +121,7 @@ void ShinySparkleSetBDSP::read_from_image(const ImageViewRGB32& image){
121121
double best_alpha = 0;
122122
for (PackedBinaryMatrix& matrix : matrices){
123123
session->set_source(matrix);
124-
ShinySparkleSetBDSP sparkles = find_sparkles(*session);
124+
ShinySparkleSetBDSP sparkles = find_sparkles(screen_area, *session);
125125
sparkles.update_alphas();
126126
double alpha = sparkles.alpha_overall();
127127
if (best_alpha < alpha){

SerialPrograms/Source/PokemonBDSP/Inference/ShinyDetection/PokemonBDSP_ShinySparkleSet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class ShinySparkleSetBDSP : public Pokemon::ShinySparkleSet{
2929
ShinySparkleSetBDSP extract_subbox(const ImagePixelBox& subbox) const;
3030

3131
virtual std::string to_str() const override;
32-
virtual void read_from_image(const ImageViewRGB32& image) override;
32+
virtual void read_from_image(size_t screen_area, const ImageViewRGB32& image) override;
3333

3434
virtual void draw_boxes(
3535
VideoOverlaySet& overlays,

SerialPrograms/Source/PokemonSwSh/Inference/ShinyDetection/PokemonSwSh_ShinySparkleSet.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,12 @@ void ShinySparkleSetSwSh::update_alphas(){
8484

8585

8686

87-
ShinySparkleSetSwSh find_sparkles(WaterfillSession& session){
87+
ShinySparkleSetSwSh find_sparkles(size_t screen_area, WaterfillSession& session){
8888
ShinySparkleSetSwSh sparkles;
8989
auto finder = session.make_iterator(20);
9090
WaterfillObject object;
9191
while (finder->find_next(object, true)){
92-
RadialSparkleDetector radial_sparkle(object);
92+
RadialSparkleDetector radial_sparkle(screen_area, object);
9393
if (radial_sparkle.is_ball()){
9494
sparkles.balls.emplace_back(object.min_x, object.min_y, object.max_x, object.max_y);
9595
continue;
@@ -109,7 +109,7 @@ ShinySparkleSetSwSh find_sparkles(WaterfillSession& session){
109109
}
110110
return sparkles;
111111
}
112-
void ShinySparkleSetSwSh::read_from_image(const ImageViewRGB32& image){
112+
void ShinySparkleSetSwSh::read_from_image(size_t screen_area, const ImageViewRGB32& image){
113113
clear();
114114
if (!image){
115115
return;
@@ -129,7 +129,7 @@ void ShinySparkleSetSwSh::read_from_image(const ImageViewRGB32& image){
129129
double best_alpha = 0;
130130
for (PackedBinaryMatrix& matrix : matrices){
131131
session->set_source(matrix);
132-
ShinySparkleSetSwSh sparkles = find_sparkles(*session);
132+
ShinySparkleSetSwSh sparkles = find_sparkles(screen_area, *session);
133133
sparkles.update_alphas();
134134
double alpha = sparkles.alpha_overall();
135135
if (best_alpha < alpha){

SerialPrograms/Source/PokemonSwSh/Inference/ShinyDetection/PokemonSwSh_ShinySparkleSet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class ShinySparkleSetSwSh : public Pokemon::ShinySparkleSet{
3131
double alpha_square() const{ return m_alpha_square; }
3232

3333
virtual std::string to_str() const override;
34-
virtual void read_from_image(const ImageViewRGB32& image) override;
34+
virtual void read_from_image(size_t screen_area, const ImageViewRGB32& image) override;
3535

3636
virtual void draw_boxes(
3737
VideoOverlaySet& overlays,

SerialPrograms/Source/PokemonSwSh/Inference/ShinyDetection/PokemonSwSh_SparkleDetectorRadial.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,16 @@ const double STAR_SPARKLE_ANGLE_TOLERANCE_DEGREES = 10.;
2626

2727

2828
RadialSparkleDetector::~RadialSparkleDetector(){}
29-
RadialSparkleDetector::RadialSparkleDetector(const WaterfillObject& object)
29+
RadialSparkleDetector::RadialSparkleDetector(size_t screen_area, const WaterfillObject& object)
3030
: m_object(object)
3131
{
3232
if (object.area < 20){
3333
return;
3434
}
35-
if (object.area > 10000){
35+
36+
double area_1080p = 1920 * 1080;
37+
double area_current = (double)screen_area;
38+
if (object.area * area_1080p > 10000 * area_current){
3639
return;
3740
}
3841

0 commit comments

Comments
 (0)