@@ -12,6 +12,43 @@ extern "C" {
1212
1313using namespace cv ;
1414
15+ mp_obj_t cv2_imgproc_adaptiveThreshold (size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
16+ // Define the arguments
17+ enum { ARG_src, ARG_maxValue, ARG_adaptiveMethod, ARG_thresholdType, ARG_blockSize, ARG_C, ARG_dst };
18+ static const mp_arg_t allowed_args[] = {
19+ { MP_QSTR_src, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
20+ { MP_QSTR_maxValue, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
21+ { MP_QSTR_adaptiveMethod, MP_ARG_REQUIRED | MP_ARG_INT, { .u_int = 0 } },
22+ { MP_QSTR_thresholdType, MP_ARG_REQUIRED | MP_ARG_INT, { .u_int = 0 } },
23+ { MP_QSTR_blockSize, MP_ARG_REQUIRED | MP_ARG_INT, { .u_int = 0 } },
24+ { MP_QSTR_C, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
25+ { MP_QSTR_dst, MP_ARG_OBJ, { .u_obj = mp_const_none } },
26+ };
27+
28+ // Parse the arguments
29+ mp_arg_val_t args[MP_ARRAY_SIZE (allowed_args)];
30+ mp_arg_parse_all (n_args, pos_args, kw_args, MP_ARRAY_SIZE (allowed_args), allowed_args, args);
31+
32+ // Convert arguments to required types
33+ Mat src = mp_obj_to_mat (args[ARG_src].u_obj );
34+ mp_float_t maxValue = mp_obj_get_float (args[ARG_maxValue].u_obj );
35+ int adaptiveMethod = args[ARG_adaptiveMethod].u_int ;
36+ int thresholdType = args[ARG_thresholdType].u_int ;
37+ int blockSize = args[ARG_blockSize].u_int ;
38+ mp_float_t C = mp_obj_get_float (args[ARG_C].u_obj );
39+ Mat dst = mp_obj_to_mat (args[ARG_dst].u_obj );
40+
41+ // Call the corresponding OpenCV function
42+ try {
43+ adaptiveThreshold (src, dst, maxValue, adaptiveMethod, thresholdType, blockSize, C);
44+ } catch (Exception& e) {
45+ mp_raise_msg (&mp_type_Exception, MP_ERROR_TEXT (e.what ()));
46+ }
47+
48+ // Return the result
49+ return mat_to_mp_obj (dst);
50+ }
51+
1552mp_obj_t cv2_imgproc_arrowedLine (size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
1653 // Define the arguments
1754 enum { ARG_img, ARG_pt1, ARG_pt2, ARG_color, ARG_thickness, ARG_line_type, ARG_shift, ARG_tipLength };
@@ -1259,3 +1296,36 @@ mp_obj_t cv2_imgproc_spatialGradient(size_t n_args, const mp_obj_t *pos_args, mp
12591296 result[1 ] = mat_to_mp_obj (dy);
12601297 return mp_obj_new_tuple (2 , result);
12611298}
1299+
1300+ mp_obj_t cv2_imgproc_threshold (size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
1301+ // Define the arguments
1302+ enum { ARG_src, ARG_thresh, ARG_maxval, ARG_type, ARG_dst };
1303+ static const mp_arg_t allowed_args[] = {
1304+ { MP_QSTR_src, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
1305+ { MP_QSTR_thresh, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
1306+ { MP_QSTR_maxval, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
1307+ { MP_QSTR_type, MP_ARG_REQUIRED | MP_ARG_INT, { .u_int = THRESH_BINARY } },
1308+ { MP_QSTR_dst, MP_ARG_OBJ, { .u_obj = mp_const_none } },
1309+ };
1310+
1311+ // Parse the arguments
1312+ mp_arg_val_t args[MP_ARRAY_SIZE (allowed_args)];
1313+ mp_arg_parse_all (n_args, pos_args, kw_args, MP_ARRAY_SIZE (allowed_args), allowed_args, args);
1314+
1315+ // Convert arguments to required types
1316+ Mat src = mp_obj_to_mat (args[ARG_src].u_obj );
1317+ mp_float_t thresh = mp_obj_get_float (args[ARG_thresh].u_obj );
1318+ mp_float_t maxval = mp_obj_get_float (args[ARG_maxval].u_obj );
1319+ int type = args[ARG_type].u_int ;
1320+ Mat dst = mp_obj_to_mat (args[ARG_dst].u_obj );
1321+
1322+ // Call the corresponding OpenCV function
1323+ try {
1324+ threshold (src, dst, thresh, maxval, type);
1325+ } catch (Exception& e) {
1326+ mp_raise_msg (&mp_type_Exception, MP_ERROR_TEXT (e.what ()));
1327+ }
1328+
1329+ // Return the result
1330+ return mat_to_mp_obj (dst);
1331+ }
0 commit comments