From 0e89b655bf7644a915567b4a1e82ec8d166aab06 Mon Sep 17 00:00:00 2001 From: "Kwabena W. Agyeman" Date: Thu, 12 Jan 2017 17:41:40 -0500 Subject: [PATCH] Made set_windowing simpilier. Tested with updated qr code example script. --- src/omv/py/py_sensor.c | 22 ++++++++++++++----- .../qrcodes_with_lens_zoom.py | 18 +++++---------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/omv/py/py_sensor.c b/src/omv/py/py_sensor.c index e523b45ab..c1b3b6271 100644 --- a/src/omv/py/py_sensor.c +++ b/src/omv/py/py_sensor.c @@ -147,13 +147,25 @@ static mp_obj_t py_sensor_set_framesize(mp_obj_t framesize) { } static mp_obj_t py_sensor_set_windowing(mp_obj_t roi_obj) { + mp_uint_t array_len; mp_obj_t *array; - mp_obj_get_array_fixed_n(roi_obj, 4, &array); + mp_obj_get_array(roi_obj, &array_len, &array); + int x, y, w, h; - int x = mp_obj_get_int(array[0]); - int y = mp_obj_get_int(array[1]); - int w = mp_obj_get_int(array[2]); - int h = mp_obj_get_int(array[3]); + if (array_len == 4) { + x = mp_obj_get_int(array[0]); + y = mp_obj_get_int(array[1]); + w = mp_obj_get_int(array[2]); + h = mp_obj_get_int(array[3]); + } else if (array_len == 2) { + w = mp_obj_get_int(array[0]); + h = mp_obj_get_int(array[1]); + x = (resolution[sensor.framesize][0] / 2) - (w / 2); + y = (resolution[sensor.framesize][1] / 2) - (h / 2); + } else { + nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, + "tuple/list must either be (x, y, w, h) or (w, h)")); + } if (sensor_set_windowing(x, y, w, h) != 0) { return mp_const_false; diff --git a/usr/examples/09-Feature-Detection/qrcodes_with_lens_zoom.py b/usr/examples/09-Feature-Detection/qrcodes_with_lens_zoom.py index 5d3088aaf..f16ddc4da 100644 --- a/usr/examples/09-Feature-Detection/qrcodes_with_lens_zoom.py +++ b/usr/examples/09-Feature-Detection/qrcodes_with_lens_zoom.py @@ -1,24 +1,16 @@ # QRCode Example # -# This example shows the power of the OpenMV Cam to detect QR Codes. -# -# On the new M7 OpenMV Cam you can detect QR codes at up to 320x240 in Grayscale or RGB565. -# We may be able to enable 640x480 operation in the future if we re-write the QR code library's front end code. -# -# On the M4 OpenMV Cam QR code detection should be done strictly at a maximum of 160x120 for Grayscale or RGB565. -# -# Lastly, reading QRCodes requires lens correction to improve the detection rate. -# Additionally, histogram equalization could be used to increase the contrast but is not required. +# This example shows the power of the OpenMV Cam to detect QR Codes +# without needing lens correction. import sensor, image, time -# For the new M7 OpenMV Cam... sensor.reset() sensor.set_pixformat(sensor.GRAYSCALE) sensor.set_framesize(sensor.VGA) -sensor.set_windowing((640//2 - 200//2, 480//2 - 200//2, 200, 200)) -sensor.skip_frames(10) -sensor.set_auto_gain(False) +sensor.set_windowing((240, 240)) # look at center 240x240 pixels of the VGA resolution. +sensor.skip_frames(30) +sensor.set_auto_gain(False) # must turn this off to prevent image washout... clock = time.clock() while(True):