From fafd586b32ebc03492b636da7969c5d06c6c41f9 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Wed, 29 Apr 2015 04:02:40 +0300 Subject: [PATCH] Disable LAB table for OpenMV1 * The LAB lookup is too big for 512K flash, it used to fit at some point but not after enabling all the needed modules. * The imlib_rgb_to_lab function is way slower than LAB lookup, but it's a must to maintain support for OMV1 --- src/omv/img/imlib.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/omv/img/imlib.c b/src/omv/img/imlib.c index 97f9b87df..4225e10ff 100644 --- a/src/omv/img/imlib.c +++ b/src/omv/img/imlib.c @@ -250,6 +250,47 @@ void imlib_binary(image_t *src, int threshold) } } +#ifdef OPENMV1 +void imlib_threshold(image_t *src, image_t *dst, color_t *color, int color_size, int threshold) +{ + struct color rgb, lab; + /* Square threshold */ + threshold *= threshold; + + /* Convert reference RGB888 to LAB */ + for (int c=0; cpixels; + + for (int y=0; yh; y++) { + int i=y*src->w; + for (int x=0; xw; x++) { + uint32_t p = pixels[i+x]; + rgb.r = ((p>>3)&0x1F)*255/31; + rgb.g = ((p&0x07)<<3)|(p>>13)*255/63; + rgb.b = ((p>>8)&0x1F)*255/31; + imlib_rgb_to_lab(&rgb, &lab); + + dst->pixels[i+x] = 0; + for (int c=0; cpixels[i+x] = c+1; //sets color label c+1 + break; + } + } + } + } +} +#else void imlib_threshold(image_t *src, image_t *dst, color_t *color, int color_size, int threshold) { /* Square threshold */ @@ -272,6 +313,7 @@ void imlib_threshold(image_t *src, image_t *dst, color_t *color, int color_size, for (int y=0; yh; y++) { int i=y*src->w; for (int x=0; xw; x++) { + // mult by 3 for lab_table lookup uint32_t rgb = pixels[i+x]*3; dst->pixels[i+x] = 0; for (int c=0; c