diff --git a/src/omv/img/template.c b/src/omv/img/template.c index eb116fd4b..8ba632cad 100644 --- a/src/omv/img/template.c +++ b/src/omv/img/template.c @@ -9,42 +9,23 @@ #include "xalloc.h" #include "imlib.h" #include -float imlib_template_match(struct image *f, struct image *t_orig, struct rectangle *r) +float imlib_template_match(struct image *f, struct image *t, struct rectangle *r) { int den_b=0; float corr =0.0; - struct image img; - struct image *t=&img; - struct integral_image sum; struct integral_image *f_imgs=∑ - /* allocate buffer for scaled template */ - t->w = t_orig->w; - t->h = t_orig->h; - t->bpp = t_orig->bpp; - t->data = xalloc(sizeof(*t->data)* t_orig->w * t_orig->h); - - /* allocate buffer for integral image */ - f_imgs->w = f->w; - f_imgs->h = f->h; - f_imgs->data = (uint32_t*) (f->data+(f->w * f->h*2));/* after the framebuffer */ - /* get integeral image */ + imlib_integral_image_alloc(f_imgs, f->w, f->h); imlib_integral_image(f, f_imgs); - /* copy template */ - t->w = (int) t_orig->w; - t->h = (int) t_orig->h; - memcpy(t->data, t_orig->data,(sizeof(*t->data)* t_orig->w * t_orig->h)); - /* get normalized template sum of squares */ int t_mean = imlib_image_mean(t); for (int i=0; i < (t->w*t->h); i++) { - int c = (int8_t)t->data[i]-t_mean; + int c = (int)t->data[i]-t_mean; den_b += c*c; - t->data[i]=(int8_t)c; } for (int v=0; v < f->h - t->h; v+=3) { @@ -56,8 +37,8 @@ float imlib_template_match(struct image *f, struct image *t_orig, struct rectan for (int y=v; yh+v; y++) { for (int x=u; xw+u; x++) { - int a = (int8_t)f->data[y*f->w+x]-f_mean; - int b = (int8_t)t->data[(y-v)*t->w+(x-u)]; + int a = (int)f->data[y*f->w+x]-f_mean; + int b = (int)t->data[(y-v)*t->w+(x-u)]-t_mean; num += a*b; den_a += a*a; } @@ -75,7 +56,5 @@ float imlib_template_match(struct image *f, struct image *t_orig, struct rectan } } } - - xfree(t->data); return corr; }