Skip to content

Commit 94b8879

Browse files
authored
Optimizations and Cleanup (#42)
* sensor.c optimization permanently remove AI related buffer and functions * disable unused image processing code * enable grayscale mode on GC2145 sensor
1 parent eae432e commit 94b8879

12 files changed

Lines changed: 114 additions & 1020 deletions

File tree

components/micropython/port/src/omv/boards/MAIX/imlib_config.h

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include "py/mpconfig.h"
1313
#include "global_config.h"
1414

15+
// #define OMV_OPTIONAL_I
16+
// #define OMV_OPTIONAL_II
1517
#if CONFIG_MAIXPY_OMV_MINIMUM
1618

1719
#ifndef CONFIG_MAIXPY_OMV_CONV_YUV_FAST
@@ -66,46 +68,46 @@
6668
#define IMLIB_ENABLE_MODE
6769

6870
// Enable midpoint()
69-
#define IMLIB_ENABLE_MIDPOINT
71+
// #define IMLIB_ENABLE_MIDPOINT
7072

7173
// Enable morph()
72-
#define IMLIB_ENABLE_MORPH
74+
// #define IMLIB_ENABLE_MORPH
7375

7476
// Enable Gaussian
75-
#define IMLIB_ENABLE_GAUSSIAN
77+
// #define IMLIB_ENABLE_GAUSSIAN
7678

7779
// Enable Laplacian
78-
#define IMLIB_ENABLE_LAPLACIAN
80+
// #define IMLIB_ENABLE_LAPLACIAN
7981

8082
// Enable bilateral()
81-
#define IMLIB_ENABLE_BILATERAL
83+
// #define IMLIB_ENABLE_BILATERAL
8284

8385
// Enable cartoon()
84-
#define IMLIB_ENABLE_CARTOON
86+
// #define IMLIB_ENABLE_CARTOON
8587

8688
// Enable remove_shadows()
87-
#define IMLIB_ENABLE_REMOVE_SHADOWS
89+
// #define IMLIB_ENABLE_REMOVE_SHADOWS
8890

8991
// Enable linpolar()
90-
#define IMLIB_ENABLE_LINPOLAR
92+
// #define IMLIB_ENABLE_LINPOLAR
9193

9294
// Enable logpolar()
93-
#define IMLIB_ENABLE_LOGPOLAR
95+
// #define IMLIB_ENABLE_LOGPOLAR
9496

9597
// Enable chrominvar()
96-
#define IMLIB_ENABLE_CHROMINVAR
98+
// #define IMLIB_ENABLE_CHROMINVAR
9799

98100
// Enable illuminvar()
99-
#define IMLIB_ENABLE_ILLUMINVAR
101+
// #define IMLIB_ENABLE_ILLUMINVAR
100102

101103
// Enable invariant table
102104
//#define IMLIB_ENABLE_INVARIANT_TABLE
103105

104106
// Enable rotation_corr()
105-
#define IMLIB_ENABLE_ROTATION_CORR
107+
//#define IMLIB_ENABLE_ROTATION_CORR
106108

107109
// Enable phasecorrelate()
108-
#define IMLIB_ENABLE_FIND_DISPLACEMENT
110+
// #define IMLIB_ENABLE_FIND_DISPLACEMENT
109111

110112
// rotation_corr() is required by phasecorrelate()
111113
#if defined(IMLIB_ENABLE_FIND_DISPLACEMENT)\
@@ -114,13 +116,13 @@
114116
#endif
115117

116118
// Enable get_similarity()
117-
#define IMLIB_ENABLE_GET_SIMILARITY
119+
// #define IMLIB_ENABLE_GET_SIMILARITY
118120

119121
// Enable find_lines()
120-
#define IMLIB_ENABLE_FIND_LINES
122+
// #define IMLIB_ENABLE_FIND_LINES
121123

122124
// Enable find_line_segments()
123-
#define IMLIB_ENABLE_FIND_LINE_SEGMENTS
125+
// #define IMLIB_ENABLE_FIND_LINE_SEGMENTS
124126

125127
// find_lines() is required by the old find_line_segments()
126128
#if defined(IMLIB_ENABLE_FIND_LINE_SEGMENTS)\
@@ -129,39 +131,39 @@
129131
#endif
130132

131133
// Enable find_circles()
132-
#define IMLIB_ENABLE_FIND_CIRCLES
134+
// #define IMLIB_ENABLE_FIND_CIRCLES
133135

134136
// Enable find_rects()
135-
#define IMLIB_ENABLE_FIND_RECTS
137+
// #define IMLIB_ENABLE_FIND_RECTS
136138

137139
// Enable find_qrcodes() (14 KB)
138140
#if CONFIG_MAIXPY_OMV_QRCODES
139141
#define IMLIB_ENABLE_QRCODES
140142
#endif
141143

142144
// Enable find_apriltags() (64 KB)
143-
#define IMLIB_ENABLE_APRILTAGS
145+
// #define IMLIB_ENABLE_APRILTAGS
144146

145147
// Enable find_datamatrices() (26 KB)
146-
#define IMLIB_ENABLE_DATAMATRICES
148+
// #define IMLIB_ENABLE_DATAMATRICES
147149

148150
// Enable find_barcodes() (42 KB)
149-
#define IMLIB_ENABLE_BARCODES
151+
// #define IMLIB_ENABLE_BARCODES
150152

151153
// Enable LENET (200+ KB).
152-
#define IMLIB_ENABLE_LENET
154+
// #define IMLIB_ENABLE_LENET
153155

154156
// Enable CMSIS NN
155-
#define IMLIB_ENABLE_CNN
157+
// #define IMLIB_ENABLE_CNN
156158

157159
// Enable FAST (20+ KBs).
158-
#define IMLIB_ENABLE_FAST
160+
// #define IMLIB_ENABLE_FAST
159161

160162
// Enable find_hog()
161-
#define IMLIB_ENABLE_HOG
163+
// #define IMLIB_ENABLE_HOG
162164

163165
// Enable selective_search()
164-
#define IMLIB_ENABLE_SELECTIVE_SEARCH
166+
// #define IMLIB_ENABLE_SELECTIVE_SEARCH
165167

166168
#ifndef CONFIG_MAIXPY_OMV_CONV_YUV_FAST
167169
#define IMLIB_ENABLE_YUV_LAB_FUNC

components/micropython/port/src/omv/framebuffer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ void fb_update_jpeg_buffer()
8686
src.h=MAIN_FB()->h;
8787
src.bpp=MAIN_FB()->bpp;
8888
#if CONFIG_MAIXPY_OMV_DOUBLE_BUFF
89-
src.pixels=MAIN_FB()->pix_ai[g_sensor_buff_index_out];
89+
src.pixels=MAIN_FB()->pixels[g_sensor_buff_index_out];
9090
#else
91-
src.pixels=MAIN_FB()->pix_ai;
91+
src.pixels=MAIN_FB()->pixels;
9292
#endif
9393
}
9494
else

components/micropython/port/src/omv/gc2145.c

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,47 @@ static int gc2145_write_reg(sensor_t *sensor, uint8_t reg_addr, uint16_t reg_dat
6363
return cambus_writeb(sensor->slv_addr, reg_addr, (uint8_t)reg_data);
6464
}
6565

66+
static int set_reg_bits(uint8_t slv_addr, uint8_t reg_addr, uint8_t mask, uint8_t shift, uint8_t value)
67+
{
68+
uint8_t reg_data;
69+
if (cambus_readb(slv_addr, reg_addr, &reg_data) != 0) {
70+
return -1;
71+
}
72+
reg_data &= ~(mask << shift);
73+
reg_data |= ((value & mask) << shift);
74+
return cambus_writeb(slv_addr, reg_addr, reg_data);
75+
}
76+
6677
static int gc2145_set_pixformat(sensor_t *sensor, pixformat_t pixformat)
6778
{
68-
// TODO:
69-
return 0;
79+
int ret = 0;
80+
81+
// Switch to page 0
82+
ret |= cambus_writeb(sensor->slv_addr, 0xfe, 0x00);
83+
84+
switch (pixformat) {
85+
case PIXFORMAT_RGB565:
86+
// RGB565 mode (value 6 in bits 4:0 of register 0x84)
87+
ret |= set_reg_bits(sensor->slv_addr, 0x84, 0x1f, 0, 6);
88+
break;
89+
90+
case PIXFORMAT_YUV422:
91+
case PIXFORMAT_GRAYSCALE:
92+
ret |= set_reg_bits(sensor->slv_addr, 0x84, 0x1f, 0, 0);
93+
94+
// Disable specific ISP modules that cause interlaced artifacts in colored regions
95+
ret |= cambus_writeb(sensor->slv_addr, 0xfe, 0x02); // Switch to page 2
96+
ret |= cambus_writeb(sensor->slv_addr, 0xd1, 0x00); // Disable YCP color saturation
97+
ret |= cambus_writeb(sensor->slv_addr, 0xd2, 0x00); // Disable YCP color saturation
98+
ret |= cambus_writeb(sensor->slv_addr, 0xfe, 0x00); // Back to page 0
99+
100+
break;
101+
102+
default:
103+
return -1;
104+
}
105+
106+
return ret;
70107
}
71108

72109
static int gc2145_set_framesize(sensor_t *sensor, framesize_t framesize)

components/micropython/port/src/omv/img/affine.c

Lines changed: 0 additions & 184 deletions
This file was deleted.

0 commit comments

Comments
 (0)