From 9d51051ba8cb49ec2c1d148fc11f46d9eebc03c3 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Thu, 9 Jul 2015 04:38:07 +0200 Subject: [PATCH] Return FR_NO_FILE if built-in cascade not found --- src/omv/img/haar.c | 7 ++++++- usr/examples/face_detection.py | 24 +++++++++++++++--------- usr/examples/face_tracking.py | 15 +++++++-------- 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/src/omv/img/haar.c b/src/omv/img/haar.c index 57603a7c8..5be830620 100644 --- a/src/omv/img/haar.c +++ b/src/omv/img/haar.c @@ -292,6 +292,8 @@ error: int imlib_load_cascade_from_flash(cascade_t *cascade, const char *path) { + FRESULT res=FR_OK; + if (strcmp(path, "frontalface") == 0) { cascade->window.w = frontalface_window_w; cascade->window.h = frontalface_window_h; @@ -316,8 +318,11 @@ int imlib_load_cascade_from_flash(cascade_t *cascade, const char *path) cascade->num_rectangles_array= (int8_t *)eye_num_rectangles_array; cascade->weights_array = (int8_t *)eye_weights_array; cascade->rectangles_array = (int8_t *)eye_rectangles_array; + } else { + res = FR_NO_FILE; } - return 0; + + return res; } int imlib_load_cascade(cascade_t *cascade, const char *path) diff --git a/usr/examples/face_detection.py b/usr/examples/face_detection.py index c830d243a..293acdecb 100644 --- a/usr/examples/face_detection.py +++ b/usr/examples/face_detection.py @@ -1,24 +1,30 @@ import sensor, time + +# Reset sensor sensor.reset() -# Set sensor brightness + +# Sensor settings sensor.set_contrast(1) -# Set sensor gainceiling sensor.set_gainceiling(16) -# Set framesize -sensor.set_framesize(sensor.QCIF) -# Set sensor to grayscale +sensor.set_framesize(sensor.QQVGA) sensor.set_pixformat(sensor.GRAYSCALE) # Load Haar Cascade -face_cascade = HaarCascade("/frontalface.cascade") +face_cascade = HaarCascade("frontalface") print(face_cascade) + +# FPS clock clock = time.clock() while (True): clock.tick() + # Capture snapshot image = sensor.snapshot() - objects = image.find_features(face_cascade, threshold=0.65, scale=1.65) + # Find objects + objects = image.find_features(face_cascade, threshold=0.65, scale=1.85) + # Draw objects for r in objects: image.draw_rectangle(r) - #Add delay to see drawing on FB - time.sleep(10) + #Add delay to see drawing on FB + time.sleep(100) + print (clock.fps()) diff --git a/usr/examples/face_tracking.py b/usr/examples/face_tracking.py index 5c03563ce..231a1c794 100644 --- a/usr/examples/face_tracking.py +++ b/usr/examples/face_tracking.py @@ -1,18 +1,17 @@ import sensor, time -#sensor.reset() -# Set framesize -sensor.set_framesize(sensor.QQVGA) -# Set sensor to grayscale -sensor.set_pixformat(sensor.GRAYSCALE) -# Set sensor contrast +# Reset sensor +sensor.reset() + +# Sensor settings sensor.set_contrast(1) -# Set sensor gainceiling sensor.set_gainceiling(16) +sensor.set_framesize(sensor.QQVGA) +sensor.set_pixformat(sensor.GRAYSCALE) def find_face(): global sensor, time # Load Haar Cascade - face_cascade = HaarCascade("/frontalface.cascade") + face_cascade = HaarCascade("frontalface") while (True): image = sensor.snapshot() objects = image.find_features(face_cascade, threshold=0.65, scale=1.85)