From 157a469ec3bc5e42e8c2d7724a1225b85ff1732b Mon Sep 17 00:00:00 2001 From: "Kwabena W. Agyeman" Date: Wed, 20 Jun 2018 02:46:09 -0400 Subject: [PATCH] Fix finding small apriltags. --- scripts/examples/26-April-Tags/find_small_apriltags.py | 10 +++++----- src/omv/py/py_image.c | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/scripts/examples/26-April-Tags/find_small_apriltags.py b/scripts/examples/26-April-Tags/find_small_apriltags.py index 4c60fa655..cbd54bf9e 100644 --- a/scripts/examples/26-April-Tags/find_small_apriltags.py +++ b/scripts/examples/26-April-Tags/find_small_apriltags.py @@ -46,10 +46,10 @@ while(True): for blob in img.find_blobs([thresholds], pixels_threshold=100, area_threshold=100, merge=True): # Next we look for a tag in an ROI that's bigger than the blob. - w = min(max(int(blob.w() * 1.2), 20), 100) # Not too small, not too big. - h = min(max(int(blob.h() * 1.2), 20), 100) # Not too small, not too big. - x = min(max(int(blob.x() - (w * 0.1)), 0), img.width()-1) - y = min(max(int(blob.y() - (h * 0.1)), 0), img.height()-1) + w = min(max(int(blob.w() * 1.2), 10), 160) # Not too small, not too big. + h = min(max(int(blob.h() * 1.2), 10), 160) # Not too small, not too big. + x = min(max(int(blob.x() + (blob.w()/4) - (w * 0.1)), 0), img.width()-1) + y = min(max(int(blob.y() + (blob.h()/4) - (h * 0.1)), 0), img.height()-1) box_list.append((x, y, w, h)) # We'll draw these later. @@ -57,7 +57,7 @@ while(True): # But, if it does we handle it... try: tag_list.extend(img.find_apriltags(roi=(x,y,w,h), families=tag_families)) - except (MemoryError, OSError): # Don't catch all exceptions otherwise you can't stop the script. + except (MemoryError): # Don't catch all exceptions otherwise you can't stop the script. pass for b in box_list: diff --git a/src/omv/py/py_image.c b/src/omv/py/py_image.c index ff75b63a2..eaf9f68c5 100644 --- a/src/omv/py/py_image.c +++ b/src/omv/py/py_image.c @@ -4528,13 +4528,13 @@ static const mp_obj_type_t py_apriltag_type = { static mp_obj_t py_image_find_apriltags(uint n_args, const mp_obj_t *args, mp_map_t *kw_args) { image_t *arg_img = py_helper_arg_to_image_mutable(args[0]); - PY_ASSERT_TRUE_MSG((arg_img->w * arg_img->h) < 65536, "The maximum supported resolution for find_apriltags() is 64K pixels."); - if ((arg_img->w < 4) || (arg_img->h < 4)) { - return mp_obj_new_list(0, NULL); - } rectangle_t roi; py_helper_keyword_rectangle_roi(arg_img, n_args, args, 1, kw_args, &roi); + PY_ASSERT_TRUE_MSG((roi.w * roi.h) < 65536, "The maximum supported resolution for find_apriltags() is < 64K pixels."); + if ((roi.w < 4) || (roi.h < 4)) { + return mp_obj_new_list(0, NULL); + } apriltag_families_t families = py_helper_keyword_int(n_args, args, 2, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_families), TAG36H11); // 2.8mm Focal Length w/ OV7725 sensor for reference.