summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Franzke <benjaminfranzke@googlemail.com>2012-03-20 20:43:44 +0100
committerBenjamin Franzke <benjaminfranzke@googlemail.com>2012-03-20 20:43:44 +0100
commit437854c37204f489c7b0492363938e345f7f2a74 (patch)
tree7c4476e671d15ce64488ae1b59cceb9d3b4853ab
parent06266dcf372b1e27068199eb963c1a2b33fe1e43 (diff)
downloadcv-437854c37204f489c7b0492363938e345f7f2a74.tar.gz
cv-437854c37204f489c7b0492363938e345f7f2a74.tar.bz2
cv-437854c37204f489c7b0492363938e345f7f2a74.zip
wimmel: Convert to calculation on monochrome image
-rw-r--r--wimmel.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/wimmel.c b/wimmel.c
index 69daa11..4f55f4e 100644
--- a/wimmel.c
+++ b/wimmel.c
@@ -40,9 +40,7 @@ find_image_in_wimmel(GdkPixbuf *wimmel, GdkPixbuf *match, GdkPixbuf *output)
pix = row + n * stride + (i + k) * nch;
- if (abs((int)pix[0] - (int)pix_m[0]) > 50 ||
- abs((int)pix[1] - (int)pix_m[1]) > 50 ||
- abs((int)pix[2] - (int)pix_m[2]) > 50) {
+ if (abs((int)pix[0] - (int)pix_m[0]) > 10) {
difference++;
if (difference > barrier)
break;
@@ -86,6 +84,24 @@ find_thread(gpointer data)
return NULL;
}
+void
+monochrome(GdkPixbuf *p)
+{
+ int x, y, width, height, nch;
+ guchar *d;
+
+ width = gdk_pixbuf_get_width(p);
+ height = gdk_pixbuf_get_height(p);
+ nch = gdk_pixbuf_get_n_channels(p);
+
+ for (y = 0; y < height; ++y) {
+ d = gdk_pixbuf_get_pixels(p) + y * gdk_pixbuf_get_rowstride(p);
+ for (x = 0; x < width; ++x, d += nch) {
+ d[0] = MAX(d[0], MAX(d[1], d[2]));
+ }
+ }
+}
+
int
main(int argc, char *argv[])
{
@@ -112,10 +128,12 @@ main(int argc, char *argv[])
exit(EXIT_FAILURE);
output = gdk_pixbuf_copy(wimmel);
+ monochrome(wimmel);
match_tmp = gdk_pixbuf_new_subpixbuf(wimmel, x1, y1, mwidth, mheight);
match = gdk_pixbuf_copy(match_tmp);
g_object_unref(match_tmp);
+ monochrome(match);
width = gdk_pixbuf_get_width(wimmel);
height = gdk_pixbuf_get_height(wimmel);