@@ -43,11 +43,15 @@ mp_obj_t cv2_imgproc_cvtColor(size_t n_args, const mp_obj_t *pos_args, mp_map_t
43
43
44
44
mp_obj_t cv2_imgproc_dilate (size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
45
45
// Define the arguments
46
- enum { ARG_src, ARG_kernel, ARG_dst };
46
+ enum { ARG_src, ARG_kernel, ARG_dst, ARG_anchor, ARG_iterations, ARG_borderType, ARG_borderValue };
47
47
static const mp_arg_t allowed_args[] = {
48
48
{ MP_QSTR_src, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
49
49
{ MP_QSTR_kernel, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
50
50
{ MP_QSTR_dst, MP_ARG_OBJ, { .u_obj = mp_const_none } },
51
+ { MP_QSTR_anchor, MP_ARG_OBJ, { .u_obj = mp_const_none } },
52
+ { MP_QSTR_iterations, MP_ARG_INT, { .u_int = 1 } },
53
+ { MP_QSTR_borderType, MP_ARG_INT, { .u_int = BORDER_CONSTANT } },
54
+ { MP_QSTR_borderValue, MP_ARG_OBJ, { .u_obj = mp_const_none } },
51
55
};
52
56
53
57
// Parse the arguments
@@ -58,10 +62,22 @@ mp_obj_t cv2_imgproc_dilate(size_t n_args, const mp_obj_t *pos_args, mp_map_t *k
58
62
Mat src = mp_obj_to_mat (args[ARG_src].u_obj );
59
63
Mat kernel = mp_obj_to_mat (args[ARG_kernel].u_obj );
60
64
Mat dst = mp_obj_to_mat (args[ARG_dst].u_obj );
65
+ Point anchor;
66
+ if (args[ARG_anchor].u_obj == mp_const_none)
67
+ anchor = Point (-1 , -1 ); // Default value
68
+ else
69
+ anchor = mp_obj_to_point (args[ARG_anchor].u_obj );
70
+ int iterations = args[ARG_iterations].u_int ;
71
+ int borderType = args[ARG_borderType].u_int ;
72
+ Scalar borderValue;
73
+ if (args[ARG_borderValue].u_obj == mp_const_none)
74
+ borderValue = morphologyDefaultBorderValue (); // Default value
75
+ else
76
+ borderValue = mp_obj_to_scalar (args[ARG_borderValue].u_obj );
61
77
62
78
// Call the corresponding OpenCV function
63
79
try {
64
- dilate (src, dst, kernel);
80
+ dilate (src, dst, kernel, anchor, iterations, borderType, borderValue );
65
81
} catch (Exception& e) {
66
82
mp_raise_msg (&mp_type_Exception, MP_ERROR_TEXT (e.what ()));
67
83
}
@@ -72,11 +88,15 @@ mp_obj_t cv2_imgproc_dilate(size_t n_args, const mp_obj_t *pos_args, mp_map_t *k
72
88
73
89
mp_obj_t cv2_imgproc_erode (size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
74
90
// Define the arguments
75
- enum { ARG_src, ARG_kernel, ARG_dst };
91
+ enum { ARG_src, ARG_kernel, ARG_dst, ARG_anchor, ARG_iterations, ARG_borderType, ARG_borderValue };
76
92
static const mp_arg_t allowed_args[] = {
77
93
{ MP_QSTR_src, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
78
94
{ MP_QSTR_kernel, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
79
95
{ MP_QSTR_dst, MP_ARG_OBJ, { .u_obj = mp_const_none } },
96
+ { MP_QSTR_anchor, MP_ARG_OBJ, { .u_obj = mp_const_none } },
97
+ { MP_QSTR_iterations, MP_ARG_INT, { .u_int = 1 } },
98
+ { MP_QSTR_borderType, MP_ARG_INT, { .u_int = BORDER_CONSTANT } },
99
+ { MP_QSTR_borderValue, MP_ARG_OBJ, { .u_obj = mp_const_none } },
80
100
};
81
101
82
102
// Parse the arguments
@@ -87,10 +107,22 @@ mp_obj_t cv2_imgproc_erode(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw
87
107
Mat src = mp_obj_to_mat (args[ARG_src].u_obj );
88
108
Mat kernel = mp_obj_to_mat (args[ARG_kernel].u_obj );
89
109
Mat dst = mp_obj_to_mat (args[ARG_dst].u_obj );
110
+ Point anchor;
111
+ if (args[ARG_anchor].u_obj == mp_const_none)
112
+ anchor = Point (-1 , -1 ); // Default value
113
+ else
114
+ anchor = mp_obj_to_point (args[ARG_anchor].u_obj );
115
+ int iterations = args[ARG_iterations].u_int ;
116
+ int borderType = args[ARG_borderType].u_int ;
117
+ Scalar borderValue;
118
+ if (args[ARG_borderValue].u_obj == mp_const_none)
119
+ borderValue = morphologyDefaultBorderValue (); // Default value
120
+ else
121
+ borderValue = mp_obj_to_scalar (args[ARG_borderValue].u_obj );
90
122
91
123
// Call the corresponding OpenCV function
92
124
try {
93
- erode (src, dst, kernel);
125
+ erode (src, dst, kernel, anchor, iterations, borderType, borderValue );
94
126
} catch (Exception& e) {
95
127
mp_raise_msg (&mp_type_Exception, MP_ERROR_TEXT (e.what ()));
96
128
}
@@ -101,10 +133,11 @@ mp_obj_t cv2_imgproc_erode(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw
101
133
102
134
mp_obj_t cv2_imgproc_getStructuringElement (size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
103
135
// Define the arguments
104
- enum { ARG_shape, ARG_ksize };
136
+ enum { ARG_shape, ARG_ksize, ARG_anchor };
105
137
static const mp_arg_t allowed_args[] = {
106
138
{ MP_QSTR_shape, MP_ARG_REQUIRED | MP_ARG_INT, { .u_int = 0 } },
107
139
{ MP_QSTR_ksize, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
140
+ { MP_QSTR_anchor, MP_ARG_OBJ, { .u_obj = mp_const_none } },
108
141
};
109
142
110
143
// Parse the arguments
@@ -114,13 +147,18 @@ mp_obj_t cv2_imgproc_getStructuringElement(size_t n_args, const mp_obj_t *pos_ar
114
147
// Convert arguments to required types
115
148
int shape = args[ARG_shape].u_int ;
116
149
Size ksize = mp_obj_to_size (args[ARG_ksize].u_obj );
150
+ Point anchor;
151
+ if (args[ARG_anchor].u_obj == mp_const_none)
152
+ anchor = Point (-1 , -1 ); // Default value
153
+ else
154
+ anchor = mp_obj_to_point (args[ARG_anchor].u_obj );
117
155
118
156
// Instantiate result
119
157
Mat kernel;
120
158
121
159
// Call the corresponding OpenCV function
122
160
try {
123
- kernel = getStructuringElement (shape, ksize);
161
+ kernel = getStructuringElement (shape, ksize, anchor );
124
162
} catch (Exception& e) {
125
163
mp_raise_msg (&mp_type_Exception, MP_ERROR_TEXT (e.what ()));
126
164
}
@@ -131,12 +169,16 @@ mp_obj_t cv2_imgproc_getStructuringElement(size_t n_args, const mp_obj_t *pos_ar
131
169
132
170
mp_obj_t cv2_imgproc_morphologyEx (size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
133
171
// Define the arguments
134
- enum { ARG_src, ARG_op, ARG_kernel, ARG_dst };
172
+ enum { ARG_src, ARG_op, ARG_kernel, ARG_dst, ARG_anchor, ARG_iterations, ARG_borderType, ARG_borderValue };
135
173
static const mp_arg_t allowed_args[] = {
136
174
{ MP_QSTR_src, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
137
175
{ MP_QSTR_op, MP_ARG_REQUIRED | MP_ARG_INT, { .u_int = 0 } },
138
176
{ MP_QSTR_kernel, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
139
177
{ MP_QSTR_dst, MP_ARG_OBJ, { .u_obj = mp_const_none } },
178
+ { MP_QSTR_anchor, MP_ARG_OBJ, { .u_obj = mp_const_none } },
179
+ { MP_QSTR_iterations, MP_ARG_INT, { .u_int = 1 } },
180
+ { MP_QSTR_borderType, MP_ARG_INT, { .u_int = BORDER_CONSTANT } },
181
+ { MP_QSTR_borderValue, MP_ARG_OBJ, { .u_obj = mp_const_none } },
140
182
};
141
183
142
184
// Parse the arguments
@@ -148,10 +190,22 @@ mp_obj_t cv2_imgproc_morphologyEx(size_t n_args, const mp_obj_t *pos_args, mp_ma
148
190
int op = args[ARG_op].u_int ;
149
191
Mat kernel = mp_obj_to_mat (args[ARG_kernel].u_obj );
150
192
Mat dst = mp_obj_to_mat (args[ARG_dst].u_obj );
193
+ Point anchor;
194
+ if (args[ARG_anchor].u_obj == mp_const_none)
195
+ anchor = Point (-1 , -1 ); // Default value
196
+ else
197
+ anchor = mp_obj_to_point (args[ARG_anchor].u_obj );
198
+ int iterations = args[ARG_iterations].u_int ;
199
+ int borderType = args[ARG_borderType].u_int ;
200
+ Scalar borderValue;
201
+ if (args[ARG_borderValue].u_obj == mp_const_none)
202
+ borderValue = morphologyDefaultBorderValue (); // Default value
203
+ else
204
+ borderValue = mp_obj_to_scalar (args[ARG_borderValue].u_obj );
151
205
152
206
// Call the corresponding OpenCV function
153
207
try {
154
- morphologyEx (src, dst, op, kernel);
208
+ morphologyEx (src, dst, op, kernel, anchor, iterations, borderType, borderValue );
155
209
} catch (Exception& e) {
156
210
mp_raise_msg (&mp_type_Exception, MP_ERROR_TEXT (e.what ()));
157
211
}
0 commit comments