@@ -49,12 +49,14 @@ mp_obj_t cv2_imgproc_adaptiveThreshold(size_t n_args, const mp_obj_t *pos_args,
49
49
return mat_to_mp_obj (dst);
50
50
}
51
51
52
- mp_obj_t cv2_imgproc_arcLength (size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
52
+ mp_obj_t cv2_imgproc_approxPolyDP (size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
53
53
// Define the arguments
54
- enum { ARG_curve, ARG_closed };
54
+ enum { ARG_curve, ARG_epsilon, ARG_closed, ARG_approxCurve };
55
55
static const mp_arg_t allowed_args[] = {
56
56
{ MP_QSTR_curve, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
57
- { MP_QSTR_closed, MP_ARG_REQUIRED | MP_ARG_BOOL, { .u_bool = false } },
57
+ { MP_QSTR_epsilon, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = mp_const_none } },
58
+ { MP_QSTR_closed, MP_ARG_BOOL, { .u_bool = false } },
59
+ { MP_QSTR_approxCurve, MP_ARG_OBJ, { .u_obj = mp_const_none } },
58
60
};
59
61
60
62
// Parse the arguments
@@ -63,72 +65,60 @@ mp_obj_t cv2_imgproc_arcLength(size_t n_args, const mp_obj_t *pos_args, mp_map_t
63
65
64
66
// Convert arguments to required types
65
67
Mat curve = mp_obj_to_mat (args[ARG_curve].u_obj );
68
+ double epsilon = mp_obj_get_float (args[ARG_epsilon].u_obj );
66
69
bool closed = args[ARG_closed].u_bool ;
67
-
68
- mp_float_t retval;
70
+ Mat approxCurve = mp_obj_to_mat (args[ARG_approxCurve].u_obj );
69
71
70
72
// Call the corresponding OpenCV function
71
73
try {
72
- retval = arcLength (curve, closed);
74
+ approxPolyDP (curve, approxCurve, epsilon , closed);
73
75
} catch (Exception& e) {
74
76
mp_raise_msg (&mp_type_Exception, MP_ERROR_TEXT (e.what ()));
75
77
}
76
78
77
79
// Return the result
78
- return mp_obj_new_float (retval );
80
+ return mat_to_mp_obj (approxCurve );
79
81
}
80
82
81
- mp_obj_t cv2_imgproc_arrowedLine (size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
83
+ mp_obj_t cv2_imgproc_approxPolyN (size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
82
84
// Define the arguments
83
- enum { ARG_img, ARG_pt1, ARG_pt2, ARG_color, ARG_thickness, ARG_line_type, ARG_shift, ARG_tipLength };
85
+ enum { ARG_curve, ARG_nsides, ARG_approxCurve, ARG_epsilon_percentage, ARG_ensure_convex };
84
86
static const mp_arg_t allowed_args[] = {
85
- { MP_QSTR_img, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
86
- { MP_QSTR_pt1, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
87
- { MP_QSTR_pt2, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
88
- { MP_QSTR_color, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
89
- { MP_QSTR_thickness, MP_ARG_INT, { .u_int = 1 } },
90
- { MP_QSTR_line_type, MP_ARG_INT, { .u_int = 8 } },
91
- { MP_QSTR_shift, MP_ARG_INT, { .u_int = 0 } },
92
- { MP_QSTR_tipLength, MP_ARG_OBJ, { .u_obj = mp_const_none } },
87
+ { MP_QSTR_curve, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
88
+ { MP_QSTR_nsides, MP_ARG_REQUIRED | MP_ARG_INT, { .u_int = 0 } },
89
+ { MP_QSTR_approxCurve, MP_ARG_OBJ, { .u_obj = mp_const_none } },
90
+ { MP_QSTR_epsilon_percentage, MP_ARG_OBJ, { .u_obj = mp_const_none } },
91
+ { MP_QSTR_ensure_convex, MP_ARG_BOOL, { .u_bool = true } },
93
92
};
94
93
95
94
// Parse the arguments
96
95
mp_arg_val_t args[MP_ARRAY_SIZE (allowed_args)];
97
96
mp_arg_parse_all (n_args, pos_args, kw_args, MP_ARRAY_SIZE (allowed_args), allowed_args, args);
98
97
99
98
// Convert arguments to required types
100
- Mat img = mp_obj_to_mat (args[ARG_img].u_obj );
101
- Point pt1 = mp_obj_to_point (args[ARG_pt1].u_obj );
102
- Point pt2 = mp_obj_to_point (args[ARG_pt2].u_obj );
103
- Scalar color = mp_obj_to_scalar (args[ARG_color].u_obj );
104
- int thickness = args[ARG_thickness].u_int ;
105
- int line_type = args[ARG_line_type].u_int ;
106
- int shift = args[ARG_shift].u_int ;
107
- mp_float_t tipLength;
108
- if (args[ARG_tipLength].u_obj == mp_const_none)
109
- tipLength = 0.1 ; // Default value
110
- else
111
- tipLength = mp_obj_get_float (args[ARG_tipLength].u_obj );
99
+ Mat curve = mp_obj_to_mat (args[ARG_curve].u_obj );
100
+ int nsides = args[ARG_nsides].u_int ;
101
+ Mat approxCurve = mp_obj_to_mat (args[ARG_approxCurve].u_obj );
102
+ mp_float_t epsilon_percentage = args[ARG_epsilon_percentage].u_obj == mp_const_none ? -1.0 : mp_obj_get_float (args[ARG_epsilon_percentage].u_obj );
103
+ bool ensure_convex = args[ARG_ensure_convex].u_bool ;
112
104
113
105
// Call the corresponding OpenCV function
114
106
try {
115
- arrowedLine (img, pt1, pt2, color, thickness, line_type, shift, tipLength );
107
+ approxPolyN (curve, approxCurve, nsides, epsilon_percentage, ensure_convex );
116
108
} catch (Exception& e) {
117
109
mp_raise_msg (&mp_type_Exception, MP_ERROR_TEXT (e.what ()));
118
110
}
119
111
120
112
// Return the result
121
- return mat_to_mp_obj (img );
113
+ return mat_to_mp_obj (approxCurve );
122
114
}
123
115
124
- mp_obj_t cv2_imgproc_approxPolyDP (size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
116
+ mp_obj_t cv2_imgproc_arcLength (size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
125
117
// Define the arguments
126
- enum { ARG_curve, ARG_epsilon, ARG_closed, ARG_approxCurve };
118
+ enum { ARG_curve, ARG_closed };
127
119
static const mp_arg_t allowed_args[] = {
128
120
{ MP_QSTR_curve, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
129
- { MP_QSTR_epsilon, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = mp_const_none } },
130
- { MP_QSTR_closed, MP_ARG_BOOL, { .u_bool = false } },
131
- { MP_QSTR_approxCurve, MP_ARG_OBJ, { .u_obj = mp_const_none } },
121
+ { MP_QSTR_closed, MP_ARG_REQUIRED | MP_ARG_BOOL, { .u_bool = false } },
132
122
};
133
123
134
124
// Parse the arguments
@@ -137,52 +127,62 @@ mp_obj_t cv2_imgproc_approxPolyDP(size_t n_args, const mp_obj_t *pos_args, mp_ma
137
127
138
128
// Convert arguments to required types
139
129
Mat curve = mp_obj_to_mat (args[ARG_curve].u_obj );
140
- double epsilon = mp_obj_get_float (args[ARG_epsilon].u_obj );
141
130
bool closed = args[ARG_closed].u_bool ;
142
- Mat approxCurve = mp_obj_to_mat (args[ARG_approxCurve].u_obj );
131
+
132
+ mp_float_t retval;
143
133
144
134
// Call the corresponding OpenCV function
145
135
try {
146
- approxPolyDP (curve, approxCurve, epsilon , closed);
136
+ retval = arcLength (curve , closed);
147
137
} catch (Exception& e) {
148
138
mp_raise_msg (&mp_type_Exception, MP_ERROR_TEXT (e.what ()));
149
139
}
150
140
151
141
// Return the result
152
- return mat_to_mp_obj (approxCurve );
142
+ return mp_obj_new_float (retval );
153
143
}
154
144
155
- mp_obj_t cv2_imgproc_approxPolyN (size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
145
+ mp_obj_t cv2_imgproc_arrowedLine (size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
156
146
// Define the arguments
157
- enum { ARG_curve, ARG_nsides, ARG_approxCurve, ARG_epsilon_percentage, ARG_ensure_convex };
147
+ enum { ARG_img, ARG_pt1, ARG_pt2, ARG_color, ARG_thickness, ARG_line_type, ARG_shift, ARG_tipLength };
158
148
static const mp_arg_t allowed_args[] = {
159
- { MP_QSTR_curve, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
160
- { MP_QSTR_nsides, MP_ARG_REQUIRED | MP_ARG_INT, { .u_int = 0 } },
161
- { MP_QSTR_approxCurve, MP_ARG_OBJ, { .u_obj = mp_const_none } },
162
- { MP_QSTR_epsilon_percentage, MP_ARG_OBJ, { .u_obj = mp_const_none } },
163
- { MP_QSTR_ensure_convex, MP_ARG_BOOL, { .u_bool = true } },
149
+ { MP_QSTR_img, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
150
+ { MP_QSTR_pt1, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
151
+ { MP_QSTR_pt2, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
152
+ { MP_QSTR_color, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
153
+ { MP_QSTR_thickness, MP_ARG_INT, { .u_int = 1 } },
154
+ { MP_QSTR_line_type, MP_ARG_INT, { .u_int = 8 } },
155
+ { MP_QSTR_shift, MP_ARG_INT, { .u_int = 0 } },
156
+ { MP_QSTR_tipLength, MP_ARG_OBJ, { .u_obj = mp_const_none } },
164
157
};
165
158
166
159
// Parse the arguments
167
160
mp_arg_val_t args[MP_ARRAY_SIZE (allowed_args)];
168
161
mp_arg_parse_all (n_args, pos_args, kw_args, MP_ARRAY_SIZE (allowed_args), allowed_args, args);
169
162
170
163
// Convert arguments to required types
171
- Mat curve = mp_obj_to_mat (args[ARG_curve].u_obj );
172
- int nsides = args[ARG_nsides].u_int ;
173
- Mat approxCurve = mp_obj_to_mat (args[ARG_approxCurve].u_obj );
174
- mp_float_t epsilon_percentage = args[ARG_epsilon_percentage].u_obj == mp_const_none ? -1.0 : mp_obj_get_float (args[ARG_epsilon_percentage].u_obj );
175
- bool ensure_convex = args[ARG_ensure_convex].u_bool ;
164
+ Mat img = mp_obj_to_mat (args[ARG_img].u_obj );
165
+ Point pt1 = mp_obj_to_point (args[ARG_pt1].u_obj );
166
+ Point pt2 = mp_obj_to_point (args[ARG_pt2].u_obj );
167
+ Scalar color = mp_obj_to_scalar (args[ARG_color].u_obj );
168
+ int thickness = args[ARG_thickness].u_int ;
169
+ int line_type = args[ARG_line_type].u_int ;
170
+ int shift = args[ARG_shift].u_int ;
171
+ mp_float_t tipLength;
172
+ if (args[ARG_tipLength].u_obj == mp_const_none)
173
+ tipLength = 0.1 ; // Default value
174
+ else
175
+ tipLength = mp_obj_get_float (args[ARG_tipLength].u_obj );
176
176
177
177
// Call the corresponding OpenCV function
178
178
try {
179
- approxPolyN (curve, approxCurve, nsides, epsilon_percentage, ensure_convex );
179
+ arrowedLine (img, pt1, pt2, color, thickness, line_type, shift, tipLength );
180
180
} catch (Exception& e) {
181
181
mp_raise_msg (&mp_type_Exception, MP_ERROR_TEXT (e.what ()));
182
182
}
183
183
184
184
// Return the result
185
- return mat_to_mp_obj (approxCurve );
185
+ return mat_to_mp_obj (img );
186
186
}
187
187
188
188
mp_obj_t cv2_imgproc_bilateralFilter (size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
@@ -389,6 +389,43 @@ mp_obj_t cv2_imgproc_Canny(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw
389
389
return mat_to_mp_obj (edges);
390
390
}
391
391
392
+ mp_obj_t cv2_imgproc_circle (size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
393
+ // Define the arguments
394
+ enum { ARG_img, ARG_center, ARG_radius, ARG_color, ARG_thickness, ARG_lineType, ARG_shift };
395
+ static const mp_arg_t allowed_args[] = {
396
+ { MP_QSTR_img, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
397
+ { MP_QSTR_center, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
398
+ { MP_QSTR_radius, MP_ARG_REQUIRED | MP_ARG_INT, { .u_int = 0 } },
399
+ { MP_QSTR_color, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
400
+ { MP_QSTR_thickness, MP_ARG_INT, { .u_int = 1 } },
401
+ { MP_QSTR_lineType, MP_ARG_INT, { .u_int = LINE_8 } },
402
+ { MP_QSTR_shift, MP_ARG_INT, { .u_int = 0 } },
403
+ };
404
+
405
+ // Parse the arguments
406
+ mp_arg_val_t args[MP_ARRAY_SIZE (allowed_args)];
407
+ mp_arg_parse_all (n_args, pos_args, kw_args, MP_ARRAY_SIZE (allowed_args), allowed_args, args);
408
+
409
+ // Convert arguments to required types
410
+ Mat img = mp_obj_to_mat (args[ARG_img].u_obj );
411
+ Point center = mp_obj_to_point (args[ARG_center].u_obj );
412
+ int radius = args[ARG_radius].u_int ;
413
+ Scalar color = mp_obj_to_scalar (args[ARG_color].u_obj );
414
+ int thickness = args[ARG_thickness].u_int ;
415
+ int lineType = args[ARG_lineType].u_int ;
416
+ int shift = args[ARG_shift].u_int ;
417
+
418
+ // Call the corresponding OpenCV function
419
+ try {
420
+ circle (img, center, radius, color, thickness, lineType, shift);
421
+ } catch (Exception& e) {
422
+ mp_raise_msg (&mp_type_Exception, MP_ERROR_TEXT (e.what ()));
423
+ }
424
+
425
+ // Return the result
426
+ return mat_to_mp_obj (img);
427
+ }
428
+
392
429
mp_obj_t cv2_imgproc_connectedComponents (size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
393
430
// Define the arguments
394
431
enum { ARG_image, ARG_labels, ARG_connectivity, ARG_ltype };
@@ -587,43 +624,6 @@ mp_obj_t cv2_imgproc_convexityDefects(size_t n_args, const mp_obj_t *pos_args, m
587
624
return mat_to_mp_obj (convexityDefects);
588
625
}
589
626
590
- mp_obj_t cv2_imgproc_circle (size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
591
- // Define the arguments
592
- enum { ARG_img, ARG_center, ARG_radius, ARG_color, ARG_thickness, ARG_lineType, ARG_shift };
593
- static const mp_arg_t allowed_args[] = {
594
- { MP_QSTR_img, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
595
- { MP_QSTR_center, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
596
- { MP_QSTR_radius, MP_ARG_REQUIRED | MP_ARG_INT, { .u_int = 0 } },
597
- { MP_QSTR_color, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
598
- { MP_QSTR_thickness, MP_ARG_INT, { .u_int = 1 } },
599
- { MP_QSTR_lineType, MP_ARG_INT, { .u_int = LINE_8 } },
600
- { MP_QSTR_shift, MP_ARG_INT, { .u_int = 0 } },
601
- };
602
-
603
- // Parse the arguments
604
- mp_arg_val_t args[MP_ARRAY_SIZE (allowed_args)];
605
- mp_arg_parse_all (n_args, pos_args, kw_args, MP_ARRAY_SIZE (allowed_args), allowed_args, args);
606
-
607
- // Convert arguments to required types
608
- Mat img = mp_obj_to_mat (args[ARG_img].u_obj );
609
- Point center = mp_obj_to_point (args[ARG_center].u_obj );
610
- int radius = args[ARG_radius].u_int ;
611
- Scalar color = mp_obj_to_scalar (args[ARG_color].u_obj );
612
- int thickness = args[ARG_thickness].u_int ;
613
- int lineType = args[ARG_lineType].u_int ;
614
- int shift = args[ARG_shift].u_int ;
615
-
616
- // Call the corresponding OpenCV function
617
- try {
618
- circle (img, center, radius, color, thickness, lineType, shift);
619
- } catch (Exception& e) {
620
- mp_raise_msg (&mp_type_Exception, MP_ERROR_TEXT (e.what ()));
621
- }
622
-
623
- // Return the result
624
- return mat_to_mp_obj (img);
625
- }
626
-
627
627
mp_obj_t cv2_imgproc_cvtColor (size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
628
628
// Define the arguments
629
629
enum { ARG_src, ARG_code, ARG_dst };
@@ -1776,53 +1776,6 @@ mp_obj_t cv2_imgproc_minEnclosingTriangle(size_t n_args, const mp_obj_t *pos_arg
1776
1776
return mp_obj_new_tuple (2 , result_tuple);
1777
1777
}
1778
1778
1779
- mp_obj_t cv2_imgproc_morphologyEx (size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
1780
- // Define the arguments
1781
- enum { ARG_src, ARG_op, ARG_kernel, ARG_dst, ARG_anchor, ARG_iterations, ARG_borderType, ARG_borderValue };
1782
- static const mp_arg_t allowed_args[] = {
1783
- { MP_QSTR_src, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
1784
- { MP_QSTR_op, MP_ARG_REQUIRED | MP_ARG_INT, { .u_int = 0 } },
1785
- { MP_QSTR_kernel, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
1786
- { MP_QSTR_dst, MP_ARG_OBJ, { .u_obj = mp_const_none } },
1787
- { MP_QSTR_anchor, MP_ARG_OBJ, { .u_obj = mp_const_none } },
1788
- { MP_QSTR_iterations, MP_ARG_INT, { .u_int = 1 } },
1789
- { MP_QSTR_borderType, MP_ARG_INT, { .u_int = BORDER_CONSTANT } },
1790
- { MP_QSTR_borderValue, MP_ARG_OBJ, { .u_obj = mp_const_none } },
1791
- };
1792
-
1793
- // Parse the arguments
1794
- mp_arg_val_t args[MP_ARRAY_SIZE (allowed_args)];
1795
- mp_arg_parse_all (n_args, pos_args, kw_args, MP_ARRAY_SIZE (allowed_args), allowed_args, args);
1796
-
1797
- // Convert arguments to required types
1798
- Mat src = mp_obj_to_mat (args[ARG_src].u_obj );
1799
- int op = args[ARG_op].u_int ;
1800
- Mat kernel = mp_obj_to_mat (args[ARG_kernel].u_obj );
1801
- Mat dst = mp_obj_to_mat (args[ARG_dst].u_obj );
1802
- Point anchor;
1803
- if (args[ARG_anchor].u_obj == mp_const_none)
1804
- anchor = Point (-1 , -1 ); // Default value
1805
- else
1806
- anchor = mp_obj_to_point (args[ARG_anchor].u_obj );
1807
- int iterations = args[ARG_iterations].u_int ;
1808
- int borderType = args[ARG_borderType].u_int ;
1809
- Scalar borderValue;
1810
- if (args[ARG_borderValue].u_obj == mp_const_none)
1811
- borderValue = morphologyDefaultBorderValue (); // Default value
1812
- else
1813
- borderValue = mp_obj_to_scalar (args[ARG_borderValue].u_obj );
1814
-
1815
- // Call the corresponding OpenCV function
1816
- try {
1817
- morphologyEx (src, dst, op, kernel, anchor, iterations, borderType, borderValue);
1818
- } catch (Exception& e) {
1819
- mp_raise_msg (&mp_type_Exception, MP_ERROR_TEXT (e.what ()));
1820
- }
1821
-
1822
- // Return the result
1823
- return mat_to_mp_obj (dst);
1824
- }
1825
-
1826
1779
mp_obj_t cv2_imgproc_moments (size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
1827
1780
// Define the arguments
1828
1781
enum { ARG_src, ARG_binary };
@@ -1878,6 +1831,53 @@ mp_obj_t cv2_imgproc_moments(size_t n_args, const mp_obj_t *pos_args, mp_map_t *
1878
1831
return moments_dict;
1879
1832
}
1880
1833
1834
+ mp_obj_t cv2_imgproc_morphologyEx (size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
1835
+ // Define the arguments
1836
+ enum { ARG_src, ARG_op, ARG_kernel, ARG_dst, ARG_anchor, ARG_iterations, ARG_borderType, ARG_borderValue };
1837
+ static const mp_arg_t allowed_args[] = {
1838
+ { MP_QSTR_src, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
1839
+ { MP_QSTR_op, MP_ARG_REQUIRED | MP_ARG_INT, { .u_int = 0 } },
1840
+ { MP_QSTR_kernel, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
1841
+ { MP_QSTR_dst, MP_ARG_OBJ, { .u_obj = mp_const_none } },
1842
+ { MP_QSTR_anchor, MP_ARG_OBJ, { .u_obj = mp_const_none } },
1843
+ { MP_QSTR_iterations, MP_ARG_INT, { .u_int = 1 } },
1844
+ { MP_QSTR_borderType, MP_ARG_INT, { .u_int = BORDER_CONSTANT } },
1845
+ { MP_QSTR_borderValue, MP_ARG_OBJ, { .u_obj = mp_const_none } },
1846
+ };
1847
+
1848
+ // Parse the arguments
1849
+ mp_arg_val_t args[MP_ARRAY_SIZE (allowed_args)];
1850
+ mp_arg_parse_all (n_args, pos_args, kw_args, MP_ARRAY_SIZE (allowed_args), allowed_args, args);
1851
+
1852
+ // Convert arguments to required types
1853
+ Mat src = mp_obj_to_mat (args[ARG_src].u_obj );
1854
+ int op = args[ARG_op].u_int ;
1855
+ Mat kernel = mp_obj_to_mat (args[ARG_kernel].u_obj );
1856
+ Mat dst = mp_obj_to_mat (args[ARG_dst].u_obj );
1857
+ Point anchor;
1858
+ if (args[ARG_anchor].u_obj == mp_const_none)
1859
+ anchor = Point (-1 , -1 ); // Default value
1860
+ else
1861
+ anchor = mp_obj_to_point (args[ARG_anchor].u_obj );
1862
+ int iterations = args[ARG_iterations].u_int ;
1863
+ int borderType = args[ARG_borderType].u_int ;
1864
+ Scalar borderValue;
1865
+ if (args[ARG_borderValue].u_obj == mp_const_none)
1866
+ borderValue = morphologyDefaultBorderValue (); // Default value
1867
+ else
1868
+ borderValue = mp_obj_to_scalar (args[ARG_borderValue].u_obj );
1869
+
1870
+ // Call the corresponding OpenCV function
1871
+ try {
1872
+ morphologyEx (src, dst, op, kernel, anchor, iterations, borderType, borderValue);
1873
+ } catch (Exception& e) {
1874
+ mp_raise_msg (&mp_type_Exception, MP_ERROR_TEXT (e.what ()));
1875
+ }
1876
+
1877
+ // Return the result
1878
+ return mat_to_mp_obj (dst);
1879
+ }
1880
+
1881
1881
mp_obj_t cv2_imgproc_pointPolygonTest (size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
1882
1882
// Define the arguments
1883
1883
enum { ARG_contour, ARG_pt, ARG_measureDist };
0 commit comments