From c548c336f97cb165a95187313bf22f45d259e1fa Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Sun, 22 Nov 2020 22:42:15 +0200 Subject: [PATCH 1/4] Fix black/top hat. * Depend on both binary and math ops. --- src/omv/py/py_image.c | 77 +++++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 36 deletions(-) diff --git a/src/omv/py/py_image.c b/src/omv/py/py_image.c index 503177a10..cda39d251 100644 --- a/src/omv/py/py_image.c +++ b/src/omv/py/py_image.c @@ -2422,38 +2422,6 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(py_image_close_obj, 2, py_image_close); // Math Methods /////////////// -STATIC mp_obj_t py_image_top_hat(uint n_args, const mp_obj_t *args, mp_map_t *kw_args) -{ - int arg_ksize = - py_helper_arg_to_ksize(args[1]); - int arg_threshold = - py_helper_keyword_int(n_args, args, 2, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_threshold), 0); - image_t *arg_msk = - py_helper_keyword_to_image_mutable_mask(n_args, args, 3, kw_args); - - fb_alloc_mark(); - imlib_top_hat(py_helper_arg_to_image_mutable(args[0]), arg_ksize, arg_threshold, arg_msk); - fb_alloc_free_till_mark(); - return args[0]; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(py_image_top_hat_obj, 2, py_image_top_hat); - -STATIC mp_obj_t py_image_black_hat(uint n_args, const mp_obj_t *args, mp_map_t *kw_args) -{ - int arg_ksize = - py_helper_arg_to_ksize(args[1]); - int arg_threshold = - py_helper_keyword_int(n_args, args, 2, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_threshold), 0); - image_t *arg_msk = - py_helper_keyword_to_image_mutable_mask(n_args, args, 3, kw_args); - - fb_alloc_mark(); - imlib_black_hat(py_helper_arg_to_image_mutable(args[0]), arg_ksize, arg_threshold, arg_msk); - fb_alloc_free_till_mark(); - return args[0]; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(py_image_black_hat_obj, 2, py_image_black_hat); - STATIC mp_obj_t py_image_gamma_corr(uint n_args, const mp_obj_t *args, mp_map_t *kw_args) { image_t *arg_img = @@ -2741,6 +2709,40 @@ STATIC mp_obj_t py_image_blend(uint n_args, const mp_obj_t *args, mp_map_t *kw_a STATIC MP_DEFINE_CONST_FUN_OBJ_KW(py_image_blend_obj, 2, py_image_blend); #endif//IMLIB_ENABLE_MATH_OPS +#if defined(IMLIB_ENABLE_MATH_OPS) && defined (IMLIB_ENABLE_BINARY_OPS) +STATIC mp_obj_t py_image_top_hat(uint n_args, const mp_obj_t *args, mp_map_t *kw_args) +{ + int arg_ksize = + py_helper_arg_to_ksize(args[1]); + int arg_threshold = + py_helper_keyword_int(n_args, args, 2, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_threshold), 0); + image_t *arg_msk = + py_helper_keyword_to_image_mutable_mask(n_args, args, 3, kw_args); + + fb_alloc_mark(); + imlib_top_hat(py_helper_arg_to_image_mutable(args[0]), arg_ksize, arg_threshold, arg_msk); + fb_alloc_free_till_mark(); + return args[0]; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_KW(py_image_top_hat_obj, 2, py_image_top_hat); + +STATIC mp_obj_t py_image_black_hat(uint n_args, const mp_obj_t *args, mp_map_t *kw_args) +{ + int arg_ksize = + py_helper_arg_to_ksize(args[1]); + int arg_threshold = + py_helper_keyword_int(n_args, args, 2, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_threshold), 0); + image_t *arg_msk = + py_helper_keyword_to_image_mutable_mask(n_args, args, 3, kw_args); + + fb_alloc_mark(); + imlib_black_hat(py_helper_arg_to_image_mutable(args[0]), arg_ksize, arg_threshold, arg_msk); + fb_alloc_free_till_mark(); + return args[0]; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_KW(py_image_black_hat_obj, 2, py_image_black_hat); +#endif // defined(IMLIB_ENABLE_MATH_OPS) && defined (IMLIB_ENABLE_BINARY_OPS) + //////////////////// // Filtering Methods //////////////////// @@ -6416,8 +6418,6 @@ static const mp_rom_map_elem_t locals_dict_table[] = { {MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&py_func_unavailable_obj)}, #endif #ifdef IMLIB_ENABLE_MATH_OPS - {MP_ROM_QSTR(MP_QSTR_top_hat), MP_ROM_PTR(&py_image_top_hat_obj)}, - {MP_ROM_QSTR(MP_QSTR_black_hat), MP_ROM_PTR(&py_image_black_hat_obj)}, /* Math Methods */ {MP_ROM_QSTR(MP_QSTR_gamma_corr), MP_ROM_PTR(&py_image_gamma_corr_obj)}, {MP_ROM_QSTR(MP_QSTR_negate), MP_ROM_PTR(&py_image_negate_obj)}, @@ -6433,8 +6433,6 @@ static const mp_rom_map_elem_t locals_dict_table[] = { {MP_ROM_QSTR(MP_QSTR_difference), MP_ROM_PTR(&py_image_difference_obj)}, {MP_ROM_QSTR(MP_QSTR_blend), MP_ROM_PTR(&py_image_blend_obj)}, #else - {MP_ROM_QSTR(MP_QSTR_top_hat), MP_ROM_PTR(&py_func_unavailable_obj)}, - {MP_ROM_QSTR(MP_QSTR_black_hat), MP_ROM_PTR(&py_func_unavailable_obj)}, {MP_ROM_QSTR(MP_QSTR_negate), MP_ROM_PTR(&py_func_unavailable_obj)}, {MP_ROM_QSTR(MP_QSTR_assign), MP_ROM_PTR(&py_func_unavailable_obj)}, {MP_ROM_QSTR(MP_QSTR_replace), MP_ROM_PTR(&py_func_unavailable_obj)}, @@ -6448,6 +6446,13 @@ static const mp_rom_map_elem_t locals_dict_table[] = { {MP_ROM_QSTR(MP_QSTR_difference), MP_ROM_PTR(&py_func_unavailable_obj)}, {MP_ROM_QSTR(MP_QSTR_blend), MP_ROM_PTR(&py_func_unavailable_obj)}, #endif +#if defined(IMLIB_ENABLE_MATH_OPS) && defined (IMLIB_ENABLE_BINARY_OPS) + {MP_ROM_QSTR(MP_QSTR_top_hat), MP_ROM_PTR(&py_image_top_hat_obj)}, + {MP_ROM_QSTR(MP_QSTR_black_hat), MP_ROM_PTR(&py_image_black_hat_obj)}, +#else + {MP_ROM_QSTR(MP_QSTR_top_hat), MP_ROM_PTR(&py_func_unavailable_obj)}, + {MP_ROM_QSTR(MP_QSTR_black_hat), MP_ROM_PTR(&py_func_unavailable_obj)}, +#endif //defined(IMLIB_ENABLE_MATH_OPS) && defined (IMLIB_ENABLE_BINARY_OPS) /* Filtering Methods */ {MP_ROM_QSTR(MP_QSTR_histeq), MP_ROM_PTR(&py_image_histeq_obj)}, #ifdef IMLIB_ENABLE_MEAN From e705908a3fc446e9c43fef5be4fb2eea9c51d973 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Sun, 22 Nov 2020 23:06:05 +0200 Subject: [PATCH 2/4] Remove find_line_segments dependency on find_lines. --- src/omv/boards/OPENMV1/imlib_config.h | 6 ------ src/omv/boards/OPENMV2/imlib_config.h | 6 ------ src/omv/boards/OPENMV3/imlib_config.h | 6 ------ src/omv/boards/OPENMV4/imlib_config.h | 6 ------ src/omv/boards/OPENMV4P/imlib_config.h | 6 ------ src/omv/boards/OPENMVPURETHERMAL/imlib_config.h | 6 ------ src/omv/boards/PORTENTA/imlib_config.h | 6 ------ 7 files changed, 42 deletions(-) diff --git a/src/omv/boards/OPENMV1/imlib_config.h b/src/omv/boards/OPENMV1/imlib_config.h index 70125bc60..cde3056f5 100644 --- a/src/omv/boards/OPENMV1/imlib_config.h +++ b/src/omv/boards/OPENMV1/imlib_config.h @@ -47,12 +47,6 @@ // Enable find_line_segments() //#define IMLIB_ENABLE_FIND_LINE_SEGMENTS -// find_lines() is required by the old find_line_segments() -//#if defined(IMLIB_ENABLE_FIND_LINE_SEGMENTS)\ -// && !defined(IMLIB_ENABLE_FIND_LINES) -// #define IMLIB_ENABLE_FIND_LINES -//#endif - // Enable find_circles() //#define IMLIB_ENABLE_FIND_CIRCLES diff --git a/src/omv/boards/OPENMV2/imlib_config.h b/src/omv/boards/OPENMV2/imlib_config.h index d8bb4f782..e0699504d 100644 --- a/src/omv/boards/OPENMV2/imlib_config.h +++ b/src/omv/boards/OPENMV2/imlib_config.h @@ -86,12 +86,6 @@ // Enable find_line_segments() //#define IMLIB_ENABLE_FIND_LINE_SEGMENTS -// find_lines() is required by the old find_line_segments() -#if defined(IMLIB_ENABLE_FIND_LINE_SEGMENTS)\ - && !defined(IMLIB_ENABLE_FIND_LINES) - #define IMLIB_ENABLE_FIND_LINES -#endif - // Enable find_circles() //#define IMLIB_ENABLE_FIND_CIRCLES diff --git a/src/omv/boards/OPENMV3/imlib_config.h b/src/omv/boards/OPENMV3/imlib_config.h index b5eba1c37..a56589176 100644 --- a/src/omv/boards/OPENMV3/imlib_config.h +++ b/src/omv/boards/OPENMV3/imlib_config.h @@ -89,12 +89,6 @@ // Enable find_line_segments() #define IMLIB_ENABLE_FIND_LINE_SEGMENTS -// find_lines() is required by the old find_line_segments() -#if defined(IMLIB_ENABLE_FIND_LINE_SEGMENTS)\ - && !defined(IMLIB_ENABLE_FIND_LINES) - #define IMLIB_ENABLE_FIND_LINES -#endif - // Enable find_circles() #define IMLIB_ENABLE_FIND_CIRCLES diff --git a/src/omv/boards/OPENMV4/imlib_config.h b/src/omv/boards/OPENMV4/imlib_config.h index 8f92da13c..1f15a9690 100644 --- a/src/omv/boards/OPENMV4/imlib_config.h +++ b/src/omv/boards/OPENMV4/imlib_config.h @@ -89,12 +89,6 @@ // Enable find_line_segments() #define IMLIB_ENABLE_FIND_LINE_SEGMENTS -// find_lines() is required by the old find_line_segments() -#if defined(IMLIB_ENABLE_FIND_LINE_SEGMENTS)\ - && !defined(IMLIB_ENABLE_FIND_LINES) - #define IMLIB_ENABLE_FIND_LINES -#endif - // Enable find_circles() #define IMLIB_ENABLE_FIND_CIRCLES diff --git a/src/omv/boards/OPENMV4P/imlib_config.h b/src/omv/boards/OPENMV4P/imlib_config.h index 4a59bbc15..f49862e69 100644 --- a/src/omv/boards/OPENMV4P/imlib_config.h +++ b/src/omv/boards/OPENMV4P/imlib_config.h @@ -89,12 +89,6 @@ // Enable find_line_segments() #define IMLIB_ENABLE_FIND_LINE_SEGMENTS -// find_lines() is required by the old find_line_segments() -#if defined(IMLIB_ENABLE_FIND_LINE_SEGMENTS)\ - && !defined(IMLIB_ENABLE_FIND_LINES) - #define IMLIB_ENABLE_FIND_LINES -#endif - // Enable find_circles() #define IMLIB_ENABLE_FIND_CIRCLES diff --git a/src/omv/boards/OPENMVPURETHERMAL/imlib_config.h b/src/omv/boards/OPENMVPURETHERMAL/imlib_config.h index 6a804cfbb..eebc171a2 100644 --- a/src/omv/boards/OPENMVPURETHERMAL/imlib_config.h +++ b/src/omv/boards/OPENMVPURETHERMAL/imlib_config.h @@ -89,12 +89,6 @@ // Enable find_line_segments() #define IMLIB_ENABLE_FIND_LINE_SEGMENTS -// find_lines() is required by the old find_line_segments() -#if defined(IMLIB_ENABLE_FIND_LINE_SEGMENTS)\ - && !defined(IMLIB_ENABLE_FIND_LINES) - #define IMLIB_ENABLE_FIND_LINES -#endif - // Enable find_circles() #define IMLIB_ENABLE_FIND_CIRCLES diff --git a/src/omv/boards/PORTENTA/imlib_config.h b/src/omv/boards/PORTENTA/imlib_config.h index b4a4a881c..9a704d0ac 100644 --- a/src/omv/boards/PORTENTA/imlib_config.h +++ b/src/omv/boards/PORTENTA/imlib_config.h @@ -89,12 +89,6 @@ // Enable find_line_segments() #define IMLIB_ENABLE_FIND_LINE_SEGMENTS -// find_lines() is required by the old find_line_segments() -#if defined(IMLIB_ENABLE_FIND_LINE_SEGMENTS)\ - && !defined(IMLIB_ENABLE_FIND_LINES) - #define IMLIB_ENABLE_FIND_LINES -#endif - // Enable find_circles() #define IMLIB_ENABLE_FIND_CIRCLES From aab594f2d04bc0793cce1a0a88794a6a1f159520 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Sun, 22 Nov 2020 23:28:19 +0200 Subject: [PATCH 3/4] Allow find_rects and rot_corr to build with apriltags disabled. --- src/omv/img/apriltag.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/omv/img/apriltag.c b/src/omv/img/apriltag.c index 273dd199a..24f6e459b 100644 --- a/src/omv/img/apriltag.c +++ b/src/omv/img/apriltag.c @@ -16,7 +16,6 @@ // Enable new code optimizations #define OPTIMIZED -#ifdef IMLIB_ENABLE_APRILTAGS #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-variable" @@ -12561,4 +12560,3 @@ void imlib_rotation_corr(image_t *img, float x_rotation, float y_rotation, float } #endif //IMLIB_ENABLE_ROTATION_CORR #pragma GCC diagnostic pop -#endif //IMLIB_ENABLE_APRILTAGS From e76acbf2f39dc08a783c3dc7e3b52c5b9dd68e35 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Sun, 22 Nov 2020 23:46:58 +0200 Subject: [PATCH 4/4] Simplify phase/rotation correlation dependency. --- src/omv/boards/OPENMV1/imlib_config.h | 6 +----- src/omv/boards/OPENMV2/imlib_config.h | 6 +----- src/omv/boards/OPENMV3/imlib_config.h | 6 +----- src/omv/boards/OPENMV4/imlib_config.h | 6 +----- src/omv/boards/OPENMV4P/imlib_config.h | 6 +----- src/omv/boards/OPENMVPURETHERMAL/imlib_config.h | 6 +----- src/omv/boards/PORTENTA/imlib_config.h | 6 +----- 7 files changed, 7 insertions(+), 35 deletions(-) diff --git a/src/omv/boards/OPENMV1/imlib_config.h b/src/omv/boards/OPENMV1/imlib_config.h index cde3056f5..2f9d5191c 100644 --- a/src/omv/boards/OPENMV1/imlib_config.h +++ b/src/omv/boards/OPENMV1/imlib_config.h @@ -30,12 +30,8 @@ //#define IMLIB_ENABLE_ROTATION_CORR // Enable phasecorrelate() +#if defined(IMLIB_ENABLE_ROTATION_CORR) //#define IMLIB_ENABLE_FIND_DISPLACEMENT - -// rotation_corr() is required by phasecorrelate() -#if defined(IMLIB_ENABLE_FIND_DISPLACEMENT)\ - && !defined(IMLIB_ENABLE_ROTATION_CORR) - #define IMLIB_ENABLE_ROTATION_CORR #endif // Enable get_similarity() diff --git a/src/omv/boards/OPENMV2/imlib_config.h b/src/omv/boards/OPENMV2/imlib_config.h index e0699504d..233627085 100644 --- a/src/omv/boards/OPENMV2/imlib_config.h +++ b/src/omv/boards/OPENMV2/imlib_config.h @@ -69,12 +69,8 @@ //#define IMLIB_ENABLE_ROTATION_CORR // Enable phasecorrelate() +#if defined(IMLIB_ENABLE_ROTATION_CORR) //#define IMLIB_ENABLE_FIND_DISPLACEMENT - -// rotation_corr() is required by phasecorrelate() -#if defined(IMLIB_ENABLE_FIND_DISPLACEMENT)\ - && !defined(IMLIB_ENABLE_ROTATION_CORR) - #define IMLIB_ENABLE_ROTATION_CORR #endif // Enable get_similarity() diff --git a/src/omv/boards/OPENMV3/imlib_config.h b/src/omv/boards/OPENMV3/imlib_config.h index a56589176..1bfbe81c3 100644 --- a/src/omv/boards/OPENMV3/imlib_config.h +++ b/src/omv/boards/OPENMV3/imlib_config.h @@ -72,12 +72,8 @@ #define IMLIB_ENABLE_ROTATION_CORR // Enable phasecorrelate() +#if defined(IMLIB_ENABLE_ROTATION_CORR) #define IMLIB_ENABLE_FIND_DISPLACEMENT - -// rotation_corr() is required by phasecorrelate() -#if defined(IMLIB_ENABLE_FIND_DISPLACEMENT)\ - && !defined(IMLIB_ENABLE_ROTATION_CORR) - #define IMLIB_ENABLE_ROTATION_CORR #endif // Enable get_similarity() diff --git a/src/omv/boards/OPENMV4/imlib_config.h b/src/omv/boards/OPENMV4/imlib_config.h index 1f15a9690..c182107d1 100644 --- a/src/omv/boards/OPENMV4/imlib_config.h +++ b/src/omv/boards/OPENMV4/imlib_config.h @@ -72,12 +72,8 @@ #define IMLIB_ENABLE_ROTATION_CORR // Enable phasecorrelate() +#if defined(IMLIB_ENABLE_ROTATION_CORR) #define IMLIB_ENABLE_FIND_DISPLACEMENT - -// rotation_corr() is required by phasecorrelate() -#if defined(IMLIB_ENABLE_FIND_DISPLACEMENT)\ - && !defined(IMLIB_ENABLE_ROTATION_CORR) - #define IMLIB_ENABLE_ROTATION_CORR #endif // Enable get_similarity() diff --git a/src/omv/boards/OPENMV4P/imlib_config.h b/src/omv/boards/OPENMV4P/imlib_config.h index f49862e69..2d00d8d58 100644 --- a/src/omv/boards/OPENMV4P/imlib_config.h +++ b/src/omv/boards/OPENMV4P/imlib_config.h @@ -72,12 +72,8 @@ #define IMLIB_ENABLE_ROTATION_CORR // Enable phasecorrelate() +#if defined(IMLIB_ENABLE_ROTATION_CORR) #define IMLIB_ENABLE_FIND_DISPLACEMENT - -// rotation_corr() is required by phasecorrelate() -#if defined(IMLIB_ENABLE_FIND_DISPLACEMENT)\ - && !defined(IMLIB_ENABLE_ROTATION_CORR) - #define IMLIB_ENABLE_ROTATION_CORR #endif // Enable get_similarity() diff --git a/src/omv/boards/OPENMVPURETHERMAL/imlib_config.h b/src/omv/boards/OPENMVPURETHERMAL/imlib_config.h index eebc171a2..459292fdf 100644 --- a/src/omv/boards/OPENMVPURETHERMAL/imlib_config.h +++ b/src/omv/boards/OPENMVPURETHERMAL/imlib_config.h @@ -72,12 +72,8 @@ #define IMLIB_ENABLE_ROTATION_CORR // Enable phasecorrelate() +#if defined(IMLIB_ENABLE_ROTATION_CORR) #define IMLIB_ENABLE_FIND_DISPLACEMENT - -// rotation_corr() is required by phasecorrelate() -#if defined(IMLIB_ENABLE_FIND_DISPLACEMENT)\ - && !defined(IMLIB_ENABLE_ROTATION_CORR) - #define IMLIB_ENABLE_ROTATION_CORR #endif // Enable get_similarity() diff --git a/src/omv/boards/PORTENTA/imlib_config.h b/src/omv/boards/PORTENTA/imlib_config.h index 9a704d0ac..bbf43d61b 100644 --- a/src/omv/boards/PORTENTA/imlib_config.h +++ b/src/omv/boards/PORTENTA/imlib_config.h @@ -72,12 +72,8 @@ #define IMLIB_ENABLE_ROTATION_CORR // Enable phasecorrelate() +#if defined(IMLIB_ENABLE_ROTATION_CORR) #define IMLIB_ENABLE_FIND_DISPLACEMENT - -// rotation_corr() is required by phasecorrelate() -#if defined(IMLIB_ENABLE_FIND_DISPLACEMENT)\ - && !defined(IMLIB_ENABLE_ROTATION_CORR) - #define IMLIB_ENABLE_ROTATION_CORR #endif // Enable get_similarity()