Skip to content

Commit

Permalink
Merge pull request openmv#2215 from kwagyeman/kwabena/ksize_fix
Browse files Browse the repository at this point in the history
modules/py_image: Move ksize to be pos_arg.
  • Loading branch information
iabdalkader authored May 21, 2024
2 parents 28d5fdf + f928965 commit 44e92b4
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/omv/modules/py_image.c
Original file line number Diff line number Diff line change
Expand Up @@ -2065,48 +2065,48 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(py_image_b_xnor_obj, 2, py_image_b_xnor);

static mp_obj_t py_image_binary_morph_op(uint n_args, const mp_obj_t *pos_args, mp_map_t *kw_args,
binary_morph_op_t op) {
enum { ARG_ksize, ARG_threshold, ARG_mask };
enum { ARG_threshold, ARG_mask };
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_ksize, MP_ARG_INT | MP_ARG_REQUIRED, },
{ MP_QSTR_threshold, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0 } },
{ MP_QSTR_mask, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_rom_obj = MP_ROM_NONE} },
};

// Parse args.
image_t *image = py_helper_arg_to_image(pos_args[0], ARG_IMAGE_MUTABLE);
int ksize = py_helper_arg_to_ksize(pos_args[1]);
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
mp_arg_parse_all(n_args - 2, pos_args + 2, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);

fb_alloc_mark();
image_t *mask = NULL;
if (args[ARG_mask].u_obj != mp_const_none) {
mask = py_helper_arg_to_image(args[ARG_mask].u_obj, ARG_IMAGE_MUTABLE | ARG_IMAGE_ALLOC);
}

op(image, args[ARG_ksize].u_int, args[ARG_threshold].u_int, mask);
op(image, ksize, args[ARG_threshold].u_int, mask);
fb_alloc_free_till_mark();
return pos_args[0];
}

STATIC mp_obj_t py_image_erode(uint n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
return py_image_binary_morph_op(n_args, pos_args, kw_args, imlib_erode);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(py_image_erode_obj, 1, py_image_erode);
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(py_image_erode_obj, 2, py_image_erode);

STATIC mp_obj_t py_image_dilate(uint n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
return py_image_binary_morph_op(n_args, pos_args, kw_args, imlib_dilate);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(py_image_dilate_obj, 1, py_image_dilate);
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(py_image_dilate_obj, 2, py_image_dilate);

STATIC mp_obj_t py_image_open(uint n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
return py_image_binary_morph_op(n_args, pos_args, kw_args, imlib_open);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(py_image_open_obj, 1, py_image_open);
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(py_image_open_obj, 2, py_image_open);

STATIC mp_obj_t py_image_close(uint n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
return py_image_binary_morph_op(n_args, pos_args, kw_args, imlib_close);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(py_image_close_obj, 1, py_image_close);
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(py_image_close_obj, 2, py_image_close);
#endif // IMLIB_ENABLE_BINARY_OPS

#ifdef IMLIB_ENABLE_MATH_OPS
Expand Down Expand Up @@ -2315,12 +2315,12 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(py_image_blend_obj, 2, py_image_blend);
STATIC mp_obj_t py_image_top_hat(uint n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
return py_image_binary_morph_op(n_args, pos_args, kw_args, imlib_top_hat);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(py_image_top_hat_obj, 1, py_image_top_hat);
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 *pos_args, mp_map_t *kw_args) {
return py_image_binary_morph_op(n_args, pos_args, kw_args, imlib_black_hat);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(py_image_black_hat_obj, 1, py_image_black_hat);
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)

////////////////////
Expand Down

0 comments on commit 44e92b4

Please sign in to comment.