diff --git a/src/omv/img/haar.c b/src/omv/img/haar.c index 0711ce8ba..6bdc2d61d 100644 --- a/src/omv/img/haar.c +++ b/src/omv/img/haar.c @@ -34,7 +34,7 @@ static int imlib_std(image_t *image) int m = s/n; /* variance */ - uint32_t v = sq*24*24-(m*m); + uint32_t v = sq*n-(m*m); /* std */ return fast_sqrtf(v); @@ -141,14 +141,18 @@ array_t *imlib_detect_objects(image_t *image, cascade_t *cascade) /* set image standard deviation */ cascade->std = imlib_std(image); - //float scale_factor = (1.0f-cascade->scale_factor)+1.0f; - + // Viola and Jones achieved best results using a scaling factor + // of 1.25 and a scanning factor proportional to the current scale. float scale_factor = cascade->scale_factor; + cascade->step = (image->w*75)/1000; //7.5% of the image width + /* iterate over the image pyramid */ for(float factor=1.0f; ; factor*=scale_factor) { /* Set the width and height of the images */ - sum.w = (image->w/factor); - sum.h = (image->h/factor); + sum.w = image->w/factor; + sum.h = image->h/factor; + cascade->step = cascade->step/factor; + cascade->step = (cascade->step == 0) ? 1:cascade->step; /* Check if scaled image is smaller than the original detection window */ diff --git a/src/omv/py/py_image.c b/src/omv/py/py_image.c index 58603ff89..5c0a99a47 100644 --- a/src/omv/py/py_image.c +++ b/src/omv/py/py_image.c @@ -1153,14 +1153,11 @@ mp_obj_t py_image_load_image(mp_obj_t path_obj) mp_obj_t py_image_load_cascade(uint n_args, const mp_obj_t *args, mp_map_t *kw_args) { + cascade_t cascade; + py_cascade_obj_t *o = NULL; mp_map_elem_t *kw_stages = NULL; - // detection parameters - struct cascade cascade = { - .step = 2, - }; - // Load cascade from file or flash const char *path = mp_obj_str_get_str(args[0]); int res = imlib_load_cascade(&cascade, path);