Skip to content

Commit 1da599e

Browse files
committed
Improve the type detector for 6-star Tera Cards.
1 parent 671f47e commit 1da599e

File tree

3 files changed

+42
-24
lines changed

3 files changed

+42
-24
lines changed

SerialPrograms/Source/NintendoSwitch/DevPrograms/TestProgramSwitch.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,13 @@ void TestProgram::program(MultiSwitchProgramEnvironment& env, CancellableScope&
270270

271271
ImageRGB32 image("20250125-232444699636.png");
272272

273-
TeraSilhouetteReader reader;
274-
ImageMatch::ImageMatchResult results = reader.read(image);
275-
results.log(logger, 110);
273+
// TeraSilhouetteReader reader;
274+
// ImageMatch::ImageMatchResult results = reader.read(image);
275+
// results.log(logger, 110);
276276

277+
TeraTypeReader reader;
278+
ImageMatch::ImageMatchResult results = reader.read(image);
279+
results.log(logger, 100);
277280

278281

279282
#if 0

SerialPrograms/Source/PokemonSV/Inference/Tera/PokemonSV_TeraSilhouetteReader.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ ImageMatch::ImageMatchResult TeraSilhouetteReader::read(const ImageViewRGB32& sc
7777
preprocessed_image,
7878
// The filter is a lambda function that returns true on black silhouette pixels.
7979
[=](Color pixel){
80-
// return (uint32_t)pixel.red() + pixel.green() + pixel.blue() < 200;
8180
return (uint32_t)pixel.red() + pixel.green() + pixel.blue() < threshold;
8281
}
8382
);

SerialPrograms/Source/PokemonSV/Inference/Tera/PokemonSV_TeraTypeReader.cpp

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,28 +41,44 @@ ImageMatch::ImageMatchResult TeraTypeReader::read(const ImageViewRGB32& screen)
4141
static constexpr double MAX_ALPHA = 100;
4242
static constexpr double ALPHA_SPREAD = 20;
4343

44-
// Get a loose crop of the tera type icon
45-
ImageViewRGB32 cropped_image = extract_box_reference(screen, m_box);
46-
//cropped_image.save("cropped_image.png");
47-
48-
// Get a tight crop
49-
const ImagePixelBox tight_box = ImageMatch::enclosing_rectangle_with_pixel_filter(
50-
cropped_image,
51-
// The filter is a lambda function that returns true on black tera type pixels.
52-
[](Color pixel){
53-
return (uint32_t)pixel.red() + pixel.green() + pixel.blue() < 200;
44+
const std::vector<uint32_t> BRIGHTNESS_THRESHOLDS{
45+
200,
46+
150,
47+
100,
48+
125,
49+
175,
50+
225,
51+
};
52+
53+
for (uint32_t threshold : BRIGHTNESS_THRESHOLDS){
54+
55+
// Get a loose crop of the tera type icon
56+
ImageViewRGB32 cropped_image = extract_box_reference(screen, m_box);
57+
//cropped_image.save("cropped_image.png");
58+
59+
// Get a tight crop
60+
const ImagePixelBox tight_box = ImageMatch::enclosing_rectangle_with_pixel_filter(
61+
cropped_image,
62+
// The filter is a lambda function that returns true on black tera type pixels.
63+
[=](Color pixel){
64+
return (uint32_t)pixel.red() + pixel.green() + pixel.blue() < threshold;
65+
}
66+
);
67+
ImageRGB32 processed_image = extract_box_reference(cropped_image, tight_box).copy();
68+
//processed_image.save("processed_image.png");
69+
70+
ImageRGB32 filtered_image = to_blackwhite_rgb32_range(processed_image, 0xff000000, 0xff5f5f5f, true);
71+
//filtered_image.save("filtered_image.png");
72+
73+
ImageMatch::ImageMatchResult types = m_matcher.match(filtered_image, ALPHA_SPREAD);
74+
types.clear_beyond_alpha(MAX_ALPHA);
75+
76+
if (types.results.size() == 1){
77+
return types;
5478
}
55-
);
56-
ImageRGB32 processed_image = extract_box_reference(cropped_image, tight_box).copy();
57-
//processed_image.save("processed_image.png");
58-
59-
ImageRGB32 filtered_image = to_blackwhite_rgb32_range(processed_image, 0xff000000, 0xff5f5f5f, true);
60-
//filtered_image.save("filtered_image.png");
61-
62-
ImageMatch::ImageMatchResult types = m_matcher.match(filtered_image, ALPHA_SPREAD);
63-
types.clear_beyond_alpha(MAX_ALPHA);
79+
}
6480

65-
return types;
81+
return ImageMatch::ImageMatchResult();
6682
}
6783

6884

0 commit comments

Comments
 (0)