diff options
author | Tom Smeding <tom.smeding@gmail.com> | 2018-08-04 11:03:19 +0200 |
---|---|---|
committer | Tom Smeding <tom.smeding@gmail.com> | 2018-08-04 11:03:19 +0200 |
commit | a7289869089b142e41cd269f3764e6f16f088da0 (patch) | |
tree | ec102998877252c5c5ab3d54b225e634cf5e4732 | |
parent | c2070362cc8130c9ae1a9799e721ea2a2fb4787f (diff) |
-rw-r--r-- | shot.cpp | 19 |
1 files changed, 15 insertions, 4 deletions
@@ -81,12 +81,13 @@ int w, h; template <bool (*F)(const Clr &c)> int flood(int x, int y, bool *mark) { + if (!F(img[w*y+x])) return 0; mark[w*y+x] = true; int t = 1; - if (x > 0 && !mark[w*y+x-1] && F(img[w*y+x-1])) t += flood<F>(x-1, y, mark); - if (y > 0 && !mark[w*(y-1)+x] && F(img[w*(y-1)+x])) t += flood<F>(x, y-1, mark); - if (x < w-1 && !mark[w*y+x+1] && F(img[w*y+x+1])) t += flood<F>(x+1, y, mark); - if (y < h-1 && !mark[w*(y+1)+x] && F(img[w*(y+1)+x])) t += flood<F>(x, y+1, mark); + if (x > 0 && !mark[w*y+x-1]) t += flood<F>(x-1, y, mark); + if (y > 0 && !mark[w*(y-1)+x]) t += flood<F>(x, y-1, mark); + if (x < w-1 && !mark[w*y+x+1]) t += flood<F>(x+1, y, mark); + if (y < h-1 && !mark[w*(y+1)+x]) t += flood<F>(x, y+1, mark); return t; } @@ -140,6 +141,7 @@ void cmd_recog() { // writeimg(img, w, h, "out1.png"); bool *mark = new bool[w*h](); + bool *mark2 = new bool[w*h]; int maxn = -1, maxi = -1; for (int y = 0; y < h; y++) { @@ -150,10 +152,19 @@ void cmd_recog() { maxn = n; maxi = w*y + x; } + if (0 < n && n < 300) { + memset(mark2, 0, w*h*sizeof(bool)); + flood<clr_interest>(x, y, mark2); + for (int i = 0; i < w*h; i++) { + if (mark2[i]) img[i] = {255, 255, 255}; + } + } } } } + delete[] mark2; + memset(mark, 0, w*h*sizeof(bool)); flood<clr_interest>(maxi%w, maxi/w, mark); |