Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 57c4cb2

Browse files
add stream_downscaled to MotionDetectionRGB example
1 parent 38b951c commit 57c4cb2

File tree

3 files changed

+47
-11
lines changed

3 files changed

+47
-11
lines changed

‎examples/Vision/MotionDetection/MotionDetectionRGBExample/MotionDetectionRGBExample.ino

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ using namespace Eloquent::Vision;
2424

2525
camera_fb_t *frame;
2626
Camera::ESP32Camera camera(PIXFORMAT);
27+
uint8_t downscaled[w * h];
2728
//IO::Decoders::GrayscaleRandomAccessDecoder decoder;
2829
IO::Decoders::Red565RandomAccessDecoder decoder;
2930
Processing::Downscaling::Center<W / w, H / h> strategy;
@@ -34,6 +35,7 @@ IO::Writers::JpegWriter<W, H> jpegWriter;
3435

3536
void capture();
3637
void save();
38+
void stream_downscaled();
3739
void stream();
3840

3941

@@ -64,7 +66,10 @@ void loop() {
6466
// save();
6567

6668
// uncomment to stream to the Python script for visualization
67-
//stream();
69+
// stream();
70+
71+
// uncomment to stream downscaled imaged tp Python script
72+
// stream_downscaled();
6873

6974
delay(1000);
7075
}
@@ -74,18 +79,13 @@ void loop() {
7479

7580

7681
void capture() {
77-
uint32_t start = millis();
78-
uint8_t downscaled[w * h];
79-
8082
timeit("capture frame", frame = camera.capture());
8183

8284
// scale image from size H * W to size h * w
8385
timeit("downscale", downscaler.downscale(frame->buf, downscaled));
8486

8587
// detect motion on the downscaled image
8688
timeit("motion detection", motion.detect(downscaled));
87-
88-
//eloquent::io::print_all(1000 / (millis() - start), " FPS");
8989
}
9090

9191

@@ -106,4 +106,11 @@ void stream() {
106106
jpegWriter.write(Serial, frame->buf, PIXFORMAT, 30);
107107

108108
eloquent::io::print_all("END OF FRAME");
109+
}
110+
111+
112+
void stream_downscaled() {
113+
eloquent::io::print_all("START OF DOWNSCALED");
114+
eloquent::io::print_array(downscaled, w * h);
115+
eloquent::io::print_all("END OF DOWNSCALED");
109116
}

‎examples/Vision/MotionDetection/MotionDetectionRGBExample/stream_captures.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,21 @@
1+
import numpy as np
12
from serial import Serial
3+
from PIL import Image
4+
5+
6+
def infer_size(arr, ratio):
7+
"""
8+
Try to infer image sizes given the ratio width / height
9+
:param arr:
10+
:param ratio:
11+
:return:
12+
"""
13+
for height in range(2, 129, 2):
14+
width = int(height * ratio)
15+
size = width * height
16+
if size == len(arr):
17+
return width, height
18+
raise AssertionError('Cannot find image size (len=%d, ratio=%.2f)' % (len(arr), ratio))
219

320

421
if __name__ == '__main__':
@@ -20,13 +37,24 @@
2037
try:
2138
text += byte.decode('utf-8')
2239
if text.endswith('END OF FRAME'):
23-
with open('frame%d.jpg' % idx, 'wb') as file:
40+
with open('captures/frame%d.jpg' % idx, 'wb') as file:
2441
for byte in jpeg[:-len('END OF FRAME')]:
2542
file.write(byte)
2643
print('done', idx)
2744
idx += 1
2845
break
2946
except UnicodeDecodeError:
3047
pass
48+
elif line == 'START OF DOWNSCALED':
49+
print('new downscaled')
50+
raw = camera.readline().decode('utf-8').strip()
51+
arr = np.asarray([int(pixel) for pixel in raw.split(',')], dtype=np.uint8)
52+
w, h = infer_size(arr, 4/3)
53+
img = arr.reshape((h, w))
54+
img = Image.fromarray(img, 'L')
55+
img.save('downscaled/%d.jpg' % idx)
56+
print('done', idx)
57+
idx += 1
58+
3159
except UnicodeDecodeError:
3260
pass

‎library.properties

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
name=EloquentArduino
22
version=1.1.0
3-
author=Simone Salerno <github.com/eloquentarduino>
4-
maintainer=Simone Salerno <github.com/eloquentarduino>
5-
sentence=An eloquent interface to common Arduino patterns
6-
paragraph=
3+
author=Simone Salerno <eloquentarduino@gmail.com>
4+
maintainer=Simone Salerno <eloquentarduino@gmail.com>
5+
sentence=An eloquent interface to common Arduino patterns, data structures and algorithms
6+
paragraph=Follow the blog at eloquentarduino.github.io for details
77
category=Other
88
url=https://github.com/eloquentarduino/EloquentArduino
99
architectures=*
10+
includes=eloquentarduino.h

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /