mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
Merge pull request #173 from kwagyeman/windowing_fix
Made set_windowing simpler.
This commit is contained in:
commit
f5ce531078
@ -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;
|
||||
|
||||
@ -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):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user