1 #include <stdio.h>
2 #include <string.h>
3 #include <stdlib.h>
4
5 #include "py/mperrno.h"
6 #include "py/obj.h"
7 #include "py/runtime.h"
8 #include "py/builtin.h"
9
10 #include "ulog/ulog.h"
11 #include "base/modules/c/include/WrapperIHaasImageProc.h"
12
13 #define LOG_TAG "IMAGE_PROC"
14
15 extern const mp_obj_type_t minicv_imageproc_type;
16 // this is the actual C-structure for our new object
17 typedef struct
18 {
19 // base represents some basic information, like type
20 mp_obj_base_t Base;
21 // a member created by us
22 char *ModuleName;
23 ImageProcType_t mType;
24 void *mInstance;
25 } mp_imageproc_obj_t;
26
imageproc_obj_print(const mp_print_t * print,mp_obj_t self_in,mp_print_kind_t kind)27 void imageproc_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind)
28 {
29 LOGD(LOG_TAG, "entern %s;\n", __func__);
30 mp_imageproc_obj_t *self = MP_OBJ_TO_PTR(self_in);
31 mp_printf(print, "ModuleName(%s)", self->ModuleName);
32 }
33
imageproc_obj_make_new(const mp_obj_type_t * type,size_t n_args,size_t n_kw,const mp_obj_t * args)34 STATIC mp_obj_t imageproc_obj_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args)
35 {
36 LOGD(LOG_TAG, "entern %s;\n", __func__);
37 mp_imageproc_obj_t* driver_obj = m_new_obj(mp_imageproc_obj_t);
38 if (!driver_obj) {
39 mp_raise_OSError(MP_EINVAL);
40 }
41
42 driver_obj->Base.type = &minicv_imageproc_type;
43 driver_obj->ModuleName = "minicv-ImageProc";
44 driver_obj->mType = IMAGE_PROC_NONE;
45 driver_obj->mInstance = NULL;
46
47 return MP_OBJ_FROM_PTR(driver_obj);
48 }
49
obj_open(size_t n_args,const mp_obj_t * args)50 STATIC mp_obj_t obj_open(size_t n_args, const mp_obj_t *args)
51 {
52 LOGD(LOG_TAG, "entern %s; n_args = %d;\n", __func__, n_args);
53 int ret = -1;
54 void* instance = NULL;
55 if (n_args < 2)
56 {
57 LOGE(LOG_TAG, "%s: args num is illegal :n_args = %d;\n", __func__, n_args);
58 return mp_const_none;
59 }
60 mp_obj_base_t *self = (mp_obj_base_t*)MP_OBJ_TO_PTR(args[0]);
61 mp_imageproc_obj_t* driver_obj = (mp_imageproc_obj_t *)self;
62 if (driver_obj == NULL)
63 {
64 LOGE(LOG_TAG, "driver_obj is NULL\n");
65 return mp_const_none;
66 }
67
68 if (driver_obj->mInstance != NULL)
69 {
70 LOGE(LOG_TAG, "Module has been opened, please clode first\n");
71 return mp_const_none;
72 }
73
74 driver_obj->mType = (ImageProcType_t)mp_obj_get_int(args[1]);
75 LOGD(LOG_TAG, "%s:mType = %d;\n", __func__, driver_obj->mType);
76 instance = ImageProcCreateInstance(driver_obj->mType);
77 driver_obj->mInstance = instance;
78 if (instance == NULL)
79 {
80 LOGE(LOG_TAG, "ImageProcCreateInstance failed\n");
81 return mp_const_none;
82 }
83
84 ret = ImageProcOpen(driver_obj->mInstance);
85 LOGD(LOG_TAG, "%s:out ret = %d;\n", __func__, ret);
86
87 return MP_ROM_INT(ret);
88 }
89 STATIC MP_DEFINE_CONST_FUN_OBJ_VAR(imageproc_obj_open, 2, obj_open);
90
obj_close(size_t n_args,const mp_obj_t * args)91 STATIC mp_obj_t obj_close(size_t n_args, const mp_obj_t *args)
92 {
93 LOGD(LOG_TAG, "entern %s; n_args = %d;\n", __func__, n_args);
94 int ret = -1;
95 void* instance = NULL;
96 if (n_args < 1)
97 {
98 LOGE(LOG_TAG, "%s: args num is illegal :n_args = %d;\n", __func__, n_args);
99 return mp_const_none;
100 }
101 mp_obj_base_t *self = (mp_obj_base_t*)MP_OBJ_TO_PTR(args[0]);
102 mp_imageproc_obj_t* driver_obj = (mp_imageproc_obj_t *)self;
103 if (driver_obj == NULL)
104 {
105 LOGE(LOG_TAG, "driver_obj is NULL\n");
106 return mp_const_none;
107 }
108
109 if (driver_obj->mInstance == NULL)
110 {
111 LOGE(LOG_TAG, "Module has not been opened, not need close\n");
112 return mp_const_none;
113 }
114
115 ret = ImageProcClose(driver_obj->mInstance);
116 ImageProcDestoryInstance(driver_obj->mInstance);
117 driver_obj->mType = IMAGE_PROC_NONE;
118 driver_obj->mInstance = NULL;
119 LOGD(LOG_TAG, "%s:out ret = %d;\n", __func__, ret);
120
121 return mp_const_none;
122 }
123 STATIC MP_DEFINE_CONST_FUN_OBJ_VAR(imageproc_obj_close, 1, obj_close);
124
obj_cvtColor(size_t n_args,const mp_obj_t * args)125 STATIC mp_obj_t obj_cvtColor(size_t n_args, const mp_obj_t *args)
126 {
127 LOGD(LOG_TAG, "entern %s; n_args = %d;\n", __func__, n_args);
128 int ret = -1;
129 void* instance = NULL;
130 if (n_args < 4)
131 {
132 LOGE(LOG_TAG, "%s: args num is illegal :n_args = %d;\n", __func__, n_args);
133 return mp_const_none;
134 }
135 mp_obj_base_t *self = (mp_obj_base_t*)MP_OBJ_TO_PTR(args[0]);
136 mp_imageproc_obj_t* driver_obj = (mp_imageproc_obj_t *)self;
137 if (driver_obj == NULL)
138 {
139 LOGE(LOG_TAG, "driver_obj is NULL\n");
140 return mp_const_none;
141 }
142
143 if (driver_obj->mInstance == NULL)
144 {
145 LOGE(LOG_TAG, "Module has been closed, please open first\n");
146 return mp_const_none;
147 }
148
149 ImageBuffer_t* src = (ImageBuffer_t*)MP_OBJ_TO_PTR(args[1]);
150 PixelFmt_t dst_format = (PixelFmt_t)mp_obj_get_int(args[2]);
151 ImageBuffer_t* dst = (ImageBuffer_t*)MP_OBJ_TO_PTR(args[3]);
152 LOGD(LOG_TAG, "src = %p;dst_format = %d; dst = %p;\n", src, dst_format, dst);
153 ret = ImageProcCvtColor(driver_obj->mInstance, src, dst_format, &dst);
154 LOGD(LOG_TAG, "%s:out ret = %d;\n", __func__, ret);
155
156 return MP_ROM_INT(ret);
157 }
158 STATIC MP_DEFINE_CONST_FUN_OBJ_VAR(imageproc_obj_cvtColor, 4, obj_cvtColor);
159
obj_resize(size_t n_args,const mp_obj_t * args)160 STATIC mp_obj_t obj_resize(size_t n_args, const mp_obj_t *args)
161 {
162 LOGD(LOG_TAG, "entern %s; n_args = %d;\n", __func__, n_args);
163 int ret = -1;
164 void* instance = NULL;
165 if (n_args < 5)
166 {
167 LOGE(LOG_TAG, "%s: args num is illegal :n_args = %d;\n", __func__, n_args);
168 return mp_const_none;
169 }
170 mp_obj_base_t *self = (mp_obj_base_t*)MP_OBJ_TO_PTR(args[0]);
171 mp_imageproc_obj_t* driver_obj = (mp_imageproc_obj_t *)self;
172 if (driver_obj == NULL)
173 {
174 LOGE(LOG_TAG, "driver_obj is NULL\n");
175 return mp_const_none;
176 }
177
178 if (driver_obj->mInstance == NULL)
179 {
180 LOGE(LOG_TAG, "Module has been closed, please open first\n");
181 return mp_const_none;
182 }
183
184 ImageBuffer_t* src = (ImageBuffer_t*)MP_OBJ_TO_PTR(args[1]);
185 uint32_t width = (uint32_t)mp_obj_get_int(args[2]);
186 uint32_t height = (uint32_t)mp_obj_get_int(args[3]);
187 ImageBuffer_t* dst = (ImageBuffer_t*)MP_OBJ_TO_PTR(args[4]);
188 LOGD(LOG_TAG, "src = %p;width = %d; height = %d; dst = %p;\n", src, width, height, dst);
189 ImageSize_t imgSize;
190 imgSize.width = width;
191 imgSize.height = height;
192
193 ret = ImageProcResize(driver_obj->mInstance, src, imgSize, &dst);
194 LOGD(LOG_TAG, "%s:out ret = %d;\n", __func__, ret);
195
196 return MP_ROM_INT(ret);
197 }
198 STATIC MP_DEFINE_CONST_FUN_OBJ_VAR(imageproc_obj_resize, 5, obj_resize);
199
obj_imgCopy(size_t n_args,const mp_obj_t * args)200 STATIC mp_obj_t obj_imgCopy(size_t n_args, const mp_obj_t *args)
201 {
202 LOGD(LOG_TAG, "entern %s; n_args = %d;\n", __func__, n_args);
203 int ret = -1;
204 void* instance = NULL;
205 if (n_args < 3)
206 {
207 LOGE(LOG_TAG, "%s: args num is illegal :n_args = %d;\n", __func__, n_args);
208 return mp_const_none;
209 }
210 mp_obj_base_t *self = (mp_obj_base_t*)MP_OBJ_TO_PTR(args[0]);
211 mp_imageproc_obj_t* driver_obj = (mp_imageproc_obj_t *)self;
212 if (driver_obj == NULL)
213 {
214 LOGE(LOG_TAG, "driver_obj is NULL\n");
215 return mp_const_none;
216 }
217
218 if (driver_obj->mInstance == NULL)
219 {
220 LOGE(LOG_TAG, "Module has been closed, please open first\n");
221 return mp_const_none;
222 }
223
224 ImageBuffer_t* src = (ImageBuffer_t*)MP_OBJ_TO_PTR(args[1]);
225 ImageBuffer_t* dst = (ImageBuffer_t*)MP_OBJ_TO_PTR(args[2]);
226 LOGD(LOG_TAG, "src = %p; dst = %p;\n", src, dst);
227
228 ret = ImageProcImgCopy(driver_obj->mInstance, src, &dst);
229 LOGD(LOG_TAG, "%s:out ret = %d;\n", __func__, ret);
230
231 return MP_ROM_INT(ret);
232 }
233 STATIC MP_DEFINE_CONST_FUN_OBJ_VAR(imageproc_obj_imgCopy, 3, obj_imgCopy);
234
obj_rectangle(size_t n_args,const mp_obj_t * args)235 STATIC mp_obj_t obj_rectangle(size_t n_args, const mp_obj_t *args)
236 {
237 LOGD(LOG_TAG, "entern %s; n_args = %d;\n", __func__, n_args);
238 int ret = -1;
239 void* instance = NULL;
240 if (n_args < 6)
241 {
242 LOGE(LOG_TAG, "%s: args num is illegal :n_args = %d;\n", __func__, n_args);
243 return mp_const_none;
244 }
245 mp_obj_base_t *self = (mp_obj_base_t*)MP_OBJ_TO_PTR(args[0]);
246 mp_imageproc_obj_t* driver_obj = (mp_imageproc_obj_t *)self;
247 if (driver_obj == NULL)
248 {
249 LOGE(LOG_TAG, "driver_obj is NULL\n");
250 return mp_const_none;
251 }
252
253 if (driver_obj->mInstance == NULL)
254 {
255 LOGE(LOG_TAG, "Module has been closed, please open first\n");
256 return mp_const_none;
257 }
258
259 ImageBuffer_t* src = (ImageBuffer_t*)MP_OBJ_TO_PTR(args[1]);
260 int32_t left = (int32_t)mp_obj_get_int(args[2]);
261 int32_t top = (int32_t)mp_obj_get_int(args[3]);
262 int32_t right = (int32_t)mp_obj_get_int(args[4]);
263 int32_t bottom = (int32_t)mp_obj_get_int(args[5]);
264 LOGD(LOG_TAG, "src = %p;left = %d; top = %d; right = %d;bottom = %d;\n", src, left, top, right, bottom);
265
266 ret = ImageProcRectangle(driver_obj->mInstance, src, left, top, right, bottom);
267 LOGD(LOG_TAG, "%s:out ret = %d;\n", __func__, ret);
268
269 return MP_ROM_INT(ret);
270 }
271 STATIC MP_DEFINE_CONST_FUN_OBJ_VAR(imageproc_obj_rectangle, 6, obj_rectangle);
272
obj_circle(size_t n_args,const mp_obj_t * args)273 STATIC mp_obj_t obj_circle(size_t n_args, const mp_obj_t *args)
274 {
275 LOGD(LOG_TAG, "entern %s; n_args = %d;\n", __func__, n_args);
276 int ret = -1;
277 void* instance = NULL;
278 if (n_args < 5)
279 {
280 LOGE(LOG_TAG, "%s: args num is illegal :n_args = %d;\n", __func__, n_args);
281 return mp_const_none;
282 }
283 mp_obj_base_t *self = (mp_obj_base_t*)MP_OBJ_TO_PTR(args[0]);
284 mp_imageproc_obj_t* driver_obj = (mp_imageproc_obj_t *)self;
285 if (driver_obj == NULL)
286 {
287 LOGE(LOG_TAG, "driver_obj is NULL\n");
288 return mp_const_none;
289 }
290
291 if (driver_obj->mInstance == NULL)
292 {
293 LOGE(LOG_TAG, "Module has been closed, please open first\n");
294 return mp_const_none;
295 }
296
297 ImageBuffer_t* src = (ImageBuffer_t*)MP_OBJ_TO_PTR(args[1]);
298 int32_t center_x = (int32_t)mp_obj_get_int(args[2]);
299 int32_t center_y = (int32_t)mp_obj_get_int(args[3]);
300 int32_t radius = (int32_t)mp_obj_get_int(args[4]);
301 LOGD(LOG_TAG, "src = %p;center_x = %d; center_y = %d; radius = %d;\n", src, center_x, center_y, radius);
302
303 ret = ImageProcCircle(driver_obj->mInstance, src, center_x, center_y, radius);
304 LOGD(LOG_TAG, "%s:out ret = %d;\n", __func__, ret);
305
306 return MP_ROM_INT(ret);
307 }
308 STATIC MP_DEFINE_CONST_FUN_OBJ_VAR(imageproc_obj_circle, 5, obj_circle);
309
obj_drawMarker(size_t n_args,const mp_obj_t * args)310 STATIC mp_obj_t obj_drawMarker(size_t n_args, const mp_obj_t *args)
311 {
312 LOGD(LOG_TAG, "entern %s; n_args = %d;\n", __func__, n_args);
313 int ret = -1;
314 void* instance = NULL;
315 if (n_args < 5)
316 {
317 LOGE(LOG_TAG, "%s: args num is illegal :n_args = %d;\n", __func__, n_args);
318 return mp_const_none;
319 }
320 mp_obj_base_t *self = (mp_obj_base_t*)MP_OBJ_TO_PTR(args[0]);
321 mp_imageproc_obj_t* driver_obj = (mp_imageproc_obj_t *)self;
322 if (driver_obj == NULL)
323 {
324 LOGE(LOG_TAG, "driver_obj is NULL\n");
325 return mp_const_none;
326 }
327
328 if (driver_obj->mInstance == NULL)
329 {
330 LOGE(LOG_TAG, "Module has been closed, please open first\n");
331 return mp_const_none;
332 }
333
334 ImageBuffer_t* src = (ImageBuffer_t*)MP_OBJ_TO_PTR(args[1]);
335 uint32_t x = (uint32_t)mp_obj_get_int(args[2]);
336 uint32_t y = (uint32_t)mp_obj_get_int(args[3]);
337 int32_t type = (int32_t)mp_obj_get_int(args[4]);
338 LOGD(LOG_TAG, "src = %p;x = %d; y = %d; type = %d;\n", src, x, y, type);
339 Point_t pt;
340 pt.x = x;
341 pt.y = y;
342
343 ret = ImageProcDrawMarker(driver_obj->mInstance, src, &pt, type);
344 LOGD(LOG_TAG, "%s:out ret = %d;\n", __func__, ret);
345
346 return MP_ROM_INT(ret);
347 }
348 STATIC MP_DEFINE_CONST_FUN_OBJ_VAR(imageproc_obj_drawMarker, 5, obj_drawMarker);
349
obj_fillPoly(size_t n_args,const mp_obj_t * args)350 STATIC mp_obj_t obj_fillPoly(size_t n_args, const mp_obj_t *args)
351 {
352 LOGD(LOG_TAG, "entern %s; n_args = %d;\n", __func__, n_args);
353 int ret = -1;
354 void* instance = NULL;
355 if (n_args < 5)
356 {
357 LOGE(LOG_TAG, "%s: args num is illegal :n_args = %d;\n", __func__, n_args);
358 return mp_const_none;
359 }
360 mp_obj_base_t *self = (mp_obj_base_t*)MP_OBJ_TO_PTR(args[0]);
361 mp_imageproc_obj_t* driver_obj = (mp_imageproc_obj_t *)self;
362 if (driver_obj == NULL)
363 {
364 LOGE(LOG_TAG, "driver_obj is NULL\n");
365 return mp_const_none;
366 }
367
368 if (driver_obj->mInstance == NULL)
369 {
370 LOGE(LOG_TAG, "Module has been closed, please open first\n");
371 return mp_const_none;
372 }
373
374 ImageBuffer_t* src = (ImageBuffer_t*)MP_OBJ_TO_PTR(args[1]);
375 uint32_t x = (uint32_t)mp_obj_get_int(args[2]);
376 uint32_t y = (uint32_t)mp_obj_get_int(args[3]);
377 int32_t color = (int32_t)mp_obj_get_int(args[4]);
378 LOGD(LOG_TAG, "src = %p;x = %d; y = %d; color = %d;\n", src, x, y, color);
379 Point_t pt;
380 pt.x = x;
381 pt.y = y;
382 Point_t *ptt = &pt;
383
384 ret = ImageProcFillPoly(driver_obj->mInstance, src, &ptt, color);
385 LOGD(LOG_TAG, "%s:out ret = %d;\n", __func__, ret);
386
387 return MP_ROM_INT(ret);
388 }
389 STATIC MP_DEFINE_CONST_FUN_OBJ_VAR(imageproc_obj_fillPoly, 5, obj_fillPoly);
390
obj_putText(size_t n_args,const mp_obj_t * args)391 STATIC mp_obj_t obj_putText(size_t n_args, const mp_obj_t *args)
392 {
393 LOGD(LOG_TAG, "entern %s; n_args = %d;\n", __func__, n_args);
394 int ret = -1;
395 void* instance = NULL;
396 if (n_args < 5)
397 {
398 LOGE(LOG_TAG, "%s: args num is illegal :n_args = %d;\n", __func__, n_args);
399 return mp_const_none;
400 }
401 mp_obj_base_t *self = (mp_obj_base_t*)MP_OBJ_TO_PTR(args[0]);
402 mp_imageproc_obj_t* driver_obj = (mp_imageproc_obj_t *)self;
403 if (driver_obj == NULL)
404 {
405 LOGE(LOG_TAG, "driver_obj is NULL\n");
406 return mp_const_none;
407 }
408
409 if (driver_obj->mInstance == NULL)
410 {
411 LOGE(LOG_TAG, "Module has been closed, please open first\n");
412 return mp_const_none;
413 }
414
415 ImageBuffer_t* src = (ImageBuffer_t*)MP_OBJ_TO_PTR(args[1]);
416 char* text = (char*)mp_obj_str_get_str(args[2]);
417 int32_t left = (int32_t)mp_obj_get_int(args[3]);
418 int32_t top = (int32_t)mp_obj_get_int(args[4]);
419 LOGD(LOG_TAG, "src = %p;text = %s; left = %d; top = %d;\n", src, text, left, top);
420
421 ret = ImageProcPutText(driver_obj->mInstance, src, text, left, top);
422 LOGD(LOG_TAG, "%s:out ret = %d;\n", __func__, ret);
423
424 return MP_ROM_INT(ret);
425 }
426 STATIC MP_DEFINE_CONST_FUN_OBJ_VAR(imageproc_obj_putText, 5, obj_putText);
427
obj_dilateErode(size_t n_args,const mp_obj_t * args)428 STATIC mp_obj_t obj_dilateErode(size_t n_args, const mp_obj_t *args)
429 {
430 LOGD(LOG_TAG, "entern %s; n_args = %d;\n", __func__, n_args);
431 int ret = -1;
432 void* instance = NULL;
433 if (n_args < 5)
434 {
435 LOGE(LOG_TAG, "%s: args num is illegal :n_args = %d;\n", __func__, n_args);
436 return mp_const_none;
437 }
438 mp_obj_base_t *self = (mp_obj_base_t*)MP_OBJ_TO_PTR(args[0]);
439 mp_imageproc_obj_t* driver_obj = (mp_imageproc_obj_t *)self;
440 if (driver_obj == NULL)
441 {
442 LOGE(LOG_TAG, "driver_obj is NULL\n");
443 return mp_const_none;
444 }
445
446 if (driver_obj->mInstance == NULL)
447 {
448 LOGE(LOG_TAG, "Module has been closed, please open first\n");
449 return mp_const_none;
450 }
451
452 ImageBuffer_t* src = (ImageBuffer_t*)MP_OBJ_TO_PTR(args[1]);
453 ImageBuffer_t* dst = (ImageBuffer_t*)MP_OBJ_TO_PTR(args[2]);
454 int32_t iMode = (int32_t)mp_obj_get_int(args[3]);
455 int32_t iThresh = (int32_t)mp_obj_get_int(args[4]);
456 LOGD(LOG_TAG, "src = %p;dst = %p; iMode = %d; iThresh = %d;\n", src, dst, iMode, iThresh);
457
458 ret = ImageProcDilateErode(driver_obj->mInstance, src, dst, iMode, iThresh);
459 LOGD(LOG_TAG, "%s:out ret = %d;\n", __func__, ret);
460
461 return MP_ROM_INT(ret);
462 }
463 STATIC MP_DEFINE_CONST_FUN_OBJ_VAR(imageproc_obj_dilateErode, 5, obj_dilateErode);
464
obj_imageAdd(size_t n_args,const mp_obj_t * args)465 STATIC mp_obj_t obj_imageAdd(size_t n_args, const mp_obj_t *args)
466 {
467 LOGD(LOG_TAG, "entern %s; n_args = %d;\n", __func__, n_args);
468 int ret = -1;
469 void* instance = NULL;
470 if (n_args < 5)
471 {
472 LOGE(LOG_TAG, "%s: args num is illegal :n_args = %d;\n", __func__, n_args);
473 return mp_const_none;
474 }
475 mp_obj_base_t *self = (mp_obj_base_t*)MP_OBJ_TO_PTR(args[0]);
476 mp_imageproc_obj_t* driver_obj = (mp_imageproc_obj_t *)self;
477 if (driver_obj == NULL)
478 {
479 LOGE(LOG_TAG, "driver_obj is NULL\n");
480 return mp_const_none;
481 }
482
483 if (driver_obj->mInstance == NULL)
484 {
485 LOGE(LOG_TAG, "Module has been closed, please open first\n");
486 return mp_const_none;
487 }
488
489 ImageBuffer_t* src = (ImageBuffer_t*)MP_OBJ_TO_PTR(args[1]);
490 ImageBuffer_t* added = (ImageBuffer_t*)MP_OBJ_TO_PTR(args[2]);
491 ImageBuffer_t* dst = (ImageBuffer_t*)MP_OBJ_TO_PTR(args[3]);
492 LOGD(LOG_TAG, "src = %p;added = %p; dst = %p;\n", src, added, dst);
493
494 ImageProcImageAdd(driver_obj->mInstance, src, added, dst);
495 LOGD(LOG_TAG, "%s:out \n", __func__);
496
497 return mp_const_none;
498 }
499 STATIC MP_DEFINE_CONST_FUN_OBJ_VAR(imageproc_obj_imageAdd, 4, obj_imageAdd);
500
obj_imageMinus(size_t n_args,const mp_obj_t * args)501 STATIC mp_obj_t obj_imageMinus(size_t n_args, const mp_obj_t *args)
502 {
503 LOGD(LOG_TAG, "entern %s; n_args = %d;\n", __func__, n_args);
504 int ret = -1;
505 void* instance = NULL;
506 if (n_args < 4)
507 {
508 LOGE(LOG_TAG, "%s: args num is illegal :n_args = %d;\n", __func__, n_args);
509 return mp_const_none;
510 }
511 mp_obj_base_t *self = (mp_obj_base_t*)MP_OBJ_TO_PTR(args[0]);
512 mp_imageproc_obj_t* driver_obj = (mp_imageproc_obj_t *)self;
513 if (driver_obj == NULL)
514 {
515 LOGE(LOG_TAG, "driver_obj is NULL\n");
516 return mp_const_none;
517 }
518
519 if (driver_obj->mInstance == NULL)
520 {
521 LOGE(LOG_TAG, "Module has been closed, please open first\n");
522 return mp_const_none;
523 }
524
525 ImageBuffer_t* src = (ImageBuffer_t*)MP_OBJ_TO_PTR(args[1]);
526 ImageBuffer_t* minused = (ImageBuffer_t*)MP_OBJ_TO_PTR(args[2]);
527 ImageBuffer_t* dst = (ImageBuffer_t*)MP_OBJ_TO_PTR(args[3]);
528 LOGD(LOG_TAG, "src = %p;minused = %p; dst = %p;\n", src, minused, dst);
529
530 ImageProcImageMinus(driver_obj->mInstance, src, minused, dst);
531 LOGD(LOG_TAG, "%s:out \n", __func__);
532
533 return mp_const_none;
534 }
535 STATIC MP_DEFINE_CONST_FUN_OBJ_VAR(imageproc_obj_imageMinus, 4, obj_imageMinus);
536
obj_imageElementMultiply(size_t n_args,const mp_obj_t * args)537 STATIC mp_obj_t obj_imageElementMultiply(size_t n_args, const mp_obj_t *args)
538 {
539 LOGD(LOG_TAG, "entern %s; n_args = %d;\n", __func__, n_args);
540 int ret = -1;
541 void* instance = NULL;
542 if (n_args < 4)
543 {
544 LOGE(LOG_TAG, "%s: args num is illegal :n_args = %d;\n", __func__, n_args);
545 return mp_const_none;
546 }
547 mp_obj_base_t *self = (mp_obj_base_t*)MP_OBJ_TO_PTR(args[0]);
548 mp_imageproc_obj_t* driver_obj = (mp_imageproc_obj_t *)self;
549 if (driver_obj == NULL)
550 {
551 LOGE(LOG_TAG, "driver_obj is NULL\n");
552 return mp_const_none;
553 }
554
555 if (driver_obj->mInstance == NULL)
556 {
557 LOGE(LOG_TAG, "Module has been closed, please open first\n");
558 return mp_const_none;
559 }
560
561 ImageBuffer_t* src = (ImageBuffer_t*)MP_OBJ_TO_PTR(args[1]);
562 ImageBuffer_t* multiplied = (ImageBuffer_t*)MP_OBJ_TO_PTR(args[2]);
563 ImageBuffer_t* dst = (ImageBuffer_t*)MP_OBJ_TO_PTR(args[3]);
564 LOGD(LOG_TAG, "src = %p;multiplied = %p; dst = %p;\n", src, multiplied, dst);
565
566 ImageProcImageElementMultiply(driver_obj->mInstance, src, multiplied, dst);
567 LOGD(LOG_TAG, "%s:out \n", __func__);
568
569 return mp_const_none;
570 }
571 STATIC MP_DEFINE_CONST_FUN_OBJ_VAR(imageproc_obj_imageElementMultiply, 4, obj_imageElementMultiply);
572
obj_imageElementDivide(size_t n_args,const mp_obj_t * args)573 STATIC mp_obj_t obj_imageElementDivide(size_t n_args, const mp_obj_t *args)
574 {
575 LOGD(LOG_TAG, "entern %s; n_args = %d;\n", __func__, n_args);
576 int ret = -1;
577 void* instance = NULL;
578 if (n_args < 4)
579 {
580 LOGE(LOG_TAG, "%s: args num is illegal :n_args = %d;\n", __func__, n_args);
581 return mp_const_none;
582 }
583 mp_obj_base_t *self = (mp_obj_base_t*)MP_OBJ_TO_PTR(args[0]);
584 mp_imageproc_obj_t* driver_obj = (mp_imageproc_obj_t *)self;
585 if (driver_obj == NULL)
586 {
587 LOGE(LOG_TAG, "driver_obj is NULL\n");
588 return mp_const_none;
589 }
590
591 if (driver_obj->mInstance == NULL)
592 {
593 LOGE(LOG_TAG, "Module has been closed, please open first\n");
594 return mp_const_none;
595 }
596
597 ImageBuffer_t* src = (ImageBuffer_t*)MP_OBJ_TO_PTR(args[1]);
598 ImageBuffer_t* divied = (ImageBuffer_t*)MP_OBJ_TO_PTR(args[2]);
599 ImageBuffer_t* dst = (ImageBuffer_t*)MP_OBJ_TO_PTR(args[3]);
600 LOGD(LOG_TAG, "src = %p;divied = %p; dst = %p;\n", src, divied, dst);
601
602 ImageProcImageElementDivide(driver_obj->mInstance, src, divied, dst);
603 LOGD(LOG_TAG, "%s:out \n", __func__);
604
605 return mp_const_none;
606 }
607 STATIC MP_DEFINE_CONST_FUN_OBJ_VAR(imageproc_obj_imageElementDivide, 4, obj_imageElementDivide);
608
obj_writeImageToFile(size_t n_args,const mp_obj_t * args)609 STATIC mp_obj_t obj_writeImageToFile(size_t n_args, const mp_obj_t *args)
610 {
611 LOGD(LOG_TAG, "entern %s; n_args = %d;\n", __func__, n_args);
612 int ret = -1;
613 void* instance = NULL;
614 if (n_args < 3)
615 {
616 LOGE(LOG_TAG, "%s: args num is illegal :n_args = %d;\n", __func__, n_args);
617 return mp_const_none;
618 }
619 mp_obj_base_t *self = (mp_obj_base_t*)MP_OBJ_TO_PTR(args[0]);
620 mp_imageproc_obj_t* driver_obj = (mp_imageproc_obj_t *)self;
621 if (driver_obj == NULL)
622 {
623 LOGE(LOG_TAG, "driver_obj is NULL\n");
624 return mp_const_none;
625 }
626
627 if (driver_obj->mInstance == NULL)
628 {
629 LOGE(LOG_TAG, "Module has been closed, please open first\n");
630 return mp_const_none;
631 }
632
633 ImageBuffer_t* src = (ImageBuffer_t*)MP_OBJ_TO_PTR(args[1]);
634 char* file_name = (char*)mp_obj_str_get_str(args[2]);
635 LOGD(LOG_TAG, "src = %p;file_name = %s;\n", src, file_name);
636
637 ret = ImageProcWriteImageToFile(driver_obj->mInstance, src, file_name);
638 LOGD(LOG_TAG, "%s:out ret = %d;\n", __func__, ret);
639
640 return MP_ROM_INT(ret);
641 }
642 STATIC MP_DEFINE_CONST_FUN_OBJ_VAR(imageproc_obj_writeImageToFile, 3, obj_writeImageToFile);
643
644 STATIC const mp_rom_map_elem_t imageproc_locals_dict_table[] = {
645 {MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ImageProc)},
646 {MP_OBJ_NEW_QSTR(MP_QSTR_IMAGE_PROC_NONE), MP_ROM_INT(IMAGE_PROC_NONE)},
647 {MP_OBJ_NEW_QSTR(MP_QSTR_IMAGE_PROC_CPU), MP_ROM_INT(IMAGE_PROC_CPU)},
648 {MP_OBJ_NEW_QSTR(MP_QSTR_IMAGE_PROC_OPENCV), MP_ROM_INT(IMAGE_PROC_OPENCV)},
649 {MP_OBJ_NEW_QSTR(MP_QSTR_IMAGE_PROC_HAL), MP_ROM_INT(IMAGE_PROC_HAL)},
650 {MP_OBJ_NEW_QSTR(MP_QSTR_IMAGE_PROC_MAX), MP_ROM_INT(IMAGE_PROC_MAX)},
651 {MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&imageproc_obj_open)},
652 {MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&imageproc_obj_close)},
653 {MP_ROM_QSTR(MP_QSTR_cvtColor), MP_ROM_PTR(&imageproc_obj_cvtColor)},
654 {MP_ROM_QSTR(MP_QSTR_resize), MP_ROM_PTR(&imageproc_obj_resize)},
655 {MP_ROM_QSTR(MP_QSTR_imgCopy), MP_ROM_PTR(&imageproc_obj_imgCopy)},
656 {MP_ROM_QSTR(MP_QSTR_rectangle), MP_ROM_PTR(&imageproc_obj_rectangle)},
657 {MP_ROM_QSTR(MP_QSTR_circle), MP_ROM_PTR(&imageproc_obj_circle)},
658 {MP_ROM_QSTR(MP_QSTR_drawMarker), MP_ROM_PTR(&imageproc_obj_drawMarker)},
659 {MP_ROM_QSTR(MP_QSTR_fillPoly), MP_ROM_PTR(&imageproc_obj_fillPoly)},
660 {MP_ROM_QSTR(MP_QSTR_putText), MP_ROM_PTR(&imageproc_obj_putText)},
661 {MP_ROM_QSTR(MP_QSTR_dilateErode), MP_ROM_PTR(&imageproc_obj_dilateErode)},
662 {MP_ROM_QSTR(MP_QSTR_imageAdd), MP_ROM_PTR(&imageproc_obj_imageAdd)},
663 {MP_ROM_QSTR(MP_QSTR_imageMinus), MP_ROM_PTR(&imageproc_obj_imageMinus)},
664 {MP_ROM_QSTR(MP_QSTR_imageElementMultiply), MP_ROM_PTR(&imageproc_obj_imageElementMultiply)},
665 {MP_ROM_QSTR(MP_QSTR_imageElementDivide), MP_ROM_PTR(&imageproc_obj_imageElementDivide)},
666 {MP_ROM_QSTR(MP_QSTR_writeImageToFile), MP_ROM_PTR(&imageproc_obj_writeImageToFile)},
667 };
668
669 STATIC MP_DEFINE_CONST_DICT(imageproc_locals_dict, imageproc_locals_dict_table);
670
671 const mp_obj_type_t minicv_imageproc_type = {
672 .base = {&mp_type_type},
673 .name = MP_QSTR_ImageProc,
674 .print = imageproc_obj_print,
675 .make_new = imageproc_obj_make_new,
676 .locals_dict = (mp_obj_dict_t *)&imageproc_locals_dict,
677 };
678
679