VJ: Use a scanning step proportional to scale.

This commit is contained in:
iabdalkader 2016-02-15 00:58:17 +02:00
parent d850325de4
commit 46d91cc95a
2 changed files with 11 additions and 10 deletions

View File

@ -34,7 +34,7 @@ static int imlib_std(image_t *image)
int m = s/n; int m = s/n;
/* variance */ /* variance */
uint32_t v = sq*24*24-(m*m); uint32_t v = sq*n-(m*m);
/* std */ /* std */
return fast_sqrtf(v); return fast_sqrtf(v);
@ -141,14 +141,18 @@ array_t *imlib_detect_objects(image_t *image, cascade_t *cascade)
/* set image standard deviation */ /* set image standard deviation */
cascade->std = imlib_std(image); 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; float scale_factor = cascade->scale_factor;
cascade->step = (image->w*75)/1000; //7.5% of the image width
/* iterate over the image pyramid */ /* iterate over the image pyramid */
for(float factor=1.0f; ; factor*=scale_factor) { for(float factor=1.0f; ; factor*=scale_factor) {
/* Set the width and height of the images */ /* Set the width and height of the images */
sum.w = (image->w/factor); sum.w = image->w/factor;
sum.h = (image->h/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 /* Check if scaled image is smaller
than the original detection window */ than the original detection window */

View File

@ -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) 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; py_cascade_obj_t *o = NULL;
mp_map_elem_t *kw_stages = NULL; mp_map_elem_t *kw_stages = NULL;
// detection parameters
struct cascade cascade = {
.step = 2,
};
// Load cascade from file or flash // Load cascade from file or flash
const char *path = mp_obj_str_get_str(args[0]); const char *path = mp_obj_str_get_str(args[0]);
int res = imlib_load_cascade(&cascade, path); int res = imlib_load_cascade(&cascade, path);