Skip to content

Commit 88e8388

Browse files
committed
Add PLZA button detectors. Refactor waterfill routine to take input resolution for size normalization. Add bench reset routine.
1 parent b817202 commit 88e8388

File tree

54 files changed

+721
-92
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+721
-92
lines changed

SerialPrograms/Source/CommonFramework/Globals.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ namespace PokemonAutomation{
2525

2626
const bool IS_BETA_VERSION = true;
2727
const int PROGRAM_VERSION_MAJOR = 0;
28-
const int PROGRAM_VERSION_MINOR = 58;
29-
const int PROGRAM_VERSION_PATCH = 3;
28+
const int PROGRAM_VERSION_MINOR = 59;
29+
const int PROGRAM_VERSION_PATCH = 1;
3030

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

SerialPrograms/Source/CommonFramework/ImageTypes/ImageViewPlanar32.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <stdint.h>
1111
#include "Common/Compiler.h"
12+
#include "Common/Cpp/ImageResolution.h"
1213

1314
namespace PokemonAutomation{
1415

@@ -35,6 +36,7 @@ class ImageViewPlanar32{
3536
PA_FORCE_INLINE size_t bytes_per_row () const{ return m_bytes_per_row; }
3637
PA_FORCE_INLINE size_t width () const{ return m_width; }
3738
PA_FORCE_INLINE size_t height () const{ return m_height; }
39+
PA_FORCE_INLINE Resolution size () const{ return Resolution(m_width, m_height); }
3840
PA_FORCE_INLINE size_t total_pixels () const{ return m_width * m_height; }
3941

4042
// Direct Pixel Access

SerialPrograms/Source/CommonTools/ImageMatch/WaterfillTemplateMatcher.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ WaterfillTemplateMatcher::WaterfillTemplateMatcher(
7777
}
7878
}
7979

80-
double WaterfillTemplateMatcher::rmsd(const ImageViewRGB32& image) const{
81-
if (!image || !check_image(image)){
80+
double WaterfillTemplateMatcher::rmsd(Resolution input_resolution, const ImageViewRGB32& image) const{
81+
if (!image || !check_image(input_resolution, image)){
8282
return 99999.;
8383
}
8484
return m_matcher->rmsd(image);
@@ -125,7 +125,11 @@ bool WaterfillTemplateMatcher::check_area_ratio(double candidate_area_ratio) con
125125

126126
return pass;
127127
}
128-
double WaterfillTemplateMatcher::rmsd_precropped(const ImageViewRGB32& cropped_image, const WaterfillObject& object) const{
128+
double WaterfillTemplateMatcher::rmsd_precropped(
129+
Resolution input_resolution,
130+
const ImageViewRGB32& cropped_image,
131+
const WaterfillObject& object
132+
) const{
129133

130134
// XXX
131135
// dump_debug_image(global_logger_command_line(), "CommonFramework/WaterfillTemplateMatcher", "rmsd_precropped_input", cropped_image);
@@ -142,7 +146,7 @@ double WaterfillTemplateMatcher::rmsd_precropped(const ImageViewRGB32& cropped_i
142146
// static int c = 0;
143147
// cout << c << endl;
144148

145-
double rmsd = this->rmsd(cropped_image);
149+
double rmsd = this->rmsd(input_resolution, cropped_image);
146150

147151
// cout << "rmsd = " << rmsd << endl;
148152

@@ -153,7 +157,11 @@ double WaterfillTemplateMatcher::rmsd_precropped(const ImageViewRGB32& cropped_i
153157

154158
return rmsd;
155159
}
156-
double WaterfillTemplateMatcher::rmsd_original(const ImageViewRGB32& original_image, const WaterfillObject& object) const{
160+
double WaterfillTemplateMatcher::rmsd_original(
161+
Resolution input_resolution,
162+
const ImageViewRGB32& original_image,
163+
const WaterfillObject& object
164+
) const{
157165

158166
if (PreloadSettings::debug().IMAGE_TEMPLATE_MATCHING){
159167
cout << "rmsd_original()" << endl;
@@ -172,7 +180,10 @@ double WaterfillTemplateMatcher::rmsd_original(const ImageViewRGB32& original_im
172180
return 99999.;
173181
}
174182

175-
double rmsd = this->rmsd(extract_box_reference(original_image, object));
183+
double rmsd = this->rmsd(
184+
input_resolution,
185+
extract_box_reference(original_image, object)
186+
);
176187
if (PreloadSettings::debug().IMAGE_TEMPLATE_MATCHING){
177188
cout << "Passed aspect and area ratio check, rmsd = " << rmsd << endl;
178189
}

SerialPrograms/Source/CommonTools/ImageMatch/WaterfillTemplateMatcher.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <memory>
1111
#include "Common/Cpp/Color.h"
12+
#include "Common/Cpp/ImageResolution.h"
1213
#include "CommonFramework/ImageTools/ImageBoxes.h"
1314
#include "CommonTools/ImageMatch/ExactImageMatcher.h"
1415

@@ -51,29 +52,37 @@ class WaterfillTemplateMatcher{
5152
// In case the image is invalid, return a large value.
5253
// It also calls the virtual function `check_image()` on the image.
5354
// If the function returns false, then return a large value.
54-
double rmsd(const ImageViewRGB32& image) const;
55+
double rmsd(Resolution input_resolution, const ImageViewRGB32& image) const;
5556

5657
// Compute RMSD of the object on the image against the template.
5758
// The input `cropped_image` is already cropped from a full image using the bounding box of the input waterfill `object`.
5859
// This cropped image is compared against the template as-is.
5960
// The waterfill object's aspect ratio and area ratio are checked against template's. Return a large value
6061
// if the check fails.
6162
// See `double rmsd(const ImageViewRGB32& image) const` on the details of comparing the image against the template.
62-
virtual double rmsd_precropped(const ImageViewRGB32& cropped_image, const WaterfillObject& object) const;
63+
virtual double rmsd_precropped(
64+
Resolution input_resolution,
65+
const ImageViewRGB32& cropped_image,
66+
const WaterfillObject& object
67+
) const;
6368

6469
// Compute RMSD of the object on the image against the template.
6570
// It will crop the original image using the bounding box of the waterfill object, then compare the cropped
6671
// image against the template as-is.
6772
// The waterfill object's aspect ratio and area ratio are checked against template's. Return a large value
6873
// if the check fails.
6974
// See `double rmsd(const ImageViewRGB32& image) const` on the details of comparing the image against the template.
70-
virtual double rmsd_original(const ImageViewRGB32& original_image, const WaterfillObject& object) const;
75+
virtual double rmsd_original(
76+
Resolution input_resolution,
77+
const ImageViewRGB32& original_image,
78+
const WaterfillObject& object
79+
) const;
7180

7281
// Return the image template mesh
7382
const ImageRGB32& image_template() const { return m_matcher->image_template(); }
7483

7584
protected:
76-
virtual bool check_image(const ImageViewRGB32& image) const{ return true; };
85+
virtual bool check_image(Resolution input_resolution, const ImageViewRGB32& image) const{ return true; };
7786
bool check_aspect_ratio(size_t candidate_width, size_t candidate_height) const;
7887
bool check_area_ratio(double candidate_area_ratio) const;
7988

SerialPrograms/Source/CommonTools/Images/WaterfillUtilities.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,11 @@ std::pair<PackedBinaryMatrix, size_t> remove_center_pixels(
7474
}
7575

7676
bool match_template_by_waterfill(
77-
const ImageViewRGB32 &image,
78-
const ImageMatch::WaterfillTemplateMatcher &matcher,
79-
const std::vector<std::pair<uint32_t, uint32_t>> &filters,
80-
const std::pair<size_t, size_t> &area_thresholds,
77+
Resolution input_resolution,
78+
const ImageViewRGB32& image,
79+
const ImageMatch::WaterfillTemplateMatcher& matcher,
80+
const std::vector<std::pair<uint32_t, uint32_t>>& filters,
81+
const std::pair<size_t, size_t>& area_thresholds,
8182
double rmsd_threshold,
8283
std::function<bool(Kernels::Waterfill::WaterfillObject& object)> check_matched_object)
8384
{
@@ -133,12 +134,13 @@ bool match_template_by_waterfill(
133134
if (object.area > area_thresholds.second){
134135
continue;
135136
}
136-
double rmsd = matcher.rmsd_original(image, object);
137+
double rmsd = matcher.rmsd_original(input_resolution, image, object);
137138
if (PreloadSettings::debug().IMAGE_TEMPLATE_MATCHING){
138139
std::cout << "Object rmsd: " << rmsd << std::endl;
139140
}
140141

141142
if (rmsd < rmsd_threshold){
143+
// std::cout << "Object rmsd: " << rmsd << std::endl;
142144
detected = true;
143145

144146
if (check_matched_object(object)){

SerialPrograms/Source/CommonTools/Images/WaterfillUtilities.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include <functional>
1212
#include <utility>
13+
#include "Common/Cpp/ImageResolution.h"
1314
#include "CommonFramework/ImageTypes/BinaryImage.h"
1415

1516
namespace PokemonAutomation{
@@ -54,10 +55,11 @@ std::pair<PackedBinaryMatrix, size_t> remove_center_pixels(
5455
// check_matched_object: if a matcher is found, pass the matched object to this function. If the function returns true, stop the
5556
// entire template matching operation.
5657
bool match_template_by_waterfill(
57-
const ImageViewRGB32 &image,
58-
const ImageMatch::WaterfillTemplateMatcher &matcher,
58+
Resolution input_resolution,
59+
const ImageViewRGB32& image,
60+
const ImageMatch::WaterfillTemplateMatcher& matcher,
5961
const std::vector<std::pair<uint32_t, uint32_t>> &filters,
60-
const std::pair<size_t, size_t> &area_thresholds,
62+
const std::pair<size_t, size_t>& area_thresholds,
6163
double rmsd_threshold,
6264
std::function<bool(Kernels::Waterfill::WaterfillObject& object)> check_matched_object);
6365

SerialPrograms/Source/NintendoSwitch/DevPrograms/TestProgramSwitch.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@
146146
#include "PokemonLGPE/Inference/Battles/PokemonLGPE_BattleArrowDetector.h"
147147
#include "PokemonLZA/Inference/PokemonLZA_DialogDetector.h"
148148
#include "PokemonLZA/Programs/PokemonLZA_GameEntry.h"
149+
#include "PokemonLZA/Programs/PokemonLZA_BasicNavigation.h"
149150

150151

151152

@@ -274,6 +275,7 @@ void TestProgram::program(MultiSwitchProgramEnvironment& env, CancellableScope&
274275
// using namespace PokemonBDSP;
275276
// using namespace PokemonLA;
276277
// using namespace PokemonSV;
278+
using namespace PokemonLZA;
277279

278280
[[maybe_unused]] Logger& logger = env.logger();
279281
[[maybe_unused]] ConsoleHandle& console = env.consoles[0];
@@ -284,7 +286,13 @@ void TestProgram::program(MultiSwitchProgramEnvironment& env, CancellableScope&
284286
VideoOverlaySet overlays(overlay);
285287

286288

289+
while (true){
290+
sit_on_bench(console, context);
291+
}
292+
293+
287294

295+
#if 0
288296
while (true){
289297
ssf_press_button(context, BUTTON_ZL, 160ms, 800ms, 200ms);
290298
ssf_press_button(context, BUTTON_PLUS, 320ms, 840ms);
@@ -293,7 +301,7 @@ void TestProgram::program(MultiSwitchProgramEnvironment& env, CancellableScope&
293301
pbf_press_button(context, BUTTON_X, 80ms, 24ms);
294302
pbf_press_button(context, BUTTON_B, 80ms, 24ms);
295303
}
296-
304+
#endif
297305

298306

299307
#if 0

SerialPrograms/Source/PokemonLA/Inference/Objects/PokemonLA_ArcDetector.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,11 @@ ArcDetector::ArcDetector()
6969
}
7070
)
7171
{}
72-
void ArcDetector::process_object(const ImageViewRGB32& image, const WaterfillObject& object){
72+
void ArcDetector::process_object(
73+
Resolution input_resolution,
74+
const ImageViewRGB32& image,
75+
const WaterfillObject& object
76+
){
7377
ImagePixelBox object_box;
7478
if (ArcMatcher::left().matches(object_box, image, object)){
7579
m_left.emplace_back(object_box);

SerialPrograms/Source/PokemonLA/Inference/Objects/PokemonLA_ArcDetector.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ namespace PokemonLA{
1818
class ArcDetector : public WhiteObjectDetector{
1919
public:
2020
ArcDetector();
21-
virtual void process_object(const ImageViewRGB32& image, const WaterfillObject& object) override;
21+
virtual void process_object(
22+
Resolution input_resolution,
23+
const ImageViewRGB32& image,
24+
const WaterfillObject& object
25+
) override;
2226
virtual void finish(const ImageViewRGB32& image) override;
2327

2428
private:

SerialPrograms/Source/PokemonLA/Inference/Objects/PokemonLA_ArcPhoneDetector.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ ArcPhoneTracker::ArcPhoneTracker()
4545
)
4646
{}
4747

48-
void ArcPhoneTracker::process_object(const ImageViewRGB32& image, const WaterfillObject& object){
48+
void ArcPhoneTracker::process_object(
49+
Resolution input_resolution,
50+
const ImageViewRGB32& image,
51+
const WaterfillObject& object
52+
){
4953
// cout << "asdf" << endl;
5054
// static int c = 0;
5155
// cout << "c = " << c << endl;
@@ -60,7 +64,7 @@ void ArcPhoneTracker::process_object(const ImageViewRGB32& image, const Waterfil
6064

6165
// cout << (double)object.width() / image.width() << endl;
6266

63-
double rmsd = ArcPhoneMatcher::instance().rmsd_original(image, object);
67+
double rmsd = ArcPhoneMatcher::instance().rmsd_original(input_resolution, image, object);
6468
// cout << "rmsd = " << rmsd << endl;
6569
if (rmsd < 80){
6670
// cout << "rmsd = " << rmsd << endl;

0 commit comments

Comments
 (0)