@@ -914,6 +914,43 @@ mp_obj_t cv2_imgproc_HoughLinesWithAccumulator(size_t n_args, const mp_obj_t *po
914
914
return mat_to_mp_obj (lines);
915
915
}
916
916
917
+ mp_obj_t cv2_imgproc_Laplacian (size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
918
+ // Define the arguments
919
+ enum { ARG_src, ARG_ddepth, ARG_dst, ARG_ksize, ARG_scale, ARG_delta, ARG_borderType };
920
+ static const mp_arg_t allowed_args[] = {
921
+ { MP_QSTR_src, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
922
+ { MP_QSTR_ddepth, MP_ARG_REQUIRED | MP_ARG_INT, { .u_int = -1 } },
923
+ { MP_QSTR_dst, MP_ARG_OBJ, { .u_obj = mp_const_none } },
924
+ { MP_QSTR_ksize, MP_ARG_INT, { .u_int = 1 } },
925
+ { MP_QSTR_scale, MP_ARG_OBJ, { .u_obj = mp_const_none } },
926
+ { MP_QSTR_delta, MP_ARG_OBJ, { .u_obj = mp_const_none } },
927
+ { MP_QSTR_borderType, MP_ARG_INT, { .u_int = BORDER_DEFAULT } },
928
+ };
929
+
930
+ // Parse the arguments
931
+ mp_arg_val_t args[MP_ARRAY_SIZE (allowed_args)];
932
+ mp_arg_parse_all (n_args, pos_args, kw_args, MP_ARRAY_SIZE (allowed_args), allowed_args, args);
933
+
934
+ // Convert arguments to required types
935
+ Mat src = mp_obj_to_mat (args[ARG_src].u_obj );
936
+ int ddepth = args[ARG_ddepth].u_int ;
937
+ int ksize = args[ARG_ksize].u_int ;
938
+ Mat dst = mp_obj_to_mat (args[ARG_dst].u_obj );
939
+ mp_float_t scale = args[ARG_scale].u_obj == mp_const_none ? 1.0 : mp_obj_get_float (args[ARG_scale].u_obj );
940
+ mp_float_t delta = args[ARG_delta].u_obj == mp_const_none ? 0.0 : mp_obj_get_float (args[ARG_delta].u_obj );
941
+ int borderType = args[ARG_borderType].u_int ;
942
+
943
+ // Call the corresponding OpenCV function
944
+ try {
945
+ Laplacian (src, dst, ddepth, ksize, scale, delta, borderType);
946
+ } catch (Exception& e) {
947
+ mp_raise_msg (&mp_type_Exception, MP_ERROR_TEXT (e.what ()));
948
+ }
949
+
950
+ // Return the result
951
+ return mat_to_mp_obj (dst);
952
+ }
953
+
917
954
mp_obj_t cv2_imgproc_line (size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
918
955
// Define the arguments
919
956
enum { ARG_img, ARG_pt1, ARG_pt2, ARG_color, ARG_thickness, ARG_lineType, ARG_shift };
@@ -1106,3 +1143,119 @@ mp_obj_t cv2_imgproc_rectangle(size_t n_args, const mp_obj_t *pos_args, mp_map_t
1106
1143
// Return the result
1107
1144
return mat_to_mp_obj (img);
1108
1145
}
1146
+
1147
+ mp_obj_t cv2_imgproc_Scharr (size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
1148
+ // Define the arguments
1149
+ enum { ARG_src, ARG_ddepth, ARG_dx, ARG_dy, ARG_dst, ARG_scale, ARG_delta, ARG_borderType };
1150
+ static const mp_arg_t allowed_args[] = {
1151
+ { MP_QSTR_src, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
1152
+ { MP_QSTR_ddepth, MP_ARG_REQUIRED | MP_ARG_INT, { .u_int = 0 } },
1153
+ { MP_QSTR_dx, MP_ARG_REQUIRED | MP_ARG_INT, { .u_int = 0 } },
1154
+ { MP_QSTR_dy, MP_ARG_REQUIRED | MP_ARG_INT, { .u_int = 0 } },
1155
+ { MP_QSTR_dst, MP_ARG_OBJ, { .u_obj = mp_const_none } },
1156
+ { MP_QSTR_scale, MP_ARG_OBJ, { .u_obj = mp_const_none } },
1157
+ { MP_QSTR_delta, MP_ARG_OBJ, { .u_obj = mp_const_none } },
1158
+ { MP_QSTR_borderType, MP_ARG_INT, { .u_int = BORDER_DEFAULT } },
1159
+ };
1160
+
1161
+ // Parse the arguments
1162
+ mp_arg_val_t args[MP_ARRAY_SIZE (allowed_args)];
1163
+ mp_arg_parse_all (n_args, pos_args, kw_args, MP_ARRAY_SIZE (allowed_args), allowed_args, args);
1164
+
1165
+ // Convert arguments to required types
1166
+ Mat src = mp_obj_to_mat (args[ARG_src].u_obj );
1167
+ int ddepth = args[ARG_ddepth].u_int ;
1168
+ int dx = args[ARG_dx].u_int ;
1169
+ int dy = args[ARG_dy].u_int ;
1170
+ Mat dst = mp_obj_to_mat (args[ARG_dst].u_obj );
1171
+ mp_float_t scale = args[ARG_scale].u_obj == mp_const_none ? 1.0 : mp_obj_get_float (args[ARG_scale].u_obj );
1172
+ mp_float_t delta = args[ARG_delta].u_obj == mp_const_none ? 0.0 : mp_obj_get_float (args[ARG_delta].u_obj );
1173
+ int borderType = args[ARG_borderType].u_int ;
1174
+
1175
+ // Call the corresponding OpenCV function
1176
+ try {
1177
+ Scharr (src, dst, ddepth, dx, dy, scale, delta, borderType);
1178
+ } catch (Exception& e) {
1179
+ mp_raise_msg (&mp_type_Exception, MP_ERROR_TEXT (e.what ()));
1180
+ }
1181
+
1182
+ // Return the result
1183
+ return mat_to_mp_obj (dst);
1184
+ }
1185
+
1186
+ mp_obj_t cv2_imgproc_Sobel (size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
1187
+ // Define the arguments
1188
+ enum { ARG_src, ARG_ddepth, ARG_dx, ARG_dy, ARG_dst, ARG_ksize, ARG_scale, ARG_delta, ARG_borderType };
1189
+ static const mp_arg_t allowed_args[] = {
1190
+ { MP_QSTR_src, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
1191
+ { MP_QSTR_ddepth, MP_ARG_REQUIRED | MP_ARG_INT, { .u_int = 0 } },
1192
+ { MP_QSTR_dx, MP_ARG_REQUIRED | MP_ARG_INT, { .u_int = 0 } },
1193
+ { MP_QSTR_dy, MP_ARG_REQUIRED | MP_ARG_INT, { .u_int = 0 } },
1194
+ { MP_QSTR_dst, MP_ARG_OBJ, { .u_obj = mp_const_none } },
1195
+ { MP_QSTR_ksize, MP_ARG_INT, { .u_int = 3 } },
1196
+ { MP_QSTR_scale, MP_ARG_OBJ, { .u_obj = mp_const_none } },
1197
+ { MP_QSTR_delta, MP_ARG_OBJ, { .u_obj = mp_const_none } },
1198
+ { MP_QSTR_borderType, MP_ARG_INT, { .u_int = BORDER_DEFAULT } },
1199
+ };
1200
+
1201
+ // Parse the arguments
1202
+ mp_arg_val_t args[MP_ARRAY_SIZE (allowed_args)];
1203
+ mp_arg_parse_all (n_args, pos_args, kw_args, MP_ARRAY_SIZE (allowed_args), allowed_args, args);
1204
+
1205
+ // Convert arguments to required types
1206
+ Mat src = mp_obj_to_mat (args[ARG_src].u_obj );
1207
+ int ddepth = args[ARG_ddepth].u_int ;
1208
+ int dx = args[ARG_dx].u_int ;
1209
+ int dy = args[ARG_dy].u_int ;
1210
+ Mat dst = mp_obj_to_mat (args[ARG_dst].u_obj );
1211
+ int ksize = args[ARG_ksize].u_int ;
1212
+ mp_float_t scale = args[ARG_scale].u_obj == mp_const_none ? 1.0 : mp_obj_get_float (args[ARG_scale].u_obj );
1213
+ mp_float_t delta = args[ARG_delta].u_obj == mp_const_none ? 0.0 : mp_obj_get_float (args[ARG_delta].u_obj );
1214
+ int borderType = args[ARG_borderType].u_int ;
1215
+
1216
+ // Call the corresponding OpenCV function
1217
+ try {
1218
+ Sobel (src, dst, ddepth, dx, dy, ksize, scale, delta, borderType);
1219
+ } catch (Exception& e) {
1220
+ mp_raise_msg (&mp_type_Exception, MP_ERROR_TEXT (e.what ()));
1221
+ }
1222
+
1223
+ // Return the result
1224
+ return mat_to_mp_obj (dst);
1225
+ }
1226
+
1227
+ mp_obj_t cv2_imgproc_spatialGradient (size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
1228
+ // Define the arguments
1229
+ enum { ARG_src, ARG_dx, ARG_dy, ARG_ksize, ARG_borderType };
1230
+ static const mp_arg_t allowed_args[] = {
1231
+ { MP_QSTR_src, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = MP_OBJ_NULL } },
1232
+ { MP_QSTR_dx, MP_ARG_OBJ, { .u_obj = mp_const_none } },
1233
+ { MP_QSTR_dy, MP_ARG_OBJ, { .u_obj = mp_const_none } },
1234
+ { MP_QSTR_ksize, MP_ARG_INT, { .u_int = 3 } },
1235
+ { MP_QSTR_borderType, MP_ARG_INT, { .u_int = BORDER_DEFAULT } },
1236
+ };
1237
+
1238
+ // Parse the arguments
1239
+ mp_arg_val_t args[MP_ARRAY_SIZE (allowed_args)];
1240
+ mp_arg_parse_all (n_args, pos_args, kw_args, MP_ARRAY_SIZE (allowed_args), allowed_args, args);
1241
+
1242
+ // Convert arguments to required types
1243
+ Mat src = mp_obj_to_mat (args[ARG_src].u_obj );
1244
+ Mat dx = mp_obj_to_mat (args[ARG_dx].u_obj );
1245
+ Mat dy = mp_obj_to_mat (args[ARG_dy].u_obj );
1246
+ int ksize = args[ARG_ksize].u_int ;
1247
+ int borderType = args[ARG_borderType].u_int ;
1248
+
1249
+ // Call the corresponding OpenCV function
1250
+ try {
1251
+ spatialGradient (src, dx, dy, ksize, borderType);
1252
+ } catch (Exception& e) {
1253
+ mp_raise_msg (&mp_type_Exception, MP_ERROR_TEXT (e.what ()));
1254
+ }
1255
+
1256
+ // Return the result
1257
+ mp_obj_t result[2 ];
1258
+ result[0 ] = mat_to_mp_obj (dx);
1259
+ result[1 ] = mat_to_mp_obj (dy);
1260
+ return mp_obj_new_tuple (2 , result);
1261
+ }
0 commit comments