@@ -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