mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
imlib/pool: Remove obsolete pooling functions.
This commit is contained in:
parent
99c3ddd7fc
commit
08ca21fd1b
@ -23,7 +23,7 @@
|
|||||||
#
|
#
|
||||||
# Your OpenMV Cam supports power of 2 resolutions of 64x32, 64x64,
|
# Your OpenMV Cam supports power of 2 resolutions of 64x32, 64x64,
|
||||||
# 128x64, and 128x128. If you want a resolution of 32x32 you can create
|
# 128x64, and 128x128. If you want a resolution of 32x32 you can create
|
||||||
# it by doing "img.pool(2, 2)" on a 64x64 image.
|
# it by doing "img.scale(x_scale=0.5, y_scale=0.5, hint=image.AREA)" on a 64x64 image.
|
||||||
|
|
||||||
import sensor
|
import sensor
|
||||||
import time
|
import time
|
||||||
|
|||||||
@ -23,7 +23,7 @@
|
|||||||
#
|
#
|
||||||
# Your OpenMV Cam supports power of 2 resolutions of 64x32, 64x64,
|
# Your OpenMV Cam supports power of 2 resolutions of 64x32, 64x64,
|
||||||
# 128x64, and 128x128. If you want a resolution of 32x32 you can create
|
# 128x64, and 128x128. If you want a resolution of 32x32 you can create
|
||||||
# it by doing "img.pool(2, 2)" on a 64x64 image.
|
# it by doing "img.scale(x_scale=0.5, y_scale=0.5, hint=image.AREA)" on a 64x64 image.
|
||||||
|
|
||||||
import sensor
|
import sensor
|
||||||
import time
|
import time
|
||||||
|
|||||||
@ -23,7 +23,7 @@
|
|||||||
#
|
#
|
||||||
# Your OpenMV Cam supports power of 2 resolutions of 64x32, 64x64,
|
# Your OpenMV Cam supports power of 2 resolutions of 64x32, 64x64,
|
||||||
# 128x64, and 128x128. If you want a resolution of 32x32 you can create
|
# 128x64, and 128x128. If you want a resolution of 32x32 you can create
|
||||||
# it by doing "img.pool(2, 2)" on a 64x64 image.
|
# it by doing "img.scale(x_scale=0.5, y_scale=0.5, hint=image.AREA)" on a 64x64 image.
|
||||||
|
|
||||||
import sensor
|
import sensor
|
||||||
import time
|
import time
|
||||||
|
|||||||
@ -23,7 +23,7 @@
|
|||||||
#
|
#
|
||||||
# Your OpenMV Cam supports power of 2 resolutions of 64x32, 64x64,
|
# Your OpenMV Cam supports power of 2 resolutions of 64x32, 64x64,
|
||||||
# 128x64, and 128x128. If you want a resolution of 32x32 you can create
|
# 128x64, and 128x128. If you want a resolution of 32x32 you can create
|
||||||
# it by doing "img.pool(2, 2)" on a 64x64 image.
|
# it by doing "img.scale(x_scale=0.5, y_scale=0.5, hint=image.AREA)" on a 64x64 image.
|
||||||
|
|
||||||
import sensor
|
import sensor
|
||||||
import time
|
import time
|
||||||
|
|||||||
@ -30,7 +30,7 @@
|
|||||||
#
|
#
|
||||||
# Your OpenMV Cam supports power of 2 resolutions of 64x32, 64x64,
|
# Your OpenMV Cam supports power of 2 resolutions of 64x32, 64x64,
|
||||||
# 128x64, and 128x128. If you want a resolution of 32x32 you can create
|
# 128x64, and 128x128. If you want a resolution of 32x32 you can create
|
||||||
# it by doing "img.pool(2, 2)" on a 64x64 image.
|
# it by doing "img.scale(x_scale=0.5, y_scale=0.5, hint=image.AREA)" on a 64x64 image.
|
||||||
|
|
||||||
import sensor
|
import sensor
|
||||||
import time
|
import time
|
||||||
|
|||||||
@ -30,7 +30,7 @@
|
|||||||
#
|
#
|
||||||
# Your OpenMV Cam supports power of 2 resolutions of 64x32, 64x64,
|
# Your OpenMV Cam supports power of 2 resolutions of 64x32, 64x64,
|
||||||
# 128x64, and 128x128. If you want a resolution of 32x32 you can create
|
# 128x64, and 128x128. If you want a resolution of 32x32 you can create
|
||||||
# it by doing "img.pool(2, 2)" on a 64x64 image.
|
# it by doing "img.scale(x_scale=0.5, y_scale=0.5, hint=image.AREA)" on a 64x64 image.
|
||||||
|
|
||||||
import sensor
|
import sensor
|
||||||
import time
|
import time
|
||||||
|
|||||||
@ -30,7 +30,7 @@
|
|||||||
#
|
#
|
||||||
# Your OpenMV Cam supports power of 2 resolutions of 64x32, 64x64,
|
# Your OpenMV Cam supports power of 2 resolutions of 64x32, 64x64,
|
||||||
# 128x64, and 128x128. If you want a resolution of 32x32 you can create
|
# 128x64, and 128x128. If you want a resolution of 32x32 you can create
|
||||||
# it by doing "img.pool(2, 2)" on a 64x64 image.
|
# it by doing "img.scale(x_scale=0.5, y_scale=0.5, hint=image.AREA)" on a 64x64 image.
|
||||||
import sensor
|
import sensor
|
||||||
import time
|
import time
|
||||||
import math
|
import math
|
||||||
|
|||||||
@ -30,7 +30,7 @@
|
|||||||
#
|
#
|
||||||
# Your OpenMV Cam supports power of 2 resolutions of 64x32, 64x64,
|
# Your OpenMV Cam supports power of 2 resolutions of 64x32, 64x64,
|
||||||
# 128x64, and 128x128. If you want a resolution of 32x32 you can create
|
# 128x64, and 128x128. If you want a resolution of 32x32 you can create
|
||||||
# it by doing "img.pool(2, 2)" on a 64x64 image.
|
# it by doing "img.scale(x_scale=0.5, y_scale=0.5, hint=image.AREA)" on a 64x64 image.
|
||||||
import sensor
|
import sensor
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
|||||||
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
import sensor
|
import sensor
|
||||||
import time
|
import time
|
||||||
|
import image
|
||||||
|
|
||||||
sensor.reset()
|
sensor.reset()
|
||||||
sensor.set_pixformat(sensor.RGB565) # or GRAYSCALE...
|
sensor.set_pixformat(sensor.RGB565) # or GRAYSCALE...
|
||||||
@ -19,7 +20,7 @@ while True:
|
|||||||
clock.tick()
|
clock.tick()
|
||||||
|
|
||||||
img = sensor.snapshot()
|
img = sensor.snapshot()
|
||||||
small_img = img.mean_pooled(4, 4) # Makes a copy.
|
small_img = img.scale(x_scale=0.25, y_scale=0.25, hint=image.AREA, copy=True)
|
||||||
|
|
||||||
x = (img.width() // 2) - (small_img.width() // 2)
|
x = (img.width() // 2) - (small_img.width() // 2)
|
||||||
y = (img.height() // 2) - (small_img.height() // 2)
|
y = (img.height() // 2) - (small_img.height() // 2)
|
||||||
|
|||||||
@ -55,7 +55,9 @@ while True:
|
|||||||
|
|
||||||
img = sensor.snapshot()
|
img = sensor.snapshot()
|
||||||
# Makes a scaled copy of the sensor
|
# Makes a scaled copy of the sensor
|
||||||
small_img = img.mean_pooled(SMALL_IMAGE_SCALE, SMALL_IMAGE_SCALE)
|
small_img = img.scale(x_scale=1.0 / SMALL_IMAGE_SCALE,
|
||||||
|
y_scale=1.0 / SMALL_IMAGE_SCALE,
|
||||||
|
hint=image.AREA, copy=True)
|
||||||
|
|
||||||
status = "rgb565 "
|
status = "rgb565 "
|
||||||
if CYCLE_FORMATS:
|
if CYCLE_FORMATS:
|
||||||
|
|||||||
@ -90,7 +90,6 @@ SRCS += $(addprefix imlib/, \
|
|||||||
orb.c \
|
orb.c \
|
||||||
phasecorrelation.c \
|
phasecorrelation.c \
|
||||||
point.c \
|
point.c \
|
||||||
pool.c \
|
|
||||||
ppm.c \
|
ppm.c \
|
||||||
qrcode.c \
|
qrcode.c \
|
||||||
qsort.c \
|
qsort.c \
|
||||||
|
|||||||
@ -23,12 +23,6 @@
|
|||||||
// Enable YUV LUT
|
// Enable YUV LUT
|
||||||
//#define IMLIB_ENABLE_YUV_LUT
|
//#define IMLIB_ENABLE_YUV_LUT
|
||||||
|
|
||||||
// Enable mean pooling
|
|
||||||
#define IMLIB_ENABLE_MEAN_POOLING
|
|
||||||
|
|
||||||
// Enable midpoint pooling
|
|
||||||
#define IMLIB_ENABLE_MIDPOINT_POOLING
|
|
||||||
|
|
||||||
// Enable ISP ops
|
// Enable ISP ops
|
||||||
#define IMLIB_ENABLE_ISP_OPS
|
#define IMLIB_ENABLE_ISP_OPS
|
||||||
|
|
||||||
|
|||||||
@ -24,12 +24,6 @@
|
|||||||
// Enable YUV LUT
|
// Enable YUV LUT
|
||||||
//#define IMLIB_ENABLE_YUV_LUT
|
//#define IMLIB_ENABLE_YUV_LUT
|
||||||
|
|
||||||
// Enable mean pooling
|
|
||||||
//#define IMLIB_ENABLE_MEAN_POOLING
|
|
||||||
|
|
||||||
// Enable midpoint pooling
|
|
||||||
//#define IMLIB_ENABLE_MIDPOINT_POOLING
|
|
||||||
|
|
||||||
// Enable ISP ops
|
// Enable ISP ops
|
||||||
//#define IMLIB_ENABLE_ISP_OPS
|
//#define IMLIB_ENABLE_ISP_OPS
|
||||||
|
|
||||||
|
|||||||
@ -23,12 +23,6 @@
|
|||||||
// Enable YUV LUT
|
// Enable YUV LUT
|
||||||
//#define IMLIB_ENABLE_YUV_LUT
|
//#define IMLIB_ENABLE_YUV_LUT
|
||||||
|
|
||||||
// Enable mean pooling
|
|
||||||
//#define IMLIB_ENABLE_MEAN_POOLING
|
|
||||||
|
|
||||||
// Enable midpoint pooling
|
|
||||||
//#define IMLIB_ENABLE_MIDPOINT_POOLING
|
|
||||||
|
|
||||||
// Enable ISP ops
|
// Enable ISP ops
|
||||||
//#define IMLIB_ENABLE_ISP_OPS
|
//#define IMLIB_ENABLE_ISP_OPS
|
||||||
|
|
||||||
|
|||||||
@ -23,12 +23,6 @@
|
|||||||
// Enable YUV LUT
|
// Enable YUV LUT
|
||||||
//#define IMLIB_ENABLE_YUV_LUT
|
//#define IMLIB_ENABLE_YUV_LUT
|
||||||
|
|
||||||
// Enable mean pooling
|
|
||||||
#define IMLIB_ENABLE_MEAN_POOLING
|
|
||||||
|
|
||||||
// Enable midpoint pooling
|
|
||||||
#define IMLIB_ENABLE_MIDPOINT_POOLING
|
|
||||||
|
|
||||||
// Enable ISP ops
|
// Enable ISP ops
|
||||||
#define IMLIB_ENABLE_ISP_OPS
|
#define IMLIB_ENABLE_ISP_OPS
|
||||||
|
|
||||||
|
|||||||
@ -23,12 +23,6 @@
|
|||||||
// Enable YUV LUT
|
// Enable YUV LUT
|
||||||
//#define IMLIB_ENABLE_YUV_LUT
|
//#define IMLIB_ENABLE_YUV_LUT
|
||||||
|
|
||||||
// Enable mean pooling
|
|
||||||
#define IMLIB_ENABLE_MEAN_POOLING
|
|
||||||
|
|
||||||
// Enable midpoint pooling
|
|
||||||
#define IMLIB_ENABLE_MIDPOINT_POOLING
|
|
||||||
|
|
||||||
// Enable ISP ops
|
// Enable ISP ops
|
||||||
#define IMLIB_ENABLE_ISP_OPS
|
#define IMLIB_ENABLE_ISP_OPS
|
||||||
|
|
||||||
|
|||||||
@ -23,12 +23,6 @@
|
|||||||
// Enable YUV LUT
|
// Enable YUV LUT
|
||||||
//#define IMLIB_ENABLE_YUV_LUT
|
//#define IMLIB_ENABLE_YUV_LUT
|
||||||
|
|
||||||
// Enable mean pooling
|
|
||||||
#define IMLIB_ENABLE_MEAN_POOLING
|
|
||||||
|
|
||||||
// Enable midpoint pooling
|
|
||||||
#define IMLIB_ENABLE_MIDPOINT_POOLING
|
|
||||||
|
|
||||||
// Enable ISP ops
|
// Enable ISP ops
|
||||||
#define IMLIB_ENABLE_ISP_OPS
|
#define IMLIB_ENABLE_ISP_OPS
|
||||||
|
|
||||||
|
|||||||
@ -23,12 +23,6 @@
|
|||||||
// Enable YUV LUT
|
// Enable YUV LUT
|
||||||
//#define IMLIB_ENABLE_YUV_LUT
|
//#define IMLIB_ENABLE_YUV_LUT
|
||||||
|
|
||||||
// Enable mean pooling
|
|
||||||
#define IMLIB_ENABLE_MEAN_POOLING
|
|
||||||
|
|
||||||
// Enable midpoint pooling
|
|
||||||
#define IMLIB_ENABLE_MIDPOINT_POOLING
|
|
||||||
|
|
||||||
// Enable ISP ops
|
// Enable ISP ops
|
||||||
#define IMLIB_ENABLE_ISP_OPS
|
#define IMLIB_ENABLE_ISP_OPS
|
||||||
|
|
||||||
|
|||||||
@ -23,12 +23,6 @@
|
|||||||
// Enable YUV LUT
|
// Enable YUV LUT
|
||||||
//#define IMLIB_ENABLE_YUV_LUT
|
//#define IMLIB_ENABLE_YUV_LUT
|
||||||
|
|
||||||
// Enable mean pooling
|
|
||||||
#define IMLIB_ENABLE_MEAN_POOLING
|
|
||||||
|
|
||||||
// Enable midpoint pooling
|
|
||||||
#define IMLIB_ENABLE_MIDPOINT_POOLING
|
|
||||||
|
|
||||||
// Enable ISP ops
|
// Enable ISP ops
|
||||||
#define IMLIB_ENABLE_ISP_OPS
|
#define IMLIB_ENABLE_ISP_OPS
|
||||||
|
|
||||||
|
|||||||
@ -23,12 +23,6 @@
|
|||||||
// Enable YUV LUT
|
// Enable YUV LUT
|
||||||
//#define IMLIB_ENABLE_YUV_LUT
|
//#define IMLIB_ENABLE_YUV_LUT
|
||||||
|
|
||||||
// Enable mean pooling
|
|
||||||
#define IMLIB_ENABLE_MEAN_POOLING
|
|
||||||
|
|
||||||
// Enable midpoint pooling
|
|
||||||
#define IMLIB_ENABLE_MIDPOINT_POOLING
|
|
||||||
|
|
||||||
// Enable ISP ops
|
// Enable ISP ops
|
||||||
#define IMLIB_ENABLE_ISP_OPS
|
#define IMLIB_ENABLE_ISP_OPS
|
||||||
|
|
||||||
|
|||||||
@ -23,12 +23,6 @@
|
|||||||
// Enable YUV LUT
|
// Enable YUV LUT
|
||||||
//#define IMLIB_ENABLE_YUV_LUT
|
//#define IMLIB_ENABLE_YUV_LUT
|
||||||
|
|
||||||
// Enable mean pooling
|
|
||||||
#define IMLIB_ENABLE_MEAN_POOLING
|
|
||||||
|
|
||||||
// Enable midpoint pooling
|
|
||||||
#define IMLIB_ENABLE_MIDPOINT_POOLING
|
|
||||||
|
|
||||||
// Enable ISP ops
|
// Enable ISP ops
|
||||||
#define IMLIB_ENABLE_ISP_OPS
|
#define IMLIB_ENABLE_ISP_OPS
|
||||||
|
|
||||||
|
|||||||
@ -23,12 +23,6 @@
|
|||||||
// Enable YUV LUT
|
// Enable YUV LUT
|
||||||
//#define IMLIB_ENABLE_YUV_LUT
|
//#define IMLIB_ENABLE_YUV_LUT
|
||||||
|
|
||||||
// Enable mean pooling
|
|
||||||
#define IMLIB_ENABLE_MEAN_POOLING
|
|
||||||
|
|
||||||
// Enable midpoint pooling
|
|
||||||
#define IMLIB_ENABLE_MIDPOINT_POOLING
|
|
||||||
|
|
||||||
// Enable ISP ops
|
// Enable ISP ops
|
||||||
#define IMLIB_ENABLE_ISP_OPS
|
#define IMLIB_ENABLE_ISP_OPS
|
||||||
|
|
||||||
|
|||||||
@ -22,12 +22,6 @@
|
|||||||
// Enable YUV LUT
|
// Enable YUV LUT
|
||||||
//#define IMLIB_ENABLE_YUV_LUT
|
//#define IMLIB_ENABLE_YUV_LUT
|
||||||
|
|
||||||
// Enable mean pooling
|
|
||||||
#define IMLIB_ENABLE_MEAN_POOLING
|
|
||||||
|
|
||||||
// Enable midpoint pooling
|
|
||||||
#define IMLIB_ENABLE_MIDPOINT_POOLING
|
|
||||||
|
|
||||||
// Enable ISP ops
|
// Enable ISP ops
|
||||||
#define IMLIB_ENABLE_ISP_OPS
|
#define IMLIB_ENABLE_ISP_OPS
|
||||||
|
|
||||||
|
|||||||
@ -24,12 +24,6 @@
|
|||||||
// Enable YUV LUT
|
// Enable YUV LUT
|
||||||
//#define IMLIB_ENABLE_YUV_LUT
|
//#define IMLIB_ENABLE_YUV_LUT
|
||||||
|
|
||||||
// Enable mean pooling
|
|
||||||
//#define IMLIB_ENABLE_MEAN_POOLING
|
|
||||||
|
|
||||||
// Enable midpoint pooling
|
|
||||||
//#define IMLIB_ENABLE_MIDPOINT_POOLING
|
|
||||||
|
|
||||||
// Enable ISP ops
|
// Enable ISP ops
|
||||||
//#define IMLIB_ENABLE_ISP_OPS
|
//#define IMLIB_ENABLE_ISP_OPS
|
||||||
|
|
||||||
|
|||||||
@ -1,149 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of the OpenMV project.
|
|
||||||
* Copyright (c) 2013-2016 Kwabena W. Agyeman <kwagyeman@openmv.io>
|
|
||||||
* This work is licensed under the MIT license, see the file LICENSE for details.
|
|
||||||
*
|
|
||||||
* Image pooling.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
#include "imlib.h"
|
|
||||||
|
|
||||||
#ifdef IMLIB_ENABLE_MIDPOINT_POOLING
|
|
||||||
void imlib_midpoint_pool(image_t *img_i, image_t *img_o, int x_div, int y_div, const int bias) {
|
|
||||||
int min_bias = (256 - bias);
|
|
||||||
int max_bias = bias;
|
|
||||||
switch (img_i->pixfmt) {
|
|
||||||
case PIXFORMAT_BINARY: {
|
|
||||||
for (int y = 0, yy = img_i->h / y_div, yyy = (img_i->h % y_div) / 2; y < yy; y++) {
|
|
||||||
uint32_t *row_ptr = IMAGE_COMPUTE_BINARY_PIXEL_ROW_PTR(img_o, y);
|
|
||||||
for (int x = 0, xx = img_i->w / x_div, xxx = (img_i->w % x_div) / 2; x < xx; x++) {
|
|
||||||
int min = COLOR_BINARY_MAX, max = COLOR_BINARY_MIN;
|
|
||||||
for (int i = 0; i < y_div; i++) {
|
|
||||||
for (int j = 0; j < x_div; j++) {
|
|
||||||
int pixel = IMAGE_GET_BINARY_PIXEL(img_i, xxx + (x * x_div) + j, yyy + (y * y_div) + i);
|
|
||||||
min = IM_MIN(min, pixel);
|
|
||||||
max = IM_MAX(max, pixel);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
IMAGE_PUT_BINARY_PIXEL_FAST(row_ptr, x,
|
|
||||||
((min * min_bias) + (max * max_bias)) >> 8);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case PIXFORMAT_GRAYSCALE: {
|
|
||||||
for (int y = 0, yy = img_i->h, yyy = (img_i->h % y_div) / 2; y < yy; y++) {
|
|
||||||
uint8_t *row_ptr = IMAGE_COMPUTE_GRAYSCALE_PIXEL_ROW_PTR(img_o, y);
|
|
||||||
for (int x = 0, xx = img_i->w / x_div, xxx = (img_i->w % x_div) / 2; x < xx; x++) {
|
|
||||||
int min = COLOR_GRAYSCALE_MAX, max = COLOR_GRAYSCALE_MIN;
|
|
||||||
for (int i = 0; i < y_div; i++) {
|
|
||||||
for (int j = 0; j < x_div; j++) {
|
|
||||||
int pixel = IMAGE_GET_GRAYSCALE_PIXEL(img_i, xxx + (x * x_div) + j, yyy + (y * y_div) + i);
|
|
||||||
min = IM_MIN(min, pixel);
|
|
||||||
max = IM_MAX(max, pixel);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
IMAGE_PUT_GRAYSCALE_PIXEL_FAST(row_ptr, x,
|
|
||||||
((min * min_bias) + (max * max_bias)) >> 8);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case PIXFORMAT_RGB565: {
|
|
||||||
for (int y = 0, yy = img_i->h / y_div, yyy = (img_i->h % y_div) / 2; y < yy; y++) {
|
|
||||||
uint16_t *row_ptr = IMAGE_COMPUTE_RGB565_PIXEL_ROW_PTR(img_o, y);
|
|
||||||
for (int x = 0, xx = img_i->w / x_div, xxx = (img_i->w % x_div) / 2; x < xx; x++) {
|
|
||||||
int r_min = COLOR_R5_MAX, r_max = COLOR_R5_MIN;
|
|
||||||
int g_min = COLOR_G6_MAX, g_max = COLOR_G6_MIN;
|
|
||||||
int b_min = COLOR_B5_MAX, b_max = COLOR_B5_MIN;
|
|
||||||
for (int i = 0; i < y_div; i++) {
|
|
||||||
for (int j = 0; j < x_div; j++) {
|
|
||||||
const uint16_t pixel = IM_GET_RGB565_PIXEL(img_i, xxx + (x * x_div) + j, yyy + (y * y_div) + i);
|
|
||||||
int r = COLOR_RGB565_TO_R5(pixel);
|
|
||||||
int g = COLOR_RGB565_TO_G6(pixel);
|
|
||||||
int b = COLOR_RGB565_TO_B5(pixel);
|
|
||||||
r_min = IM_MIN(r_min, r);
|
|
||||||
r_max = IM_MAX(r_max, r);
|
|
||||||
g_min = IM_MIN(g_min, g);
|
|
||||||
g_max = IM_MAX(g_max, g);
|
|
||||||
b_min = IM_MIN(b_min, b);
|
|
||||||
b_max = IM_MAX(b_max, b);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
IMAGE_PUT_RGB565_PIXEL_FAST(row_ptr, x,
|
|
||||||
COLOR_R5_G6_B5_TO_RGB565(((r_min * min_bias) + (r_max * max_bias)) >> 8,
|
|
||||||
((g_min * min_bias) + (g_max * max_bias)) >> 8,
|
|
||||||
((b_min * min_bias) + (b_max * max_bias)) >> 8));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default: {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif // IMLIB_ENABLE_MIDPOINT_POOLING
|
|
||||||
|
|
||||||
#ifdef IMLIB_ENABLE_MEAN_POOLING
|
|
||||||
void imlib_mean_pool(image_t *img_i, image_t *img_o, int x_div, int y_div) {
|
|
||||||
int n = x_div * y_div;
|
|
||||||
switch (img_i->pixfmt) {
|
|
||||||
case PIXFORMAT_BINARY: {
|
|
||||||
for (int y = 0, yy = img_i->h / y_div, yyy = (img_i->h % y_div) / 2; y < yy; y++) {
|
|
||||||
uint32_t *row_ptr = IMAGE_COMPUTE_BINARY_PIXEL_ROW_PTR(img_o, y);
|
|
||||||
for (int x = 0, xx = img_i->w / x_div, xxx = (img_i->w % x_div) / 2; x < xx; x++) {
|
|
||||||
int acc = 0;
|
|
||||||
for (int i = 0; i < y_div; i++) {
|
|
||||||
for (int j = 0; j < x_div; j++) {
|
|
||||||
int pixel = IMAGE_GET_BINARY_PIXEL(img_i, xxx + (x * x_div) + j, yyy + (y * y_div) + i);
|
|
||||||
acc += pixel;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
IMAGE_PUT_BINARY_PIXEL_FAST(row_ptr, x, acc / n);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case PIXFORMAT_GRAYSCALE: {
|
|
||||||
for (int y = 0, yy = img_i->h / y_div, yyy = (img_i->h % y_div) / 2; y < yy; y++) {
|
|
||||||
uint8_t *row_ptr = IMAGE_COMPUTE_GRAYSCALE_PIXEL_ROW_PTR(img_o, y);
|
|
||||||
for (int x = 0, xx = img_i->w / x_div, xxx = (img_i->w % x_div) / 2; x < xx; x++) {
|
|
||||||
int acc = 0;
|
|
||||||
for (int i = 0; i < y_div; i++) {
|
|
||||||
for (int j = 0; j < x_div; j++) {
|
|
||||||
int pixel = IMAGE_GET_GRAYSCALE_PIXEL(img_i, xxx + (x * x_div) + j, yyy + (y * y_div) + i);
|
|
||||||
acc += pixel;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
IMAGE_PUT_GRAYSCALE_PIXEL_FAST(row_ptr, x, acc / n);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case PIXFORMAT_RGB565: {
|
|
||||||
for (int y = 0, yy = img_i->h / y_div, yyy = (img_i->h % y_div) / 2; y < yy; y++) {
|
|
||||||
uint16_t *row_ptr = IMAGE_COMPUTE_RGB565_PIXEL_ROW_PTR(img_o, y);
|
|
||||||
for (int x = 0, xx = img_i->w / x_div, xxx = (img_i->w % x_div) / 2; x < xx; x++) {
|
|
||||||
int r_acc = 0;
|
|
||||||
int g_acc = 0;
|
|
||||||
int b_acc = 0;
|
|
||||||
for (int i = 0; i < y_div; i++) {
|
|
||||||
for (int j = 0; j < x_div; j++) {
|
|
||||||
int pixel = IMAGE_GET_RGB565_PIXEL(img_i, xxx + (x * x_div) + j, yyy + (y * y_div) + i);
|
|
||||||
r_acc += COLOR_RGB565_TO_R5(pixel);
|
|
||||||
g_acc += COLOR_RGB565_TO_G6(pixel);
|
|
||||||
b_acc += COLOR_RGB565_TO_B5(pixel);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
IMAGE_PUT_RGB565_PIXEL_FAST(row_ptr, x, COLOR_R5_G6_B5_TO_RGB565(r_acc / n, g_acc / n, b_acc / n));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default: {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif // IMLIB_ENABLE_MEAN_POOLING
|
|
||||||
@ -840,108 +840,6 @@ STATIC mp_obj_t py_image_set_pixel(uint n_args, const mp_obj_t *args, mp_map_t *
|
|||||||
}
|
}
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(py_image_set_pixel_obj, 2, py_image_set_pixel);
|
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(py_image_set_pixel_obj, 2, py_image_set_pixel);
|
||||||
|
|
||||||
#ifdef IMLIB_ENABLE_MEAN_POOLING
|
|
||||||
static mp_obj_t py_image_mean_pool(mp_obj_t img_obj, mp_obj_t x_div_obj, mp_obj_t y_div_obj) {
|
|
||||||
image_t *arg_img = py_helper_arg_to_image(img_obj, ARG_IMAGE_MUTABLE);
|
|
||||||
|
|
||||||
int arg_x_div = mp_obj_get_int(x_div_obj);
|
|
||||||
PY_ASSERT_TRUE_MSG(arg_x_div >= 1, "Width divisor must be greater than >= 1");
|
|
||||||
PY_ASSERT_TRUE_MSG(arg_x_div <= arg_img->w, "Width divisor must be less than <= img width");
|
|
||||||
int arg_y_div = mp_obj_get_int(y_div_obj);
|
|
||||||
PY_ASSERT_TRUE_MSG(arg_y_div >= 1, "Height divisor must be greater than >= 1");
|
|
||||||
PY_ASSERT_TRUE_MSG(arg_y_div <= arg_img->h, "Height divisor must be less than <= img height");
|
|
||||||
|
|
||||||
image_t out_img;
|
|
||||||
out_img.w = arg_img->w / arg_x_div;
|
|
||||||
out_img.h = arg_img->h / arg_y_div;
|
|
||||||
out_img.pixfmt = arg_img->pixfmt;
|
|
||||||
out_img.pixels = arg_img->pixels;
|
|
||||||
PY_ASSERT_TRUE_MSG(image_size(&out_img) <= image_size(arg_img), "Can't pool in place!");
|
|
||||||
|
|
||||||
imlib_mean_pool(arg_img, &out_img, arg_x_div, arg_y_div);
|
|
||||||
arg_img->w = out_img.w;
|
|
||||||
arg_img->h = out_img.h;
|
|
||||||
py_helper_update_framebuffer(arg_img);
|
|
||||||
return img_obj;
|
|
||||||
}
|
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(py_image_mean_pool_obj, py_image_mean_pool);
|
|
||||||
|
|
||||||
static mp_obj_t py_image_mean_pooled(mp_obj_t img_obj, mp_obj_t x_div_obj, mp_obj_t y_div_obj) {
|
|
||||||
image_t *arg_img = py_helper_arg_to_image(img_obj, ARG_IMAGE_MUTABLE);
|
|
||||||
|
|
||||||
int arg_x_div = mp_obj_get_int(x_div_obj);
|
|
||||||
PY_ASSERT_TRUE_MSG(arg_x_div >= 1, "Width divisor must be greater than >= 1");
|
|
||||||
PY_ASSERT_TRUE_MSG(arg_x_div <= arg_img->w, "Width divisor must be less than <= img width");
|
|
||||||
int arg_y_div = mp_obj_get_int(y_div_obj);
|
|
||||||
PY_ASSERT_TRUE_MSG(arg_y_div >= 1, "Height divisor must be greater than >= 1");
|
|
||||||
PY_ASSERT_TRUE_MSG(arg_y_div <= arg_img->h, "Height divisor must be less than <= img height");
|
|
||||||
|
|
||||||
image_t out_img;
|
|
||||||
out_img.w = arg_img->w / arg_x_div;
|
|
||||||
out_img.h = arg_img->h / arg_y_div;
|
|
||||||
out_img.pixfmt = arg_img->pixfmt;
|
|
||||||
out_img.pixels = xalloc(image_size(&out_img));
|
|
||||||
|
|
||||||
imlib_mean_pool(arg_img, &out_img, arg_x_div, arg_y_div);
|
|
||||||
return py_image_from_struct(&out_img);
|
|
||||||
}
|
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_3(py_image_mean_pooled_obj, py_image_mean_pooled);
|
|
||||||
#endif // IMLIB_ENABLE_MEAN_POOLING
|
|
||||||
|
|
||||||
#ifdef IMLIB_ENABLE_MIDPOINT_POOLING
|
|
||||||
static mp_obj_t py_image_midpoint_pool(uint n_args, const mp_obj_t *args, mp_map_t *kw_args) {
|
|
||||||
image_t *arg_img = py_helper_arg_to_image(args[0], ARG_IMAGE_MUTABLE);
|
|
||||||
|
|
||||||
int arg_x_div = mp_obj_get_int(args[1]);
|
|
||||||
PY_ASSERT_TRUE_MSG(arg_x_div >= 1, "Width divisor must be greater than >= 1");
|
|
||||||
PY_ASSERT_TRUE_MSG(arg_x_div <= arg_img->w, "Width divisor must be less than <= img width");
|
|
||||||
int arg_y_div = mp_obj_get_int(args[2]);
|
|
||||||
PY_ASSERT_TRUE_MSG(arg_y_div >= 1, "Height divisor must be greater than >= 1");
|
|
||||||
PY_ASSERT_TRUE_MSG(arg_y_div <= arg_img->h, "Height divisor must be less than <= img height");
|
|
||||||
|
|
||||||
int arg_bias = py_helper_keyword_float(n_args, args, 3, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_bias), 0.5) * 256;
|
|
||||||
PY_ASSERT_TRUE_MSG((0 <= arg_bias) && (arg_bias <= 256), "Error: 0 <= bias <= 1!");
|
|
||||||
|
|
||||||
image_t out_img;
|
|
||||||
out_img.w = arg_img->w / arg_x_div;
|
|
||||||
out_img.h = arg_img->h / arg_y_div;
|
|
||||||
out_img.pixfmt = arg_img->pixfmt;
|
|
||||||
out_img.pixels = arg_img->pixels;
|
|
||||||
PY_ASSERT_TRUE_MSG(image_size(&out_img) <= image_size(arg_img), "Can't pool in place!");
|
|
||||||
|
|
||||||
imlib_midpoint_pool(arg_img, &out_img, arg_x_div, arg_y_div, arg_bias);
|
|
||||||
arg_img->w = out_img.w;
|
|
||||||
arg_img->h = out_img.h;
|
|
||||||
py_helper_update_framebuffer(arg_img);
|
|
||||||
return args[0];
|
|
||||||
}
|
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(py_image_midpoint_pool_obj, 3, py_image_midpoint_pool);
|
|
||||||
|
|
||||||
static mp_obj_t py_image_midpoint_pooled(uint n_args, const mp_obj_t *args, mp_map_t *kw_args) {
|
|
||||||
image_t *arg_img = py_helper_arg_to_image(args[0], ARG_IMAGE_MUTABLE);
|
|
||||||
|
|
||||||
int arg_x_div = mp_obj_get_int(args[1]);
|
|
||||||
PY_ASSERT_TRUE_MSG(arg_x_div >= 1, "Width divisor must be greater than >= 1");
|
|
||||||
PY_ASSERT_TRUE_MSG(arg_x_div <= arg_img->w, "Width divisor must be less than <= img width");
|
|
||||||
int arg_y_div = mp_obj_get_int(args[2]);
|
|
||||||
PY_ASSERT_TRUE_MSG(arg_y_div >= 1, "Height divisor must be greater than >= 1");
|
|
||||||
PY_ASSERT_TRUE_MSG(arg_y_div <= arg_img->h, "Height divisor must be less than <= img height");
|
|
||||||
|
|
||||||
int arg_bias = py_helper_keyword_float(n_args, args, 3, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_bias), 0.5) * 256;
|
|
||||||
PY_ASSERT_TRUE_MSG((0 <= arg_bias) && (arg_bias <= 256), "Error: 0 <= bias <= 1!");
|
|
||||||
|
|
||||||
image_t out_img;
|
|
||||||
out_img.w = arg_img->w / arg_x_div;
|
|
||||||
out_img.h = arg_img->h / arg_y_div;
|
|
||||||
out_img.pixfmt = arg_img->pixfmt;
|
|
||||||
out_img.pixels = xalloc(image_size(&out_img));
|
|
||||||
|
|
||||||
imlib_midpoint_pool(arg_img, &out_img, arg_x_div, arg_y_div, arg_bias);
|
|
||||||
return py_image_from_struct(&out_img);
|
|
||||||
}
|
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(py_image_midpoint_pooled_obj, 3, py_image_midpoint_pooled);
|
|
||||||
#endif // IMLIB_ENABLE_MIDPOINT_POOLING
|
|
||||||
|
|
||||||
static mp_obj_t py_image_to(pixformat_t pixfmt, mp_rom_obj_t default_color_palette, bool default_copy,
|
static mp_obj_t py_image_to(pixformat_t pixfmt, mp_rom_obj_t default_color_palette, bool default_copy,
|
||||||
uint n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
uint n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||||
enum {
|
enum {
|
||||||
@ -6271,20 +6169,6 @@ static const mp_rom_map_elem_t locals_dict_table[] = {
|
|||||||
{MP_ROM_QSTR(MP_QSTR_bytearray), MP_ROM_PTR(&py_image_bytearray_obj)},
|
{MP_ROM_QSTR(MP_QSTR_bytearray), MP_ROM_PTR(&py_image_bytearray_obj)},
|
||||||
{MP_ROM_QSTR(MP_QSTR_get_pixel), MP_ROM_PTR(&py_image_get_pixel_obj)},
|
{MP_ROM_QSTR(MP_QSTR_get_pixel), MP_ROM_PTR(&py_image_get_pixel_obj)},
|
||||||
{MP_ROM_QSTR(MP_QSTR_set_pixel), MP_ROM_PTR(&py_image_set_pixel_obj)},
|
{MP_ROM_QSTR(MP_QSTR_set_pixel), MP_ROM_PTR(&py_image_set_pixel_obj)},
|
||||||
#ifdef IMLIB_ENABLE_MEAN_POOLING
|
|
||||||
{MP_ROM_QSTR(MP_QSTR_mean_pool), MP_ROM_PTR(&py_image_mean_pool_obj)},
|
|
||||||
{MP_ROM_QSTR(MP_QSTR_mean_pooled), MP_ROM_PTR(&py_image_mean_pooled_obj)},
|
|
||||||
#else
|
|
||||||
{MP_ROM_QSTR(MP_QSTR_mean_pool), MP_ROM_PTR(&py_func_unavailable_obj)},
|
|
||||||
{MP_ROM_QSTR(MP_QSTR_mean_pooled), MP_ROM_PTR(&py_func_unavailable_obj)},
|
|
||||||
#endif
|
|
||||||
#ifdef IMLIB_ENABLE_MIDPOINT_POOLING
|
|
||||||
{MP_ROM_QSTR(MP_QSTR_midpoint_pool), MP_ROM_PTR(&py_image_midpoint_pool_obj)},
|
|
||||||
{MP_ROM_QSTR(MP_QSTR_midpoint_pooled), MP_ROM_PTR(&py_image_midpoint_pooled_obj)},
|
|
||||||
#else
|
|
||||||
{MP_ROM_QSTR(MP_QSTR_midpoint_pool), MP_ROM_PTR(&py_func_unavailable_obj)},
|
|
||||||
{MP_ROM_QSTR(MP_QSTR_midpoint_pooled), MP_ROM_PTR(&py_func_unavailable_obj)},
|
|
||||||
#endif
|
|
||||||
{MP_ROM_QSTR(MP_QSTR_to_bitmap), MP_ROM_PTR(&py_image_to_bitmap_obj)},
|
{MP_ROM_QSTR(MP_QSTR_to_bitmap), MP_ROM_PTR(&py_image_to_bitmap_obj)},
|
||||||
{MP_ROM_QSTR(MP_QSTR_to_grayscale), MP_ROM_PTR(&py_image_to_grayscale_obj)},
|
{MP_ROM_QSTR(MP_QSTR_to_grayscale), MP_ROM_PTR(&py_image_to_grayscale_obj)},
|
||||||
{MP_ROM_QSTR(MP_QSTR_to_rgb565), MP_ROM_PTR(&py_image_to_rgb565_obj)},
|
{MP_ROM_QSTR(MP_QSTR_to_rgb565), MP_ROM_PTR(&py_image_to_rgb565_obj)},
|
||||||
|
|||||||
@ -203,7 +203,6 @@ FIRM_OBJ += $(addprefix $(BUILD)/$(OMV_DIR)/imlib/, \
|
|||||||
orb.o \
|
orb.o \
|
||||||
phasecorrelation.o \
|
phasecorrelation.o \
|
||||||
point.o \
|
point.o \
|
||||||
pool.o \
|
|
||||||
ppm.o \
|
ppm.o \
|
||||||
qrcode.o \
|
qrcode.o \
|
||||||
qsort.o \
|
qsort.o \
|
||||||
|
|||||||
@ -169,7 +169,6 @@ FIRM_OBJ += $(addprefix $(BUILD)/$(OMV_DIR)/imlib/, \
|
|||||||
orb.o \
|
orb.o \
|
||||||
phasecorrelation.o \
|
phasecorrelation.o \
|
||||||
point.o \
|
point.o \
|
||||||
pool.o \
|
|
||||||
ppm.o \
|
ppm.o \
|
||||||
qrcode.o \
|
qrcode.o \
|
||||||
qsort.o \
|
qsort.o \
|
||||||
|
|||||||
@ -162,7 +162,6 @@ target_sources(${MICROPY_TARGET} PRIVATE
|
|||||||
${TOP_DIR}/${OMV_DIR}/imlib/orb.c
|
${TOP_DIR}/${OMV_DIR}/imlib/orb.c
|
||||||
${TOP_DIR}/${OMV_DIR}/imlib/phasecorrelation.c
|
${TOP_DIR}/${OMV_DIR}/imlib/phasecorrelation.c
|
||||||
${TOP_DIR}/${OMV_DIR}/imlib/point.c
|
${TOP_DIR}/${OMV_DIR}/imlib/point.c
|
||||||
${TOP_DIR}/${OMV_DIR}/imlib/pool.c
|
|
||||||
${TOP_DIR}/${OMV_DIR}/imlib/ppm.c
|
${TOP_DIR}/${OMV_DIR}/imlib/ppm.c
|
||||||
${TOP_DIR}/${OMV_DIR}/imlib/qrcode.c
|
${TOP_DIR}/${OMV_DIR}/imlib/qrcode.c
|
||||||
${TOP_DIR}/${OMV_DIR}/imlib/qsort.c
|
${TOP_DIR}/${OMV_DIR}/imlib/qsort.c
|
||||||
|
|||||||
@ -218,7 +218,6 @@ FIRM_OBJ += $(addprefix $(BUILD)/$(OMV_DIR)/imlib/, \
|
|||||||
orb.o \
|
orb.o \
|
||||||
phasecorrelation.o \
|
phasecorrelation.o \
|
||||||
point.o \
|
point.o \
|
||||||
pool.o \
|
|
||||||
ppm.o \
|
ppm.o \
|
||||||
qrcode.o \
|
qrcode.o \
|
||||||
qsort.o \
|
qsort.o \
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user