Repository navigation
Expand file tree
/
Copy pathNintendoSwitch_DateChangeDetector.cpp
More file actions
179 lines (146 loc) · 5.99 KB
/
Copy pathNintendoSwitch_DateChangeDetector.cpp
File metadata and controls
179 lines (146 loc) · 5.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/* Date Change Detector
*
* From: https://github.com/PokemonAutomation/
*
*/
#include "CommonFramework/ImageTools/ImageStats.h"
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
#include "NintendoSwitch_DateChangeDetector.h"
//#include <iostream>
//using std::cout;
//using std::endl;
namespace PokemonAutomation{
namespace NintendoSwitch{
DateChangeDetector_Switch1::DateChangeDetector_Switch1(Color color)
: m_color(color)
, m_background_top(0.50, 0.02, 0.45, 0.08)
, m_window_top(0.50, 0.36, 0.45, 0.07)
, m_window_text(0.05, 0.36, 0.10, 0.07)
, m_jp_year(0.136, 0.61, 0.11, 0.09)
, m_us_hour(0.473, 0.61, 0.06, 0.09)
, m_jp_month_arrow(0.30, 0.50, 0.05, 0.06)
{}
void DateChangeDetector_Switch1::make_overlays(VideoOverlaySet& items) const{
items.add(m_color, m_background_top);
items.add(m_color, m_window_top);
items.add(m_color, m_window_text);
items.add(m_color, m_jp_year);
items.add(m_color, m_us_hour);
items.add(m_color, m_jp_month_arrow);
}
bool DateChangeDetector_Switch1::detect(const ImageViewRGB32& screen){
ImageStats stats_background_top = image_stats(extract_box_reference(screen, m_background_top));
if (stats_background_top.stddev.sum() > 10){
// cout << "asdf" << endl;
return false;
}
ImageStats stats_window_top = image_stats(extract_box_reference(screen, m_window_top));
// cout << stats_window_top.average << stats_window_top.stddev << endl;
if (stats_window_top.stddev.sum() > 10){
// cout << "qwer" << endl;
return false;
}
ImageStats stats_window_text = image_stats(extract_box_reference(screen, m_window_text));
// cout << stats_window_text.stddev << endl;
if (stats_window_text.stddev.sum() < 100){
// cout << "zxcv" << endl;
return false;
}
// cout << "stats_background_top: " << stats_background_top.average.sum() << endl;
// cout << "stats_window_top: " << stats_window_top.average.sum() << endl;
if (std::abs(stats_background_top.average.sum() - stats_window_top.average.sum()) < 50){
// cout << "xcvb" << endl;
return false;
}
// bool white_theme = stats_window_top.average.sum() > 600;
ImageViewRGB32 year_box = extract_box_reference(screen, m_jp_year);
ImageStats year_stats = image_stats(year_box);
// cout << year_stats.average << year_stats.stddev << endl;
double stddev = year_stats.stddev.sum();
if (stddev < 80){
// cout << "sdfg" << endl;
return false;
}
return true;
}
DateFormat DateChangeDetector_Switch1::detect_date_format(const ImageViewRGB32& screen) const{
ImageViewRGB32 us_hours = extract_box_reference(screen, m_us_hour);
ImageStats stats_us_hours = image_stats(us_hours);
if (stats_us_hours.stddev.sum() > 30){
return DateFormat::US;
}
ImageViewRGB32 jp_arrow = extract_box_reference(screen, m_jp_month_arrow);
ImageStats stats_arrow = image_stats(jp_arrow);
if (stats_arrow.stddev.sum() > 30){
return DateFormat::JP;
}
return DateFormat::EU;
}
DateChangeDetector_Switch2::DateChangeDetector_Switch2(Color color)
: m_color(color)
, m_background_top(0.50, 0.02, 0.45, 0.08)
, m_window_bottom(0.50, 0.80, 0.45, 0.07)
, m_window_text(0.05, 0.02, 0.10, 0.08)
, m_jp_year(0.139, 0.436, 0.088, 0.095)
, m_us_hour(0.466856, 0.567340, 0.049242, 0.063973)
, m_jp_month_arrow(0.291705, 0.331675, 0.054986, 0.069652)
{}
void DateChangeDetector_Switch2::make_overlays(VideoOverlaySet& items) const{
items.add(m_color, m_background_top);
items.add(m_color, m_window_bottom);
items.add(m_color, m_window_text);
items.add(m_color, m_jp_year);
items.add(m_color, m_us_hour);
items.add(m_color, m_jp_month_arrow);
}
bool DateChangeDetector_Switch2::detect(const ImageViewRGB32& screen){
ImageStats stats_background_top = image_stats(extract_box_reference(screen, m_background_top));
if (stats_background_top.stddev.sum() > 10){
// cout << "asdf" << endl;
return false;
}
ImageStats stats_window_bottom = image_stats(extract_box_reference(screen, m_window_bottom));
// cout << stats_window_bottom.average << stats_window_top.stddev << endl;
if (stats_window_bottom.stddev.sum() > 10){
// cout << "qwer" << endl;
return false;
}
ImageStats stats_window_text = image_stats(extract_box_reference(screen, m_window_text));
// cout << stats_window_text.stddev << endl;
if (stats_window_text.stddev.sum() < 100){
// cout << "zxcv" << endl;
return false;
}
// cout << "stats_background_top: " << stats_background_top.average.sum() << endl;
// cout << "stats_window_top: " << stats_window_top.average.sum() << endl;
if (euclidean_distance(stats_background_top.average, stats_window_bottom.average) > 10){
// cout << "xcvb" << endl;
return false;
}
// bool white_theme = stats_window_top.average.sum() > 600;
ImageViewRGB32 year_box = extract_box_reference(screen, m_jp_year);
ImageStats year_stats = image_stats(year_box);
// cout << year_stats.average << year_stats.stddev << endl;
double stddev = year_stats.stddev.sum();
if (stddev < 80){
// cout << "sdfg" << endl;
return false;
}
return true;
}
DateFormat DateChangeDetector_Switch2::detect_date_format(const ImageViewRGB32& screen) const{
ImageViewRGB32 us_hours = extract_box_reference(screen, m_us_hour);
ImageStats stats_us_hours = image_stats(us_hours);
// cout << stats_us_hours.stddev.sum() << endl;
if (stats_us_hours.stddev.sum() > 30){
return DateFormat::US;
}
ImageViewRGB32 jp_arrow = extract_box_reference(screen, m_jp_month_arrow);
ImageStats stats_arrow = image_stats(jp_arrow);
if (stats_arrow.stddev.sum() > 30){
return DateFormat::JP;
}
return DateFormat::EU;
}
}
}