Skip to content

Commit 872a686

Browse files
committed
mnist_cnn: Include downscaling
1 parent 15d8304 commit 872a686

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

examples/mnist_cnn/mnist_cnn_camera.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11

22

33
import time
4+
import array
45

56
# Using https://github.com/cnadler86/micropython-camera-API for ESP32 with OV2640 camera
67
from camera import Camera, GrabMode, PixelFormat, FrameSize, GainCeiling
78

9+
import downscale
810

911
def print_2d_buffer(arr, rowstride):
1012

@@ -99,6 +101,9 @@ def main():
99101

100102
image_no = 0
101103

104+
process_size = 32
105+
scaled = array.array('B', (0 for _ in range(process_size*process_size)))
106+
102107
while True:
103108

104109
capture_start = time.ticks_ms()
@@ -119,9 +124,16 @@ def main():
119124
print('mean', mean)
120125

121126
path = f'img{image_no}.bmp'
122-
save_image(path, buf, width, height)
127+
#save_image(path, buf, width, height)
123128
#print_2d_buffer(buf, 96)
124-
print('Saved', path)
129+
#print('Saved', path)
130+
131+
# Downscale
132+
downscale_start = time.ticks_ms()
133+
downscale.downscale(buf, scaled, width, process_size)
134+
downscale_duration = time.ticks_diff(time.ticks_ms(), downscale_start)
135+
print('downscale', downscale_duration)
136+
# TODO: run CNN inference
125137

126138
image_no += 1
127139
time.sleep(5.0)

0 commit comments

Comments
 (0)