Skip to content

Commit 8502bf8

Browse files
committed
Fix alphabetical order of imgproc module
Spelling is hard...
1 parent 908ad71 commit 8502bf8

File tree

2 files changed

+150
-150
lines changed

2 files changed

+150
-150
lines changed

src/imgproc.cpp

Lines changed: 138 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,14 @@ mp_obj_t cv2_imgproc_adaptiveThreshold(size_t n_args, const mp_obj_t *pos_args,
4949
return mat_to_mp_obj(dst);
5050
}
5151

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) {
5353
// Define the arguments
54-
enum { ARG_curve, ARG_closed };
54+
enum { ARG_curve, ARG_epsilon, ARG_closed, ARG_approxCurve };
5555
static const mp_arg_t allowed_args[] = {
5656
{ 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 } },
5860
};
5961

6062
// 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
6365

6466
// Convert arguments to required types
6567
Mat curve = mp_obj_to_mat(args[ARG_curve].u_obj);
68+
double epsilon = mp_obj_get_float(args[ARG_epsilon].u_obj);
6669
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);
6971

7072
// Call the corresponding OpenCV function
7173
try {
72-
retval = arcLength(curve, closed);
74+
approxPolyDP(curve, approxCurve, epsilon, closed);
7375
} catch(Exception& e) {
7476
mp_raise_msg(&mp_type_Exception, MP_ERROR_TEXT(e.what()));
7577
}
7678

7779
// Return the result
78-
return mp_obj_new_float(retval);
80+
return mat_to_mp_obj(approxCurve);
7981
}
8082

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) {
8284
// 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 };
8486
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 } },
9392
};
9493

9594
// Parse the arguments
9695
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
9796
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
9897

9998
// 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;
112104

113105
// Call the corresponding OpenCV function
114106
try {
115-
arrowedLine(img, pt1, pt2, color, thickness, line_type, shift, tipLength);
107+
approxPolyN(curve, approxCurve, nsides, epsilon_percentage, ensure_convex);
116108
} catch(Exception& e) {
117109
mp_raise_msg(&mp_type_Exception, MP_ERROR_TEXT(e.what()));
118110
}
119111

120112
// Return the result
121-
return mat_to_mp_obj(img);
113+
return mat_to_mp_obj(approxCurve);
122114
}
123115

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) {
125117
// Define the arguments
126-
enum { ARG_curve, ARG_epsilon, ARG_closed, ARG_approxCurve };
118+
enum { ARG_curve, ARG_closed };
127119
static const mp_arg_t allowed_args[] = {
128120
{ 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 } },
132122
};
133123

134124
// 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
137127

138128
// Convert arguments to required types
139129
Mat curve = mp_obj_to_mat(args[ARG_curve].u_obj);
140-
double epsilon = mp_obj_get_float(args[ARG_epsilon].u_obj);
141130
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;
143133

144134
// Call the corresponding OpenCV function
145135
try {
146-
approxPolyDP(curve, approxCurve, epsilon, closed);
136+
retval = arcLength(curve, closed);
147137
} catch(Exception& e) {
148138
mp_raise_msg(&mp_type_Exception, MP_ERROR_TEXT(e.what()));
149139
}
150140

151141
// Return the result
152-
return mat_to_mp_obj(approxCurve);
142+
return mp_obj_new_float(retval);
153143
}
154144

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) {
156146
// 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 };
158148
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 } },
164157
};
165158

166159
// Parse the arguments
167160
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
168161
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
169162

170163
// 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);
176176

177177
// Call the corresponding OpenCV function
178178
try {
179-
approxPolyN(curve, approxCurve, nsides, epsilon_percentage, ensure_convex);
179+
arrowedLine(img, pt1, pt2, color, thickness, line_type, shift, tipLength);
180180
} catch(Exception& e) {
181181
mp_raise_msg(&mp_type_Exception, MP_ERROR_TEXT(e.what()));
182182
}
183183

184184
// Return the result
185-
return mat_to_mp_obj(approxCurve);
185+
return mat_to_mp_obj(img);
186186
}
187187

188188
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
389389
return mat_to_mp_obj(edges);
390390
}
391391

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+
392429
mp_obj_t cv2_imgproc_connectedComponents(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
393430
// Define the arguments
394431
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
587624
return mat_to_mp_obj(convexityDefects);
588625
}
589626

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-
627627
mp_obj_t cv2_imgproc_cvtColor(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
628628
// Define the arguments
629629
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
17761776
return mp_obj_new_tuple(2, result_tuple);
17771777
}
17781778

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-
18261779
mp_obj_t cv2_imgproc_moments(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
18271780
// Define the arguments
18281781
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 *
18781831
return moments_dict;
18791832
}
18801833

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+
18811881
mp_obj_t cv2_imgproc_pointPolygonTest(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
18821882
// Define the arguments
18831883
enum { ARG_contour, ARG_pt, ARG_measureDist };

0 commit comments

Comments
 (0)