@@ -12,6 +12,86 @@ extern "C" {
12
12
13
13
using namespace cv ;
14
14
15
+ mp_obj_t cv2_imgproc_arrowedLine (size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
16
+ // Define the arguments
17
+ enum { ARG_img, ARG_pt1, ARG_pt2, ARG_color, ARG_thickness, ARG_line_type, ARG_shift, ARG_tipLength };
18
+ static const mp_arg_t allowed_args[] = {
19
+ { MP_QSTR_img, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
20
+ { MP_QSTR_pt1, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
21
+ { MP_QSTR_pt2, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
22
+ { MP_QSTR_color, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
23
+ { MP_QSTR_thickness, MP_ARG_INT, { .u_int = 1 } },
24
+ { MP_QSTR_line_type, MP_ARG_INT, { .u_int = 8 } },
25
+ { MP_QSTR_shift, MP_ARG_INT, { .u_int = 0 } },
26
+ { MP_QSTR_tipLength, MP_ARG_OBJ, { .u_obj = mp_const_none } },
27
+ };
28
+
29
+ // Parse the arguments
30
+ mp_arg_val_t args[MP_ARRAY_SIZE (allowed_args)];
31
+ mp_arg_parse_all (n_args, pos_args, kw_args, MP_ARRAY_SIZE (allowed_args), allowed_args, args);
32
+
33
+ // Convert arguments to required types
34
+ Mat img = mp_obj_to_mat (args[ARG_img].u_obj );
35
+ Point pt1 = mp_obj_to_point (args[ARG_pt1].u_obj );
36
+ Point pt2 = mp_obj_to_point (args[ARG_pt2].u_obj );
37
+ Scalar color = mp_obj_to_scalar (args[ARG_color].u_obj );
38
+ int thickness = args[ARG_thickness].u_int ;
39
+ int line_type = args[ARG_line_type].u_int ;
40
+ int shift = args[ARG_shift].u_int ;
41
+ mp_float_t tipLength;
42
+ if (args[ARG_tipLength].u_obj == mp_const_none)
43
+ tipLength = 0.1 ; // Default value
44
+ else
45
+ tipLength = mp_obj_get_float (args[ARG_tipLength].u_obj );
46
+
47
+ // Call the corresponding OpenCV function
48
+ try {
49
+ arrowedLine (img, pt1, pt2, color, thickness, line_type, shift, tipLength);
50
+ } catch (Exception& e) {
51
+ mp_raise_msg (&mp_type_Exception, MP_ERROR_TEXT (e.what ()));
52
+ }
53
+
54
+ // Return the result
55
+ return mat_to_mp_obj (img);
56
+ }
57
+
58
+ mp_obj_t cv2_imgproc_circle (size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
59
+ // Define the arguments
60
+ enum { ARG_img, ARG_center, ARG_radius, ARG_color, ARG_thickness, ARG_lineType, ARG_shift };
61
+ static const mp_arg_t allowed_args[] = {
62
+ { MP_QSTR_img, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
63
+ { MP_QSTR_center, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
64
+ { MP_QSTR_radius, MP_ARG_REQUIRED | MP_ARG_INT, { .u_int = 0 } },
65
+ { MP_QSTR_color, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
66
+ { MP_QSTR_thickness, MP_ARG_INT, { .u_int = 1 } },
67
+ { MP_QSTR_lineType, MP_ARG_INT, { .u_int = LINE_8 } },
68
+ { MP_QSTR_shift, MP_ARG_INT, { .u_int = 0 } },
69
+ };
70
+
71
+ // Parse the arguments
72
+ mp_arg_val_t args[MP_ARRAY_SIZE (allowed_args)];
73
+ mp_arg_parse_all (n_args, pos_args, kw_args, MP_ARRAY_SIZE (allowed_args), allowed_args, args);
74
+
75
+ // Convert arguments to required types
76
+ Mat img = mp_obj_to_mat (args[ARG_img].u_obj );
77
+ Point center = mp_obj_to_point (args[ARG_center].u_obj );
78
+ int radius = args[ARG_radius].u_int ;
79
+ Scalar color = mp_obj_to_scalar (args[ARG_color].u_obj );
80
+ int thickness = args[ARG_thickness].u_int ;
81
+ int lineType = args[ARG_lineType].u_int ;
82
+ int shift = args[ARG_shift].u_int ;
83
+
84
+ // Call the corresponding OpenCV function
85
+ try {
86
+ circle (img, center, radius, color, thickness, lineType, shift);
87
+ } catch (Exception& e) {
88
+ mp_raise_msg (&mp_type_Exception, MP_ERROR_TEXT (e.what ()));
89
+ }
90
+
91
+ // Return the result
92
+ return mat_to_mp_obj (img);
93
+ }
94
+
15
95
mp_obj_t cv2_imgproc_cvtColor (size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
16
96
// Define the arguments
17
97
enum { ARG_src, ARG_code, ARG_dst };
@@ -86,6 +166,86 @@ mp_obj_t cv2_imgproc_dilate(size_t n_args, const mp_obj_t *pos_args, mp_map_t *k
86
166
return mat_to_mp_obj (dst);
87
167
}
88
168
169
+ mp_obj_t cv2_imgproc_drawMarker (size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
170
+ // Define the arguments
171
+ enum { ARG_img, ARG_position, ARG_color, ARG_markerType, ARG_markerSize, ARG_thickness, ARG_line_type };
172
+ static const mp_arg_t allowed_args[] = {
173
+ { MP_QSTR_img, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
174
+ { MP_QSTR_position, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
175
+ { MP_QSTR_color, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
176
+ { MP_QSTR_markerType, MP_ARG_INT, { .u_int = MARKER_CROSS } },
177
+ { MP_QSTR_markerSize, MP_ARG_INT, { .u_int = 20 } },
178
+ { MP_QSTR_thickness, MP_ARG_INT, { .u_int = 1 } },
179
+ { MP_QSTR_line_type, MP_ARG_INT, { .u_int = 8 } },
180
+ };
181
+
182
+ // Parse the arguments
183
+ mp_arg_val_t args[MP_ARRAY_SIZE (allowed_args)];
184
+ mp_arg_parse_all (n_args, pos_args, kw_args, MP_ARRAY_SIZE (allowed_args), allowed_args, args);
185
+
186
+ // Convert arguments to required types
187
+ Mat img = mp_obj_to_mat (args[ARG_img].u_obj );
188
+ Point position = mp_obj_to_point (args[ARG_position].u_obj );
189
+ int markerType = args[ARG_markerType].u_int ;
190
+ Scalar color = mp_obj_to_scalar (args[ARG_color].u_obj );
191
+ int markerSize = args[ARG_markerSize].u_int ;
192
+ int thickness = args[ARG_thickness].u_int ;
193
+ int line_type = args[ARG_line_type].u_int ;
194
+
195
+ // Call the corresponding OpenCV function
196
+ try {
197
+ drawMarker (img, position, color, markerType, markerSize, thickness, line_type);
198
+ } catch (Exception& e) {
199
+ mp_raise_msg (&mp_type_Exception, MP_ERROR_TEXT (e.what ()));
200
+ }
201
+
202
+ // Return the result
203
+ return mat_to_mp_obj (img);
204
+ }
205
+
206
+ mp_obj_t cv2_imgproc_ellipse (size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
207
+ // Define the arguments
208
+ enum { ARG_img, ARG_center, ARG_axes, ARG_angle, ARG_startAngle, ARG_endAngle, ARG_color, ARG_thickness, ARG_lineType, ARG_shift };
209
+ static const mp_arg_t allowed_args[] = {
210
+ { MP_QSTR_img, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
211
+ { MP_QSTR_center, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
212
+ { MP_QSTR_axes, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
213
+ { MP_QSTR_angle, MP_ARG_REQUIRED | MP_ARG_INT, { .u_int = 0 } },
214
+ { MP_QSTR_startAngle, MP_ARG_REQUIRED | MP_ARG_INT, { .u_int = 0 } },
215
+ { MP_QSTR_endAngle, MP_ARG_REQUIRED | MP_ARG_INT, { .u_int = 0 } },
216
+ { MP_QSTR_color, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
217
+ { MP_QSTR_thickness, MP_ARG_INT, { .u_int = 1 } },
218
+ { MP_QSTR_lineType, MP_ARG_INT, { .u_int = LINE_8 } },
219
+ { MP_QSTR_shift, MP_ARG_INT, { .u_int = 0 } },
220
+ };
221
+
222
+ // Parse the arguments
223
+ mp_arg_val_t args[MP_ARRAY_SIZE (allowed_args)];
224
+ mp_arg_parse_all (n_args, pos_args, kw_args, MP_ARRAY_SIZE (allowed_args), allowed_args, args);
225
+
226
+ // Convert arguments to required types
227
+ Mat img = mp_obj_to_mat (args[ARG_img].u_obj );
228
+ Point center = mp_obj_to_point (args[ARG_center].u_obj );
229
+ Size axes = mp_obj_to_size (args[ARG_axes].u_obj );
230
+ int angle = args[ARG_angle].u_int ;
231
+ int startAngle = args[ARG_startAngle].u_int ;
232
+ int endAngle = args[ARG_endAngle].u_int ;
233
+ Scalar color = mp_obj_to_scalar (args[ARG_color].u_obj );
234
+ int thickness = args[ARG_thickness].u_int ;
235
+ int lineType = args[ARG_lineType].u_int ;
236
+ int shift = args[ARG_shift].u_int ;
237
+
238
+ // Call the corresponding OpenCV function
239
+ try {
240
+ ellipse (img, center, axes, angle, startAngle, endAngle, color, thickness, lineType, shift);
241
+ } catch (Exception& e) {
242
+ mp_raise_msg (&mp_type_Exception, MP_ERROR_TEXT (e.what ()));
243
+ }
244
+
245
+ // Return the result
246
+ return mat_to_mp_obj (img);
247
+ }
248
+
89
249
mp_obj_t cv2_imgproc_erode (size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
90
250
// Define the arguments
91
251
enum { ARG_src, ARG_kernel, ARG_dst, ARG_anchor, ARG_iterations, ARG_borderType, ARG_borderValue };
@@ -131,6 +291,88 @@ mp_obj_t cv2_imgproc_erode(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw
131
291
return mat_to_mp_obj (dst);
132
292
}
133
293
294
+ mp_obj_t cv2_imgproc_fillConvexPoly (size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
295
+ // Define the arguments
296
+ enum { ARG_img, ARG_points, ARG_color, ARG_lineType, ARG_shift };
297
+ static const mp_arg_t allowed_args[] = {
298
+ { MP_QSTR_img, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
299
+ { MP_QSTR_points, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
300
+ { MP_QSTR_color, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
301
+ { MP_QSTR_lineType, MP_ARG_INT, { .u_int = LINE_8 } },
302
+ { MP_QSTR_shift, MP_ARG_INT, { .u_int = 0 } },
303
+ };
304
+
305
+ // Parse the arguments
306
+ mp_arg_val_t args[MP_ARRAY_SIZE (allowed_args)];
307
+ mp_arg_parse_all (n_args, pos_args, kw_args, MP_ARRAY_SIZE (allowed_args), allowed_args, args);
308
+
309
+ // Convert arguments to required types
310
+ Mat img = mp_obj_to_mat (args[ARG_img].u_obj );
311
+ Mat points = mp_obj_to_mat (args[ARG_points].u_obj );
312
+ Scalar color = mp_obj_to_scalar (args[ARG_color].u_obj );
313
+ int lineType = args[ARG_lineType].u_int ;
314
+ int shift = args[ARG_shift].u_int ;
315
+
316
+ // points must be of type CV_32S
317
+ Mat points_32S;
318
+ points.allocator = &GetNumpyAllocator ();
319
+ points.convertTo (points_32S, CV_32S);
320
+
321
+ // Call the corresponding OpenCV function
322
+ try {
323
+ fillConvexPoly (img, points_32S, color, lineType, shift);
324
+ } catch (Exception& e) {
325
+ mp_raise_msg (&mp_type_Exception, MP_ERROR_TEXT (e.what ()));
326
+ }
327
+
328
+ // Return the result
329
+ return mat_to_mp_obj (img);
330
+ }
331
+
332
+ mp_obj_t cv2_imgproc_fillPoly (size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
333
+ // Define the arguments
334
+ enum { ARG_img, ARG_pts, ARG_color, ARG_lineType, ARG_shift, ARG_offset };
335
+ static const mp_arg_t allowed_args[] = {
336
+ { MP_QSTR_img, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
337
+ { MP_QSTR_pts, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
338
+ { MP_QSTR_color, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
339
+ { MP_QSTR_lineType, MP_ARG_INT, { .u_int = LINE_8 } },
340
+ { MP_QSTR_shift, MP_ARG_INT, { .u_int = 0 } },
341
+ { MP_QSTR_offset, MP_ARG_OBJ, { .u_obj = mp_const_none } },
342
+ };
343
+
344
+ // Parse the arguments
345
+ mp_arg_val_t args[MP_ARRAY_SIZE (allowed_args)];
346
+ mp_arg_parse_all (n_args, pos_args, kw_args, MP_ARRAY_SIZE (allowed_args), allowed_args, args);
347
+
348
+ // Convert arguments to required types
349
+ Mat img = mp_obj_to_mat (args[ARG_img].u_obj );
350
+ Mat pts = mp_obj_to_mat (args[ARG_pts].u_obj );
351
+ Scalar color = mp_obj_to_scalar (args[ARG_color].u_obj );
352
+ int lineType = args[ARG_lineType].u_int ;
353
+ int shift = args[ARG_shift].u_int ;
354
+ Point offset;
355
+ if (args[ARG_offset].u_obj == mp_const_none)
356
+ offset = Point (); // Default value
357
+ else
358
+ offset = mp_obj_to_point (args[ARG_offset].u_obj );
359
+
360
+ // points must be of type CV_32S
361
+ Mat pts_32S;
362
+ pts.allocator = &GetNumpyAllocator ();
363
+ pts.convertTo (pts_32S, CV_32S);
364
+
365
+ // Call the corresponding OpenCV function
366
+ try {
367
+ fillPoly (img, pts_32S, color, lineType, shift, offset);
368
+ } catch (Exception& e) {
369
+ mp_raise_msg (&mp_type_Exception, MP_ERROR_TEXT (e.what ()));
370
+ }
371
+
372
+ // Return the result
373
+ return mat_to_mp_obj (img);
374
+ }
375
+
134
376
mp_obj_t cv2_imgproc_getStructuringElement (size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
135
377
// Define the arguments
136
378
enum { ARG_shape, ARG_ksize, ARG_anchor };
@@ -167,6 +409,43 @@ mp_obj_t cv2_imgproc_getStructuringElement(size_t n_args, const mp_obj_t *pos_ar
167
409
return mat_to_mp_obj (kernel);
168
410
}
169
411
412
+ mp_obj_t cv2_imgproc_line (size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
413
+ // Define the arguments
414
+ enum { ARG_img, ARG_pt1, ARG_pt2, ARG_color, ARG_thickness, ARG_lineType, ARG_shift };
415
+ static const mp_arg_t allowed_args[] = {
416
+ { MP_QSTR_img, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
417
+ { MP_QSTR_pt1, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
418
+ { MP_QSTR_pt2, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
419
+ { MP_QSTR_color, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
420
+ { MP_QSTR_thickness, MP_ARG_INT, { .u_int = 1 } },
421
+ { MP_QSTR_lineType, MP_ARG_INT, { .u_int = LINE_8 } },
422
+ { MP_QSTR_shift, MP_ARG_INT, { .u_int = 0 } },
423
+ };
424
+
425
+ // Parse the arguments
426
+ mp_arg_val_t args[MP_ARRAY_SIZE (allowed_args)];
427
+ mp_arg_parse_all (n_args, pos_args, kw_args, MP_ARRAY_SIZE (allowed_args), allowed_args, args);
428
+
429
+ // Convert arguments to required types
430
+ Mat img = mp_obj_to_mat (args[ARG_img].u_obj );
431
+ Point pt1 = mp_obj_to_point (args[ARG_pt1].u_obj );
432
+ Point pt2 = mp_obj_to_point (args[ARG_pt2].u_obj );
433
+ Scalar color = mp_obj_to_scalar (args[ARG_color].u_obj );
434
+ int thickness = args[ARG_thickness].u_int ;
435
+ int lineType = args[ARG_lineType].u_int ;
436
+ int shift = args[ARG_shift].u_int ;
437
+
438
+ // Call the corresponding OpenCV function
439
+ try {
440
+ line (img, pt1, pt2, color, thickness, lineType, shift);
441
+ } catch (Exception& e) {
442
+ mp_raise_msg (&mp_type_Exception, MP_ERROR_TEXT (e.what ()));
443
+ }
444
+
445
+ // Return the result
446
+ return mat_to_mp_obj (img);
447
+ }
448
+
170
449
mp_obj_t cv2_imgproc_morphologyEx (size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
171
450
// Define the arguments
172
451
enum { ARG_src, ARG_op, ARG_kernel, ARG_dst, ARG_anchor, ARG_iterations, ARG_borderType, ARG_borderValue };
@@ -213,3 +492,83 @@ mp_obj_t cv2_imgproc_morphologyEx(size_t n_args, const mp_obj_t *pos_args, mp_ma
213
492
// Return the result
214
493
return mat_to_mp_obj (dst);
215
494
}
495
+
496
+ // mp_obj_t cv2_imgproc_putText(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
497
+ // // Define the arguments
498
+ // enum { ARG_img, ARG_text, ARG_org, ARG_fontFace, ARG_fontScale, ARG_color, ARG_thickness, ARG_lineType, ARG_bottomLeftOrigin };
499
+ // static const mp_arg_t allowed_args[] = {
500
+ // { MP_QSTR_img, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
501
+ // { MP_QSTR_text, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
502
+ // { MP_QSTR_org, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
503
+ // { MP_QSTR_fontFace, MP_ARG_REQUIRED | MP_ARG_INT, { .u_int = FONT_HERSHEY_SIMPLEX } },
504
+ // { MP_QSTR_fontScale, MP_ARG_REQUIRED, { .u_obj = mp_const_none } },
505
+ // { MP_QSTR_color, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
506
+ // { MP_QSTR_thickness, MP_ARG_INT, { .u_int = 1 } },
507
+ // { MP_QSTR_lineType, MP_ARG_INT, { .u_int = LINE_8 } },
508
+ // { MP_QSTR_bottomLeftOrigin, MP_ARG_BOOL, { .u_bool = 0 } },
509
+ // };
510
+
511
+ // // Parse the arguments
512
+ // mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
513
+ // mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
514
+
515
+ // // Convert arguments to required types
516
+ // Mat img = mp_obj_to_mat(args[ARG_img].u_obj);
517
+ // size_t len;
518
+ // const char *text_str = mp_obj_str_get_data(args[ARG_text].u_obj, &len);
519
+ // String text(text_str, len);
520
+ // Point org = mp_obj_to_point(args[ARG_org].u_obj);
521
+ // int fontFace = args[ARG_fontFace].u_int;
522
+ // mp_float_t fontScale = mp_obj_get_float(args[ARG_fontScale].u_obj);
523
+ // Scalar color = mp_obj_to_scalar(args[ARG_color].u_obj);
524
+ // int thickness = args[ARG_thickness].u_int;
525
+ // int lineType = args[ARG_lineType].u_int;
526
+ // bool bottomLeftOrigin = args[ARG_bottomLeftOrigin].u_bool;
527
+
528
+ // // Call the corresponding OpenCV function
529
+ // try {
530
+ // putText(img, text, org, fontFace, fontScale, color, thickness, lineType, bottomLeftOrigin);
531
+ // } catch(Exception& e) {
532
+ // mp_raise_msg(&mp_type_Exception, MP_ERROR_TEXT(e.what()));
533
+ // }
534
+
535
+ // // Return the result
536
+ // return mat_to_mp_obj(img);
537
+ // }
538
+
539
+ mp_obj_t cv2_imgproc_rectangle (size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
540
+ // Define the arguments
541
+ enum { ARG_img, ARG_pt1, ARG_pt2, ARG_color, ARG_thickness, ARG_lineType, ARG_shift };
542
+ static const mp_arg_t allowed_args[] = {
543
+ { MP_QSTR_img, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
544
+ { MP_QSTR_pt1, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
545
+ { MP_QSTR_pt2, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
546
+ { MP_QSTR_color, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
547
+ { MP_QSTR_thickness, MP_ARG_INT, { .u_int = 1 } },
548
+ { MP_QSTR_lineType, MP_ARG_INT, { .u_int = LINE_8 } },
549
+ { MP_QSTR_shift, MP_ARG_INT, { .u_int = 0 } },
550
+ };
551
+
552
+ // Parse the arguments
553
+ mp_arg_val_t args[MP_ARRAY_SIZE (allowed_args)];
554
+ mp_arg_parse_all (n_args, pos_args, kw_args, MP_ARRAY_SIZE (allowed_args), allowed_args, args);
555
+
556
+ // Convert arguments to required types
557
+ Mat img = mp_obj_to_mat (args[ARG_img].u_obj );
558
+ Point pt1 = mp_obj_to_point (args[ARG_pt1].u_obj );
559
+ Point pt2 = mp_obj_to_point (args[ARG_pt2].u_obj );
560
+ Scalar color = mp_obj_to_scalar (args[ARG_color].u_obj );
561
+ int thickness = args[ARG_thickness].u_int ;
562
+ int lineType = args[ARG_lineType].u_int ;
563
+ int shift = args[ARG_shift].u_int ;
564
+
565
+ // Call the corresponding OpenCV function
566
+ try {
567
+ rectangle (img, pt1, pt2, color, thickness, lineType, shift);
568
+ } catch (Exception& e) {
569
+ mp_raise_msg (&mp_type_Exception, MP_ERROR_TEXT (e.what ()));
570
+ }
571
+
572
+ // Return the result
573
+ return mat_to_mp_obj (img);
574
+ }
0 commit comments