@@ -55,6 +55,111 @@ mp_obj_t cv2_imgproc_arrowedLine(size_t n_args, const mp_obj_t *pos_args, mp_map
55
55
return mat_to_mp_obj (img);
56
56
}
57
57
58
+ mp_obj_t cv2_imgproc_bilateralFilter (size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
59
+ // Define the arguments
60
+ enum { ARG_src, ARG_d, ARG_sigmaColor, ARG_sigmaSpace, ARG_dst, ARG_borderType };
61
+ static const mp_arg_t allowed_args[] = {
62
+ { MP_QSTR_src, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
63
+ { MP_QSTR_d, MP_ARG_REQUIRED | MP_ARG_INT, { .u_int = 0 } },
64
+ { MP_QSTR_sigmaColor, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = mp_const_none } },
65
+ { MP_QSTR_sigmaSpace, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = mp_const_none } },
66
+ { MP_QSTR_dst, MP_ARG_OBJ, { .u_obj = mp_const_none } },
67
+ { MP_QSTR_borderType, MP_ARG_INT, { .u_int = BORDER_DEFAULT } },
68
+ };
69
+
70
+ // Parse the arguments
71
+ mp_arg_val_t args[MP_ARRAY_SIZE (allowed_args)];
72
+ mp_arg_parse_all (n_args, pos_args, kw_args, MP_ARRAY_SIZE (allowed_args), allowed_args, args);
73
+
74
+ // Convert arguments to required types
75
+ Mat src = mp_obj_to_mat (args[ARG_src].u_obj );
76
+ int d = args[ARG_d].u_int ;
77
+ mp_float_t sigmaColor = mp_obj_get_float (args[ARG_sigmaColor].u_obj );
78
+ mp_float_t sigmaSpace = mp_obj_get_float (args[ARG_sigmaSpace].u_obj );
79
+ Mat dst = mp_obj_to_mat (args[ARG_dst].u_obj );
80
+ int borderType = args[ARG_borderType].u_int ;
81
+
82
+ // Call the corresponding OpenCV function
83
+ try {
84
+ bilateralFilter (src, dst, d, sigmaColor, sigmaSpace, borderType);
85
+ } catch (Exception& e) {
86
+ mp_raise_msg (&mp_type_Exception, MP_ERROR_TEXT (e.what ()));
87
+ }
88
+
89
+ // Return the result
90
+ return mat_to_mp_obj (dst);
91
+ }
92
+
93
+ mp_obj_t cv2_imgproc_blur (size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
94
+ // Define the arguments
95
+ enum { ARG_src, ARG_ksize, ARG_dst, ARG_anchor, ARG_borderType };
96
+ static const mp_arg_t allowed_args[] = {
97
+ { MP_QSTR_src, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
98
+ { MP_QSTR_ksize, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
99
+ { MP_QSTR_dst, MP_ARG_OBJ, { .u_obj = mp_const_none } },
100
+ { MP_QSTR_anchor, MP_ARG_OBJ, { .u_obj = mp_const_none } },
101
+ { MP_QSTR_borderType, MP_ARG_INT, { .u_int = BORDER_DEFAULT } },
102
+ };
103
+
104
+ // Parse the arguments
105
+ mp_arg_val_t args[MP_ARRAY_SIZE (allowed_args)];
106
+ mp_arg_parse_all (n_args, pos_args, kw_args, MP_ARRAY_SIZE (allowed_args), allowed_args, args);
107
+
108
+ // Convert arguments to required types
109
+ Mat src = mp_obj_to_mat (args[ARG_src].u_obj );
110
+ Size ksize = mp_obj_to_size (args[ARG_ksize].u_obj );
111
+ Mat dst = mp_obj_to_mat (args[ARG_dst].u_obj );
112
+ Point anchor = args[ARG_anchor].u_obj == mp_const_none ? Point (-1 ,-1 ) : mp_obj_to_point (args[ARG_anchor].u_obj );
113
+ int borderType = args[ARG_borderType].u_int ;
114
+
115
+ // Call the corresponding OpenCV function
116
+ try {
117
+ blur (src, dst, ksize, anchor, borderType);
118
+ } catch (Exception& e) {
119
+ mp_raise_msg (&mp_type_Exception, MP_ERROR_TEXT (e.what ()));
120
+ }
121
+
122
+ // Return the result
123
+ return mat_to_mp_obj (dst);
124
+ }
125
+
126
+ mp_obj_t cv2_imgproc_boxFilter (size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
127
+ // Define the arguments
128
+ enum { ARG_src, ARG_ddepth, ARG_ksize, ARG_dst, ARG_anchor, ARG_normalize, ARG_borderType };
129
+ static const mp_arg_t allowed_args[] = {
130
+ { MP_QSTR_src, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
131
+ { MP_QSTR_ddepth, MP_ARG_REQUIRED | MP_ARG_INT, { .u_int = -1 } },
132
+ { MP_QSTR_ksize, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
133
+ { MP_QSTR_dst, MP_ARG_OBJ, { .u_obj = mp_const_none } },
134
+ { MP_QSTR_anchor, MP_ARG_OBJ, { .u_obj = mp_const_none } },
135
+ { MP_QSTR_normalize, MP_ARG_BOOL, { .u_bool = true } },
136
+ { MP_QSTR_borderType, MP_ARG_INT, { .u_int = BORDER_DEFAULT } },
137
+ };
138
+
139
+ // Parse the arguments
140
+ mp_arg_val_t args[MP_ARRAY_SIZE (allowed_args)];
141
+ mp_arg_parse_all (n_args, pos_args, kw_args, MP_ARRAY_SIZE (allowed_args), allowed_args, args);
142
+
143
+ // Convert arguments to required types
144
+ Mat src = mp_obj_to_mat (args[ARG_src].u_obj );
145
+ int ddepth = args[ARG_ddepth].u_int ;
146
+ Size ksize = mp_obj_to_size (args[ARG_ksize].u_obj );
147
+ Mat dst = mp_obj_to_mat (args[ARG_dst].u_obj );
148
+ Point anchor = args[ARG_anchor].u_obj == mp_const_none ? Point (-1 ,-1 ) : mp_obj_to_point (args[ARG_anchor].u_obj );
149
+ bool normalize = args[ARG_normalize].u_bool ;
150
+ int borderType = args[ARG_borderType].u_int ;
151
+
152
+ // Call the corresponding OpenCV function
153
+ try {
154
+ boxFilter (src, dst, ddepth, ksize, anchor, normalize, borderType);
155
+ } catch (Exception& e) {
156
+ mp_raise_msg (&mp_type_Exception, MP_ERROR_TEXT (e.what ()));
157
+ }
158
+
159
+ // Return the result
160
+ return mat_to_mp_obj (dst);
161
+ }
162
+
58
163
mp_obj_t cv2_imgproc_Canny (size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
59
164
// Define the arguments
60
165
enum { ARG_image, ARG_threshold1, ARG_threshold2, ARG_edges, ARG_apertureSize, ARG_L2gradient };
@@ -408,6 +513,84 @@ mp_obj_t cv2_imgproc_fillPoly(size_t n_args, const mp_obj_t *pos_args, mp_map_t
408
513
return mat_to_mp_obj (img);
409
514
}
410
515
516
+ mp_obj_t cv2_imgproc_filter2D (size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
517
+ // Define the arguments
518
+ enum { ARG_src, ARG_ddepth, ARG_kernel, ARG_dst, ARG_anchor, ARG_delta, ARG_borderType };
519
+ static const mp_arg_t allowed_args[] = {
520
+ { MP_QSTR_src, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
521
+ { MP_QSTR_ddepth, MP_ARG_REQUIRED | MP_ARG_INT, { .u_int = -1 } },
522
+ { MP_QSTR_kernel, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
523
+ { MP_QSTR_dst, MP_ARG_OBJ, { .u_obj = mp_const_none } },
524
+ { MP_QSTR_anchor, MP_ARG_OBJ, { .u_obj = mp_const_none } },
525
+ { MP_QSTR_delta, MP_ARG_OBJ, { .u_obj = mp_const_none } },
526
+ { MP_QSTR_borderType, MP_ARG_INT, { .u_int = BORDER_DEFAULT } },
527
+ };
528
+
529
+ // Parse the arguments
530
+ mp_arg_val_t args[MP_ARRAY_SIZE (allowed_args)];
531
+ mp_arg_parse_all (n_args, pos_args, kw_args, MP_ARRAY_SIZE (allowed_args), allowed_args, args);
532
+
533
+ // Convert arguments to required types
534
+ Mat src = mp_obj_to_mat (args[ARG_src].u_obj );
535
+ int ddepth = args[ARG_ddepth].u_int ;
536
+ Mat kernel = mp_obj_to_mat (args[ARG_kernel].u_obj );
537
+ Mat dst = mp_obj_to_mat (args[ARG_dst].u_obj );
538
+ Point anchor;
539
+ if (args[ARG_anchor].u_obj == mp_const_none)
540
+ anchor = Point (-1 ,-1 ); // Default value
541
+ else
542
+ anchor = mp_obj_to_point (args[ARG_anchor].u_obj );
543
+ mp_float_t delta = args[ARG_delta].u_obj == mp_const_none ? 0.0 : mp_obj_get_float (args[ARG_delta].u_obj );
544
+ int borderType = args[ARG_borderType].u_int ;
545
+
546
+ // Call the corresponding OpenCV function
547
+ try {
548
+ filter2D (src, dst, ddepth, kernel, anchor, delta, borderType);
549
+ } catch (Exception& e) {
550
+ mp_raise_msg (&mp_type_Exception, MP_ERROR_TEXT (e.what ()));
551
+ }
552
+
553
+ // Return the result
554
+ return mat_to_mp_obj (dst);
555
+ }
556
+
557
+ mp_obj_t cv2_imgproc_GaussianBlur (size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
558
+ // Define the arguments
559
+ enum { ARG_src, ARG_ksize, ARG_sigmaX, ARG_dst, ARG_sigmaY, ARG_borderType, ARG_hint };
560
+ static const mp_arg_t allowed_args[] = {
561
+ { MP_QSTR_src, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
562
+ { MP_QSTR_ksize, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
563
+ { MP_QSTR_sigmaX, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = mp_const_none } },
564
+ { MP_QSTR_dst, MP_ARG_OBJ, { .u_obj = mp_const_none } },
565
+ { MP_QSTR_sigmaY, MP_ARG_OBJ, { .u_obj = mp_const_none } },
566
+ { MP_QSTR_borderType, MP_ARG_INT, { .u_int = BORDER_DEFAULT } },
567
+ { MP_QSTR_hint, MP_ARG_INT, { .u_int = ALGO_HINT_DEFAULT } },
568
+ };
569
+
570
+ // Parse the arguments
571
+ mp_arg_val_t args[MP_ARRAY_SIZE (allowed_args)];
572
+ mp_arg_parse_all (n_args, pos_args, kw_args, MP_ARRAY_SIZE (allowed_args), allowed_args, args);
573
+
574
+ // Convert arguments to required types
575
+ Mat src = mp_obj_to_mat (args[ARG_src].u_obj );
576
+ Size ksize = mp_obj_to_size (args[ARG_ksize].u_obj );
577
+ mp_float_t sigmaX = mp_obj_get_float (args[ARG_sigmaX].u_obj );
578
+ Mat dst = mp_obj_to_mat (args[ARG_dst].u_obj );
579
+ mp_float_t sigmaY = args[ARG_sigmaY].u_obj == mp_const_none ? sigmaX : mp_obj_get_float (args[ARG_sigmaY].u_obj );
580
+ int borderType = args[ARG_borderType].u_int ;
581
+ AlgorithmHint hint = (AlgorithmHint) args[ARG_hint].u_int ;
582
+
583
+ // Call the corresponding OpenCV function
584
+ try {
585
+ GaussianBlur (src, dst, ksize, sigmaX, sigmaY, borderType, hint);
586
+ } catch (Exception& e) {
587
+ mp_raise_msg (&mp_type_Exception, MP_ERROR_TEXT (e.what ()));
588
+ }
589
+
590
+ // Return the result
591
+ return mat_to_mp_obj (dst);
592
+ }
593
+
411
594
mp_obj_t cv2_imgproc_getStructuringElement (size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
412
595
// Define the arguments
413
596
enum { ARG_shape, ARG_ksize, ARG_anchor };
@@ -768,6 +951,35 @@ mp_obj_t cv2_imgproc_line(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_
768
951
return mat_to_mp_obj (img);
769
952
}
770
953
954
+ mp_obj_t cv2_imgproc_medianBlur (size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
955
+ // Define the arguments
956
+ enum { ARG_src, ARG_ksize, ARG_dst };
957
+ static const mp_arg_t allowed_args[] = {
958
+ { MP_QSTR_src, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
959
+ { MP_QSTR_ksize, MP_ARG_REQUIRED | MP_ARG_INT, { .u_int = 0 } },
960
+ { MP_QSTR_dst, MP_ARG_OBJ, { .u_obj = mp_const_none } },
961
+ };
962
+
963
+ // Parse the arguments
964
+ mp_arg_val_t args[MP_ARRAY_SIZE (allowed_args)];
965
+ mp_arg_parse_all (n_args, pos_args, kw_args, MP_ARRAY_SIZE (allowed_args), allowed_args, args);
966
+
967
+ // Convert arguments to required types
968
+ Mat src = mp_obj_to_mat (args[ARG_src].u_obj );
969
+ int ksize = args[ARG_ksize].u_int ;
970
+ Mat dst = mp_obj_to_mat (args[ARG_dst].u_obj );
971
+
972
+ // Call the corresponding OpenCV function
973
+ try {
974
+ medianBlur (src, dst, ksize);
975
+ } catch (Exception& e) {
976
+ mp_raise_msg (&mp_type_Exception, MP_ERROR_TEXT (e.what ()));
977
+ }
978
+
979
+ // Return the result
980
+ return mat_to_mp_obj (dst);
981
+ }
982
+
771
983
mp_obj_t cv2_imgproc_morphologyEx (size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
772
984
// Define the arguments
773
985
enum { ARG_src, ARG_op, ARG_kernel, ARG_dst, ARG_anchor, ARG_iterations, ARG_borderType, ARG_borderValue };
0 commit comments