|
8 | 8 | #include "CommonFramework/ImageTypes/ImageRGB32.h" |
9 | 9 | #include "CommonFramework/ImageTools/ImageBoxes.h" |
10 | 10 | #include "CommonFramework/ImageTools/FloatPixel.h" |
| 11 | +#include "CommonTools/Images/SolidColorTest.h" |
11 | 12 | #include "ImageTools.h" |
12 | 13 |
|
13 | 14 | namespace PokemonAutomation{ |
@@ -47,6 +48,50 @@ ImageRGB32 image_diff_greyscale(const ImageViewRGB32& x, const ImageViewRGB32& y |
47 | 48 |
|
48 | 49 |
|
49 | 50 |
|
| 51 | +ImagePixelBox find_contents_pixel_box(const ImageViewRGB32& image){ |
| 52 | + const double MAX_SUM = 10; |
| 53 | + const double MAX_STDDEV = 10; |
| 54 | + |
| 55 | + size_t top = 0; |
| 56 | + for (; top < image.height(); top++){ |
| 57 | + ImageViewRGB32 line = image.sub_image(0, top, image.width(), 1); |
| 58 | + if (!is_black(line, MAX_SUM, MAX_STDDEV)){ |
| 59 | + break; |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | + size_t bot = image.height(); |
| 64 | + for (; bot > top; bot--){ |
| 65 | + ImageViewRGB32 line = image.sub_image(0, bot - 1, image.width(), 1); |
| 66 | + if (!is_black(line, MAX_SUM, MAX_STDDEV)){ |
| 67 | + break; |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + size_t left = 0; |
| 72 | + for (; left < image.width(); left++){ |
| 73 | + ImageViewRGB32 line = image.sub_image(left, 0, 1, image.height()); |
| 74 | + if (!is_black(line, MAX_SUM, MAX_STDDEV)){ |
| 75 | + break; |
| 76 | + } |
| 77 | + } |
| 78 | + |
| 79 | + size_t right = image.width(); |
| 80 | + for (; right > left; right--){ |
| 81 | + ImageViewRGB32 line = image.sub_image(right - 1, 0, 1, image.height()); |
| 82 | + if (!is_black(line, MAX_SUM, MAX_STDDEV)){ |
| 83 | + break; |
| 84 | + } |
| 85 | + } |
| 86 | + |
| 87 | + return ImagePixelBox(left, top, right, bot); |
| 88 | +} |
| 89 | +ImageFloatBox find_contents_float_box(const ImageViewRGB32& image){ |
| 90 | + return pixelbox_to_floatbox( |
| 91 | + image.width(), image.height(), |
| 92 | + find_contents_pixel_box(image) |
| 93 | + ); |
| 94 | +} |
50 | 95 |
|
51 | 96 |
|
52 | 97 |
|
|
0 commit comments