mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
Revert HaarCascade.
* HaarCascade doesn't really fit into generic descriptor functions.
This commit is contained in:
parent
67acf7188c
commit
acafef5207
@ -1 +1 @@
|
||||
Subproject commit 725401182220a6d87d6b7105350dd9244a055fa6
|
||||
Subproject commit d5dd53aea029077a44456ea8f0a0aab9b9be242c
|
||||
@ -314,9 +314,8 @@ typedef struct img_read_settings {
|
||||
typedef void (*line_op_t)(image_t*, int, uint8_t*);
|
||||
|
||||
typedef enum descriptor_type {
|
||||
DESC_HAAR,
|
||||
DESC_FREAK,
|
||||
DESC_LBP,
|
||||
DESC_FREAK,
|
||||
} descriptor_t;
|
||||
|
||||
/* Image file functions */
|
||||
|
||||
@ -1308,6 +1308,31 @@ mp_obj_t py_image_load_image(mp_obj_t path_obj)
|
||||
return image_obj;
|
||||
}
|
||||
|
||||
mp_obj_t py_image_load_cascade(uint n_args, const mp_obj_t *args, mp_map_t *kw_args)
|
||||
{
|
||||
cascade_t cascade;
|
||||
const char *path = mp_obj_str_get_str(args[0]);
|
||||
|
||||
// Load cascade from file or flash
|
||||
int res = imlib_load_cascade(&cascade, path);
|
||||
if (res != FR_OK) {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, ffs_strerror(res)));
|
||||
}
|
||||
|
||||
// Read the number of stages
|
||||
int stages = py_helper_lookup_int(kw_args, MP_OBJ_NEW_QSTR(qstr_from_str("stages")), cascade.n_stages);
|
||||
// Check the number of stages
|
||||
if (stages > 0 && stages < cascade.n_stages) {
|
||||
cascade.n_stages = stages;
|
||||
}
|
||||
|
||||
// Return micropython cascade object
|
||||
py_cascade_obj_t *o = m_new_obj(py_cascade_obj_t);
|
||||
o->base.type = &py_cascade_type;
|
||||
o->_cobj = cascade;
|
||||
return o;
|
||||
}
|
||||
|
||||
mp_obj_t py_image_load_descriptor(uint n_args, const mp_obj_t *args, mp_map_t *kw_args)
|
||||
{
|
||||
int res = FR_OK;
|
||||
@ -1316,28 +1341,18 @@ mp_obj_t py_image_load_descriptor(uint n_args, const mp_obj_t *args, mp_map_t *k
|
||||
const char *path = mp_obj_str_get_str(args[1]);
|
||||
|
||||
switch (desc_type) {
|
||||
case DESC_HAAR: {
|
||||
cascade_t cascade;
|
||||
// Load cascade from file or flash
|
||||
res = imlib_load_cascade(&cascade, path);
|
||||
case DESC_LBP: {
|
||||
py_lbp_obj_t *lbp = m_new_obj(py_lbp_obj_t);
|
||||
lbp->base.type = &py_lbp_type;
|
||||
|
||||
res = imlib_lbp_desc_load(path, &lbp->hist);
|
||||
if (res != FR_OK) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Read the number of stages
|
||||
int stages = py_helper_lookup_int(kw_args, MP_OBJ_NEW_QSTR(qstr_from_str("stages")), cascade.n_stages);
|
||||
// Check the number of stages
|
||||
if (stages > 0 && stages < cascade.n_stages) {
|
||||
cascade.n_stages = stages;
|
||||
}
|
||||
|
||||
// Return micropython cascade object
|
||||
py_cascade_obj_t *o = m_new_obj(py_cascade_obj_t);
|
||||
o->base.type = &py_cascade_type;
|
||||
o->_cobj = cascade;
|
||||
desc = o;
|
||||
desc = lbp;
|
||||
break;
|
||||
}
|
||||
|
||||
case DESC_FREAK: {
|
||||
array_t *kpts = NULL;
|
||||
array_alloc(&kpts, xfree);
|
||||
@ -1356,19 +1371,10 @@ mp_obj_t py_image_load_descriptor(uint n_args, const mp_obj_t *args, mp_map_t *k
|
||||
desc = kp_obj;
|
||||
break;
|
||||
}
|
||||
case DESC_LBP: {
|
||||
py_lbp_obj_t *lbp = m_new_obj(py_lbp_obj_t);
|
||||
lbp->base.type = &py_lbp_type;
|
||||
|
||||
res = imlib_lbp_desc_load(path, &lbp->hist);
|
||||
if (res != FR_OK) {
|
||||
break;
|
||||
}
|
||||
desc = lbp;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
default: {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Descriptor type is not supported"));
|
||||
}
|
||||
}
|
||||
|
||||
if (res != FR_OK) {
|
||||
@ -1384,19 +1390,21 @@ mp_obj_t py_image_save_descriptor(uint n_args, const mp_obj_t *args, mp_map_t *k
|
||||
const char *path = mp_obj_str_get_str(args[1]);
|
||||
|
||||
switch (desc_type) {
|
||||
case DESC_FREAK: {
|
||||
py_kp_obj_t *kpts = ((py_kp_obj_t*)args[2]);
|
||||
res = freak_save_descriptor(kpts->kpts, path);
|
||||
break;
|
||||
}
|
||||
case DESC_LBP: {
|
||||
py_lbp_obj_t *lbp = ((py_lbp_obj_t*)args[2]);
|
||||
res = imlib_lbp_desc_save(path, lbp->hist);
|
||||
break;
|
||||
}
|
||||
case DESC_HAAR: // Can't save Haar
|
||||
default:
|
||||
|
||||
case DESC_FREAK: {
|
||||
py_kp_obj_t *kpts = ((py_kp_obj_t*)args[2]);
|
||||
res = freak_save_descriptor(kpts->kpts, path);
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Descriptor type is not supported"));
|
||||
}
|
||||
}
|
||||
|
||||
if (res != FR_OK) {
|
||||
@ -1406,18 +1414,19 @@ mp_obj_t py_image_save_descriptor(uint n_args, const mp_obj_t *args, mp_map_t *k
|
||||
}
|
||||
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(py_image_load_image_obj, py_image_load_image);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(py_image_load_cascade_obj, 1, py_image_load_cascade);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(py_image_load_descriptor_obj, 2, py_image_load_descriptor);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(py_image_save_descriptor_obj, 3, py_image_save_descriptor);
|
||||
|
||||
static const mp_map_elem_t globals_dict_table[] = {
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_image) },
|
||||
// Descriptor types
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_HAAR), MP_OBJ_NEW_SMALL_INT(DESC_HAAR)},
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_FREAK), MP_OBJ_NEW_SMALL_INT(DESC_FREAK)},
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_LBP), MP_OBJ_NEW_SMALL_INT(DESC_LBP)},
|
||||
|
||||
// Image module functions
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_Image), (mp_obj_t)&py_image_load_image_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_HaarCascade), (mp_obj_t)&py_image_load_cascade_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_load_descriptor), (mp_obj_t)&py_image_load_descriptor_obj },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_save_descriptor), (mp_obj_t)&py_image_save_descriptor_obj },
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user