From 902ae3c98bfa0bc0e3c9d021c7789578a719e6b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=BC=80=E6=99=BA?= Date: Sun, 3 Jan 2021 22:04:44 +0800 Subject: [PATCH] faster hough (#1068) 1, change `sqrt(a*a + b*b)` to `(abs(a)+abs(b))/2` 2, drop small mag calculate --- src/omv/imlib/hough.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/omv/imlib/hough.c b/src/omv/imlib/hough.c index f726dcab8..33a422270 100644 --- a/src/omv/imlib/hough.c +++ b/src/omv/imlib/hough.c @@ -81,14 +81,16 @@ void imlib_find_lines(list_t *out, image_t *ptr, rectangle_t *roi, unsigned int row_ptr -= ((ptr->w + UINT32_T_MASK) >> UINT32_T_SHIFT); + int mag = (abs(x_acc) + abs(y_acc)) / 2; + if (mag < 126) + continue; + int theta = fast_roundf((x_acc ? fast_atan2f(y_acc, x_acc) : 1.570796f) * 57.295780) % 180; // * (180 / PI) if (theta < 0) theta += 180; int rho = (fast_roundf(((x - roi->x) * cos_table[theta]) + ((y - roi->y) * sin_table[theta])) / hough_divide) + r_diag_len_div; int acc_index = (rho * theta_size) + ((theta / hough_divide) + 1); // add offset - - int acc_value = acc[acc_index] + fast_roundf(fast_sqrtf((x_acc * x_acc) + (y_acc * y_acc))); - acc[acc_index] = acc_value; + acc[acc_index] += mag; } } break; @@ -145,14 +147,16 @@ void imlib_find_lines(list_t *out, image_t *ptr, rectangle_t *roi, unsigned int row_ptr -= ptr->w; + int mag = (abs(x_acc) + abs(y_acc)) / 2; + if (mag < 126) + continue; + int theta = fast_roundf((x_acc ? fast_atan2f(y_acc, x_acc) : 1.570796f) * 57.295780) % 180; // * (180 / PI) if (theta < 0) theta += 180; - int rho = (fast_roundf(((x - roi->x) * cos_table[theta]) - + ((y - roi->y) * sin_table[theta])) / hough_divide) + r_diag_len_div; + int rho = (fast_roundf(((x - roi->x) * cos_table[theta]) + + ((y - roi->y) * sin_table[theta])) / hough_divide) + r_diag_len_div; int acc_index = (rho * theta_size) + ((theta / hough_divide) + 1); // add offset - - int acc_value = acc[acc_index] + fast_roundf(fast_sqrtf((x_acc * x_acc) + (y_acc * y_acc))); - acc[acc_index] = acc_value; + acc[acc_index] += mag; } } break; @@ -209,14 +213,16 @@ void imlib_find_lines(list_t *out, image_t *ptr, rectangle_t *roi, unsigned int row_ptr -= ptr->w; + int mag = (abs(x_acc) + abs(y_acc)) / 2; + if (mag < 126) + continue; + int theta = fast_roundf((x_acc ? fast_atan2f(y_acc, x_acc) : 1.570796f) * 57.295780) % 180; // * (180 / PI) if (theta < 0) theta += 180; - int rho = (fast_roundf(((x - roi->x) * cos_table[theta]) - + ((y - roi->y) * sin_table[theta])) / hough_divide) + r_diag_len_div; + int rho = (fast_roundf(((x - roi->x) * cos_table[theta]) + + ((y - roi->y) * sin_table[theta])) / hough_divide) + r_diag_len_div; int acc_index = (rho * theta_size) + ((theta / hough_divide) + 1); // add offset - - int acc_value = acc[acc_index] + fast_roundf(fast_sqrtf((x_acc * x_acc) + (y_acc * y_acc))); - acc[acc_index] = acc_value; + acc[acc_index] += mag; } } break;