aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--shot.cpp19
1 files changed, 15 insertions, 4 deletions
diff --git a/shot.cpp b/shot.cpp
index b0c1fdb..bcaa607 100644
--- a/shot.cpp
+++ b/shot.cpp
@@ -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);