diff --git a/include/CMSIS/arm_math.h b/include/CMSIS/arm_math.h index 59662ae1a..7f312a12d 100644 --- a/include/CMSIS/arm_math.h +++ b/include/CMSIS/arm_math.h @@ -283,7 +283,7 @@ #undef __CMSIS_GENERIC /* enable NVIC and Systick functions */ #include "string.h" -#include "math.h" +//#include "math.h" #ifdef __cplusplus extern "C" { @@ -5874,9 +5874,9 @@ void arm_rfft_fast_f32( // #if __FPU_USED #if (__FPU_USED == 1) && defined ( __CC_ARM ) - *pOut = __sqrtf(in); +// *pOut = __sqrtf(in); #else - *pOut = sqrtf(in); + // *pOut = sqrtf(in); #endif return (ARM_MATH_SUCCESS); diff --git a/src/img/blob.c b/src/img/blob.c index 00eda9c03..a5c7107d6 100644 --- a/src/img/blob.c +++ b/src/img/blob.c @@ -1,7 +1,6 @@ #include #include "xalloc.h" #include "imlib.h" -#include #include array_t *imlib_count_blobs(struct image *image) @@ -10,7 +9,7 @@ array_t *imlib_count_blobs(struct image *image) array_t *points; array_alloc(&blobs, xfree); - array_alloc_init(&points, xfree, 300); + array_alloc_init(&points, xfree, 500); uint16_t *pixels = (uint16_t*) image->pixels; for (int y=1; yh-1; y++) { @@ -23,34 +22,29 @@ array_t *imlib_count_blobs(struct image *image) /* flood fill */ array_push_back(points, point_alloc(x, y)); - while(array_length(points)) { - int i = array_length(points)-1; - point_t *p = array_at(points, i); - int px = p->x; - int py = p->y; - array_erase(points, i); - + point_t *p; + while((p = array_pop_back(points))!= NULL) { /* add point to blob */ - if (px < blob->x) { - blob->x = px; + if (p->x < blob->x) { + blob->x = p->x; } - if (py < blob->y) { + if (p->y < blob->y) { blob->y = y; } - if (px > blob->w) { - blob->w = px; + if (p->x > blob->w) { + blob->w = p->x; } - if (py > blob->h) { - blob->h = py; + if (p->y > blob->h) { + blob->h = p->y; } - if (pixels[py*image->w+px]) { - pixels[py*image->w+px]=0x0000; - array_push_back(points, point_alloc(px-1, py)); - array_push_back(points, point_alloc(px+1, py)); - array_push_back(points, point_alloc(px, py-1)); - array_push_back(points, point_alloc(px, py+1)); + if (pixels[p->y*image->w+p->x]) { + pixels[p->y*image->w+p->x]=0x0000; + array_push_back(points, point_alloc(p->x-1, p->y)); + array_push_back(points, point_alloc(p->x+1, p->y)); + array_push_back(points, point_alloc(p->x, p->y-1)); + array_push_back(points, point_alloc(p->x, p->y+1)); } } } @@ -60,12 +54,13 @@ array_t *imlib_count_blobs(struct image *image) for (int i=0; iw < 10) { /* blob too small */ - array_erase(blobs, i); + //array_erase(blobs, i); i--; } else { blob->w = blob->w - blob->x; blob->h = blob->h - blob->y; } } + //array_free(points); return blobs; } diff --git a/src/img/haar.c b/src/img/haar.c index 0a634a222..aee6cb276 100644 --- a/src/img/haar.c +++ b/src/img/haar.c @@ -74,7 +74,7 @@ static int runCascadeClassifier(struct cascade* cascade, struct point pt, int st - cascade->sum.data[cascade->sum.w * win_h + p_offset] + cascade->sum.data[cascade->sum.w * win_h + win_w + p_offset]; - std = sqrtf(sumsq * cascade->window.w * cascade->window.h - mean * mean); + std = fast_sqrtf(sumsq * cascade->window.w * cascade->window.h - mean * mean); for (i=start_stage; in_stages; i++) { stage_sum = 0; @@ -102,8 +102,8 @@ static void ScaleImageInvoker(struct cascade *cascade, float factor, int sum_row struct point p; struct size win_size; - win_size.w = roundf(cascade->window.w*factor); - win_size.h = roundf(cascade->window.h*factor); + win_size.w = fast_roundf(cascade->window.w*factor); + win_size.h = fast_roundf(cascade->window.h*factor); /* When filter window shifts to image boarder, some margin need to be kept */ y2 = sum_row - win_size.h; @@ -120,8 +120,8 @@ static void ScaleImageInvoker(struct cascade *cascade, float factor, int sum_row /* If a face is detected, record the coordinates of the filter window */ if (result > 0) { struct rectangle *r = xalloc(sizeof(struct rectangle)); - r->x = roundf(x*factor); - r->y = roundf(y*factor); + r->x = fast_roundf(x*factor); + r->y = fast_roundf(y*factor); r->w = win_size.w; r->h = win_size.h; array_push_back(vec, r); diff --git a/src/img/integral.c b/src/img/integral.c index 76aa7d4c0..391dca380 100644 --- a/src/img/integral.c +++ b/src/img/integral.c @@ -1,6 +1,5 @@ #include #include -#include #include #include "imlib.h" diff --git a/src/img/kmeans.c b/src/img/kmeans.c index 69eef0bf4..8eca358d5 100644 --- a/src/img/kmeans.c +++ b/src/img/kmeans.c @@ -1,6 +1,5 @@ #include #include -#include #include #include "imlib.h" #include "array.h" diff --git a/src/img/median.c b/src/img/median.c index 932c9688e..097f21dd2 100644 --- a/src/img/median.c +++ b/src/img/median.c @@ -1,7 +1,6 @@ #include #include "xalloc.h" #include "imlib.h" -#include #include #define R8(p) \ (uint8_t)((p>>11) * 255/31) diff --git a/src/img/point.c b/src/img/point.c index 8a993f46b..b4af5ed80 100644 --- a/src/img/point.c +++ b/src/img/point.c @@ -1,6 +1,5 @@ #include #include -#include #include #include "imlib.h" #include "array.h" @@ -26,5 +25,5 @@ float point_distance(point_t *p1, point_t *p2) float sum=0.0f; sum += (p1->x - p2->x) * (p1->x - p2->x); sum += (p1->y - p2->y) * (p1->y - p2->y); - return sqrtf(sum); + return fast_sqrtf(sum); } diff --git a/src/img/rectangle.c b/src/img/rectangle.c index 7781e7bc0..5b3757e43 100644 --- a/src/img/rectangle.c +++ b/src/img/rectangle.c @@ -1,6 +1,5 @@ #include #include -#include #include #include "imlib.h" #include "array.h" diff --git a/src/img/surf.c b/src/img/surf.c index 350eac034..cb1039de1 100644 --- a/src/img/surf.c +++ b/src/img/surf.c @@ -11,7 +11,6 @@ #include #include #include -#include #include #include "array.h" #include "xalloc.h" @@ -60,12 +59,6 @@ void arm_mat_free(arm_matrix_instance_f32 *m) xfree(m); } -//! Round float to nearest integer -static inline int fRound(float flt) -{ - return (int) floor(flt+0.5f); -} - /* Computes the sum of pixels within the rectangle specified by the top-left start co-ordinate and size. */ static float box_integral(i_image_t *img, int row, int col, int rows, int cols) @@ -94,19 +87,19 @@ static float box_integral(i_image_t *img, int row, int col, int rows, int cols) //! Calculate the value of the 2d gaussian at x,y static inline float gaussian(int x, int y, float sig) { - return (1.0f/(2.0f*pi*sig*sig)) * expf( -(x*x+y*y)/(2.0f*sig*sig)); + return (1.0f/(2.0f*pi*sig*sig)) * fast_expf(-(x*x+y*y)/(2.0f*sig*sig)); } //! Calculate the value of the 2d gaussian at x,y static inline float gaussianf(float x, float y, float sig) { - return 1.0f/(2.0f*pi*sig*sig) * expf(-(x*x+y*y)/(2.0f*sig*sig)); + return 1.0f/(2.0f*pi*sig*sig) * fast_expf(-(x*x+y*y)/(2.0f*sig*sig)); } //! Calculate Haar wavelet responses in x direction static inline float haar_x(surf_t *surf, int row, int column, int s) { - return box_integral(surf->i_img, row-s/2, column, s, s/2) + return box_integral(surf->i_img, row-s/2, column, s, s/2) -1 * box_integral(surf->i_img, row-s/2, column-s/2, s, s/2); } @@ -121,16 +114,16 @@ static inline float haar_y(surf_t *surf, int row, int column, int s) static float get_angle(float x, float y) { if(x > 0 && y >= 0) - return atan(y/x); + return fast_atanf(y/x); if(x < 0 && y >= 0) - return pi - atanf(-y/x); + return pi - fast_atanf(-y/x); if(x < 0 && y < 0) - return pi + atanf(y/x); + return pi + fast_atanf(y/x); if(x > 0 && y < 0) - return 2*pi - atanf(-y/x); + return 2*pi - fast_atanf(-y/x); return 0; } @@ -139,9 +132,9 @@ static float get_angle(float x, float y) static void get_orientation(surf_t *surf, i_point_t *ipt) { float gauss = 0.f, scale = ipt->scale; - const int s = fRound(scale); - const int r = fRound(ipt->y); - const int c = fRound(ipt->x); + const int s = fast_roundf(scale); + const int r = fast_roundf(ipt->y); + const int c = fast_roundf(ipt->x); float resX[109]; float resY[109]; float Ang[109]; @@ -212,8 +205,8 @@ static void get_descriptor(surf_t *surf, i_point_t *ipt, bool bUpright) float cx = -0.5f, cy = 0.f; //Subregion centers for the 4x4 gaussian weighting scale = ipt->scale; - x = fRound(ipt->x); - y = fRound(ipt->y); + x = fast_roundf(ipt->x); + y = fast_roundf(ipt->y); desc = ipt->descriptor; if (bUpright) { @@ -243,19 +236,19 @@ static void get_descriptor(surf_t *surf, i_point_t *ipt, bool bUpright) ix = i + 5; jx = j + 5; - xs = fRound(x + ( -jx*scale*si + ix*scale*co)); - ys = fRound(y + ( jx*scale*co + ix*scale*si)); + xs = fast_roundf(x + ( -jx*scale*si + ix*scale*co)); + ys = fast_roundf(y + ( jx*scale*co + ix*scale*si)); for (int k = i; k < i + 9; ++k) { for (int l = j; l < j + 9; ++l) { //Get coords of sample point on the rotated axis - sample_x = fRound(x + (-l*scale*si + k*scale*co)); - sample_y = fRound(y + ( l*scale*co + k*scale*si)); + sample_x = fast_roundf(x + (-l*scale*si + k*scale*co)); + sample_y = fast_roundf(y + ( l*scale*co + k*scale*si)); //Get the gaussian weighted x and y responses gauss_s1 = gaussian(xs-sample_x,ys-sample_y,2.5f*scale); - rx = haar_x(surf, sample_y, sample_x, 2*fRound(scale)); - ry = haar_y(surf, sample_y, sample_x, 2*fRound(scale)); + rx = haar_x(surf, sample_y, sample_x, 2*fast_roundf(scale)); + ry = haar_y(surf, sample_y, sample_x, 2*fast_roundf(scale)); //Get the gaussian weighted x and y responses on rotated axis rrx = gauss_s1*(-rx*si + ry*co); @@ -263,8 +256,8 @@ static void get_descriptor(surf_t *surf, i_point_t *ipt, bool bUpright) dx += rrx; dy += rry; - mdx += fabsf(rrx); - mdy += fabsf(rry); + mdx += fast_fabsf(rrx); + mdy += fast_fabsf(rry); } } @@ -291,7 +284,7 @@ static void get_descriptor(surf_t *surf, i_point_t *ipt, bool bUpright) done: //Convert to Unit Vector - len = sqrtf(len); + len = fast_sqrtf(len); for(int i = 0; i x = (float)((c + xc) * t->step); ipt->y = (float)((r + xr) * t->step); @@ -577,7 +570,7 @@ float i_point_sub(i_point_t *lhs, i_point_t *rhs) { for (int i=0; idescriptor[i] - rhs->descriptor[i])*(lhs->descriptor[i] - rhs->descriptor[i]); } - return sqrtf(sum); + return fast_sqrtf(sum); }; static array_t *get_matches(array_t *ipts1, array_t *ipts2) diff --git a/src/img/template.c b/src/img/template.c index 219e77e80..68d06f89e 100644 --- a/src/img/template.c +++ b/src/img/template.c @@ -1,7 +1,6 @@ #include #include "xalloc.h" #include "imlib.h" -#include #include int imlib_save_template(struct image *image, const char *path) @@ -142,7 +141,7 @@ float imlib_template_match(struct image *f, struct image *t_orig, struct rectan int a_den = f_sumsq-(f_sum*(long)f_sum)/(t->w*t->h); /* this overflows */ //corr = sum_shift/sqrtf(a_den*b_den); - float c = sum_shift/(sqrtf(a_den)*sqrtf(b_den)); + float c = sum_shift/(fast_sqrtf(a_den)*fast_sqrtf(b_den)); if (c > corr) { corr = c;