From 7c684670cac5edf1d21c0f31bc87146c63aa00de Mon Sep 17 00:00:00 2001 From: "Kwabena W. Agyeman" Date: Sat, 25 Sep 2021 12:57:33 -0700 Subject: [PATCH] Move find_line_segments to draw image --- src/omv/imlib/lsd.c | 49 +++++++++----------------------------- src/omv/modules/py_image.c | 2 +- 2 files changed, 12 insertions(+), 39 deletions(-) diff --git a/src/omv/imlib/lsd.c b/src/omv/imlib/lsd.c index a92070da2..a0931adf5 100644 --- a/src/omv/imlib/lsd.c +++ b/src/omv/imlib/lsd.c @@ -513,7 +513,7 @@ static int double_equal(float a, float b) abs_diff = fabs(a-b); // For the numbers we work with, this is valid test that avoids some calculations. - // The error threshold tested below is 1/1000 of the diff/max_val + // The error threshold tested below is 1/1000 of the diff/max_val if (abs_diff > 0.1f) return FALSE; aa = fabs(a); bb = fabs(b); @@ -1936,7 +1936,7 @@ void ri_ini_fast(rect_iter *i, struct rect * r) /* advance to the first pixel */ ri_inc(i); - + } /* ri_ini_fast() */ /*----------------------------------------------------------------------------*/ @@ -2742,45 +2742,18 @@ float * lsd(int * n_out, unsigned char * img, int X, int Y) void imlib_lsd_find_line_segments(list_t *out, image_t *ptr, rectangle_t *roi, unsigned int merge_distance, unsigned int max_theta_diff) { uint8_t *grayscale_image = fb_alloc(roi->w * roi->h, FB_ALLOC_NO_HINT); - uint8_t *grayscale_image_tmp = grayscale_image; + + image_t img; + img.w = roi->w; + img.h = roi->h; + img.pixfmt = PIXFORMAT_GRAYSCALE; + img.data = grayscale_image; + imlib_draw_image(&img, ptr, 0, 0, 1.f, 1.f, roi, -1, 256, NULL, NULL, 0, NULL, NULL); + umm_init_x(fb_avail()); - switch (ptr->pixfmt) { - case PIXFORMAT_BINARY: { - for (int y = roi->y, yy = roi->y + roi->h; y < yy; y++) { - uint32_t *row_ptr = IMAGE_COMPUTE_BINARY_PIXEL_ROW_PTR(ptr, y); - for (int x = roi->x, xx = roi->x + roi->w; x < xx; x++) { - *(grayscale_image++) = COLOR_BINARY_TO_GRAYSCALE(IMAGE_GET_BINARY_PIXEL_FAST(row_ptr, x)); - } - } - break; - } - case PIXFORMAT_GRAYSCALE: { - for (int y = roi->y, yy = roi->y + roi->h; y < yy; y++) { - uint8_t *row_ptr = IMAGE_COMPUTE_GRAYSCALE_PIXEL_ROW_PTR(ptr, y); - for (int x = roi->x, xx = roi->x + roi->w; x < xx; x++) { - *(grayscale_image++) = IMAGE_GET_GRAYSCALE_PIXEL_FAST(row_ptr, x); - } - } - break; - } - case PIXFORMAT_RGB565: { - for (int y = roi->y, yy = roi->y + roi->h; y < yy; y++) { - uint16_t *row_ptr = IMAGE_COMPUTE_RGB565_PIXEL_ROW_PTR(ptr, y); - for (int x = roi->x, xx = roi->x + roi->w; x < xx; x++) { - *(grayscale_image++) = COLOR_RGB565_TO_GRAYSCALE(IMAGE_GET_RGB565_PIXEL_FAST(row_ptr, x)); - } - } - break; - } - default: { - memset(grayscale_image, 0, roi->w * roi->h); - break; - } - } - int n_ls; - float *ls = LineSegmentDetection(&n_ls, grayscale_image_tmp, roi->w, roi->h, 0.8, 0.6, 2.0, 22.5, 0.0, 0.7, 1024, NULL, NULL, NULL); + float *ls = LineSegmentDetection(&n_ls, grayscale_image, roi->w, roi->h, 0.8, 0.6, 2.0, 22.5, 0.0, 0.7, 1024, NULL, NULL, NULL); list_init(out, sizeof(find_lines_list_lnk_data_t)); for (int i = 0, j = n_ls; i < j; i++) { diff --git a/src/omv/modules/py_image.c b/src/omv/modules/py_image.c index fc3ecccb3..f1200f649 100644 --- a/src/omv/modules/py_image.c +++ b/src/omv/modules/py_image.c @@ -4674,7 +4674,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(py_image_find_lines_obj, 1, py_image_find_line #ifdef IMLIB_ENABLE_FIND_LINE_SEGMENTS static mp_obj_t py_image_find_line_segments(uint n_args, const mp_obj_t *args, mp_map_t *kw_args) { - image_t *arg_img = py_helper_arg_to_image_mutable(args[0]); + image_t *arg_img = py_image_cobj(args[0]); rectangle_t roi; py_helper_keyword_rectangle_roi(arg_img, n_args, args, 1, kw_args, &roi);