Skip to content

Commit b0eee5f

Browse files
committed
shiny dex num detector
1 parent cd769f9 commit b0eee5f

File tree

2 files changed

+100
-0
lines changed

2 files changed

+100
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/* Shiny Number Detector
2+
*
3+
* From: https://github.com/PokemonAutomation/Arduino-Source
4+
*
5+
*/
6+
7+
#include "Common/Cpp/Color.h"
8+
#include "CommonFramework/ImageTools/ImageBoxes.h"
9+
#include "CommonFramework/ImageTools/ImageStats.h"
10+
#include "CommonFramework/ImageTypes/ImageRGB32.h"
11+
#include "CommonFramework/ImageTypes/ImageViewRGB32.h"
12+
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
13+
#include "CommonTools/Images/ImageFilter.h"
14+
#include "PokemonRSE_ShinyNumberDetector.h"
15+
16+
//#include <iostream>
17+
//using std::cout;
18+
//using std::endl;
19+
20+
namespace PokemonAutomation{
21+
namespace NintendoSwitch{
22+
namespace PokemonRSE{
23+
24+
ShinyNumberDetector::ShinyNumberDetector(Color color)
25+
: m_box_number(0.136, 0.156, 0.123, 0.072)
26+
{}
27+
void ShinyNumberDetector::make_overlays(VideoOverlaySet& items) const{
28+
items.add(COLOR_RED, m_box_number);
29+
}
30+
bool ShinyNumberDetector::read(Logger& logger, const ImageViewRGB32& frame){
31+
const bool replace_color_within_range = true;
32+
33+
//Filter out background
34+
ImageRGB32 filtered_region = filter_rgb32_range(
35+
extract_box_reference(frame, m_box_number),
36+
combine_rgb(138, 97, 221), combine_rgb(200, 181, 239), Color(0), replace_color_within_range
37+
);
38+
ImageStats stats = image_stats(filtered_region);
39+
40+
/*
41+
filtered_region.save("./filtered_only.png");
42+
cout << stats.average.r << endl;
43+
cout << stats.average.g << endl;
44+
cout << stats.average.b << endl;
45+
*/
46+
47+
/*
48+
Shiny:
49+
R: 196.632, G: 196.771, B: 145.863
50+
Not shiny:
51+
R: 181.862, G: 180.686, B: 193.999
52+
*/
53+
54+
if (stats.average.b + 20 < stats.average.r){
55+
return true;
56+
}
57+
return false;
58+
}
59+
60+
61+
}
62+
}
63+
}
64+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/* Shiny Number Detector
2+
*
3+
* From: https://github.com/PokemonAutomation/Arduino-Source
4+
*
5+
*/
6+
7+
#ifndef PokemonAutomation_PokemonRSE_ShinyNumberDetector_H
8+
#define PokemonAutomation_PokemonRSE_ShinyNumberDetector_H
9+
10+
#include "Common/Cpp/AbstractLogger.h"
11+
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
12+
13+
namespace PokemonAutomation{
14+
namespace NintendoSwitch{
15+
namespace PokemonRSE{
16+
17+
// In the summary screen, the dex number will be yellow if a shiny, white if not.
18+
// Additionally, the background behind the sprite will be white if shiny, grey if not.
19+
// Number is easier to check as the background is scan lines.
20+
class ShinyNumberDetector{
21+
public:
22+
ShinyNumberDetector(Color color);
23+
24+
virtual void make_overlays(VideoOverlaySet& items) const;
25+
bool read(Logger& logger, const ImageViewRGB32& frame);
26+
27+
private:
28+
ImageFloatBox m_box_number;
29+
};
30+
31+
32+
33+
}
34+
}
35+
}
36+
#endif

0 commit comments

Comments
 (0)