Add loop step argument to template matching.

This commit is contained in:
iabdalkader 2016-06-14 00:14:22 +02:00
parent a25e0c162e
commit 2767791aae
3 changed files with 7 additions and 5 deletions

View File

@ -449,7 +449,7 @@ array_t *imlib_find_markers(array_t *blobs_list, int margin,
bool (*f_fun)(void*,void*,color_blob_t*), void *f_fun_arg_0, void *f_fun_arg_1);
/* Template Matching */
float imlib_template_match(image_t *image, image_t *template, rectangle_t *r, rectangle_t *roi);
float imlib_template_match(image_t *image, image_t *template, rectangle_t *roi, int step, rectangle_t *r);
void imlib_phasecorrelate(image_t *img0, image_t *img1, int *x_offset, int *y_offset);
/* Clustering functions */

View File

@ -8,7 +8,7 @@
*/
#include "imlib.h"
#include "xalloc.h"
float imlib_template_match(image_t *f, image_t *t, rectangle_t *roi, rectangle_t *r)
float imlib_template_match(image_t *f, image_t *t, rectangle_t *roi, int step, rectangle_t *r)
{
int den_b=0;
float corr=0.0f;
@ -25,8 +25,8 @@ float imlib_template_match(image_t *f, image_t *t, rectangle_t *roi, rectangle_t
den_b += c*c;
}
for (int v=roi->y; v < roi->y + roi->h - t->h; v+=2) {
for (int u=roi->x; u < roi->x + roi->w - t->w; u+=2) {
for (int v=roi->y; v < roi->y + roi->h - t->h; v+=step) {
for (int u=roi->x; u < roi->x + roi->w - t->w; u+=step) {
int num = 0;
int den_a=0;

View File

@ -1039,9 +1039,11 @@ static mp_obj_t py_image_find_template(uint n_args, const mp_obj_t *args, mp_map
PY_ASSERT_TRUE_MSG(((roi.x + roi.w) <= arg_img->w && (roi.y + roi.h) <= arg_img->h),
"Region of interest is bigger than image!");
int step = py_helper_lookup_int(kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_step), 2);
// Find template
rectangle_t r;
float corr = imlib_template_match(arg_img, arg_template, &roi, &r);
float corr = imlib_template_match(arg_img, arg_template, &roi, step, &r);
if (corr > arg_thresh) {
mp_obj_t rec_obj[4] = {