Skip to content

Commit 1a36fd9

Browse files
fix naive motion detection
1 parent 6d7d35a commit 1a36fd9

File tree

15 files changed

+724
-548
lines changed

15 files changed

+724
-548
lines changed

examples/Camera/CameraCaptureExample/CameraCaptureExample.ino

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818
//#include "eloquent/vision/camera/esp32/eye/gray/vga.h"
1919
//#include "eloquent/vision/camera/esp32/eye/gray/qvga.h"
2020
//#include "eloquent/vision/camera/esp32/eye/gray/qqvga.h"
21+
//#include "eloquent/vision/camera/esp32/m5/gray/vga.h"
22+
//#include "eloquent/vision/camera/esp32/m5/gray/qvga.h"
23+
//#include "eloquent/vision/camera/esp32/m5/gray/qqvga.h"
24+
//#include "eloquent/vision/camera/esp32/m5wide/gray/vga.h"
25+
//#include "eloquent/vision/camera/esp32/m5wide/gray/qvga.h"
26+
//#include "eloquent/vision/camera/esp32/m5wide/gray/qqvga.h"
2127

2228

2329
void setup() {
@@ -27,7 +33,7 @@ void setup() {
2733
// comment out if you want to increase the acquisition frequency
2834
// in the case of OV767x camera, highFreq = 5 fps instead of 1 fps
2935
// in the case of Esp32 camera, highFreq clock = 20 MHz instead of 10 MHz
30-
//camera.setHighFreq();
36+
camera.setHighFreq();
3137

3238
if (!camera.begin()) {
3339
while (true) {
@@ -47,6 +53,7 @@ void loop() {
4753
return;
4854
}
4955

56+
// resize for faster transmission over Serial port
5057
camera.image.resize<40, 30>();
5158
camera.image.printAsJsonTo(Serial);
5259
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/**
2+
* Camera motion detection demo
3+
*/
4+
5+
#include "eloquent.h"
6+
#include "eloquent/vision/motion/naive.h"
7+
8+
9+
// uncomment based on your camera and resolution
10+
11+
//#include "eloquent/vision/camera/ov767x/gray/vga.h"
12+
//#include "eloquent/vision/camera/ov767x/gray/qvga.h"
13+
//#include "eloquent/vision/camera/ov767x/gray/qqvga.h"
14+
//#include "eloquent/vision/camera/esp32/aithinker/gray/vga.h"
15+
//#include "eloquent/vision/camera/esp32/aithinker/gray/qvga.h"
16+
//#include "eloquent/vision/camera/esp32/aithinker/gray/qqvga.h"
17+
//#include "eloquent/vision/camera/esp32/wrover/gray/vga.h"
18+
//#include "eloquent/vision/camera/esp32/wrover/gray/qvga.h"
19+
//#include "eloquent/vision/camera/esp32/wrover/gray/qqvga.h"
20+
//#include "eloquent/vision/camera/esp32/eye/gray/vga.h"
21+
//#include "eloquent/vision/camera/esp32/eye/gray/qvga.h"
22+
//#include "eloquent/vision/camera/esp32/eye/gray/qqvga.h"
23+
//#include "eloquent/vision/camera/esp32/m5/gray/vga.h"
24+
//#include "eloquent/vision/camera/esp32/m5/gray/qvga.h"
25+
//#include "eloquent/vision/camera/esp32/m5/gray/qqvga.h"
26+
//#include "eloquent/vision/camera/esp32/m5wide/gray/vga.h"
27+
//#include "eloquent/vision/camera/esp32/m5wide/gray/qvga.h"
28+
//#include "eloquent/vision/camera/esp32/m5wide/gray/qqvga.h"
29+
30+
31+
#define THUMB_WIDTH 32
32+
#define THUMB_HEIGHT 24
33+
34+
35+
Eloquent::Vision::Motion::Naive<THUMB_WIDTH, THUMB_HEIGHT> detector;
36+
37+
38+
void setup() {
39+
delay(4000);
40+
Serial.begin(115200);
41+
42+
// turn on high freq for fast streaming speed
43+
camera.setHighFreq();
44+
45+
if (!camera.begin()) {
46+
while (true) {
47+
Serial.println(camera.getErrorMessage());
48+
delay(1000);
49+
}
50+
}
51+
else {
52+
Serial.println("Camera init OK");
53+
}
54+
55+
// wait for at least 10 frames to be processed before starting to detect
56+
// motion (false triggers at start)
57+
// then, when motion is detected, don't trigger for the next 10 frames
58+
detector.startSinceFrameNumber(10);
59+
detector.debounceMotionTriggerEvery(10);
60+
61+
// or, in one call
62+
detector.throttle(10);
63+
64+
// trigger motion when at least 10% of pixels change intensity by
65+
// at least 15 out of 255
66+
detector.setIntensityChangeThreshold(15);
67+
detector.setPixelChangesThreshold(0.1);
68+
}
69+
70+
71+
void loop() {
72+
if (!camera.capture()) {
73+
Serial.println(camera.getErrorMessage());
74+
delay(1000);
75+
return;
76+
}
77+
78+
// perform motion detection on resized image for fast detection
79+
camera.image.resize<THUMB_WIDTH, THUMB_HEIGHT>();
80+
camera.image.printAsJsonTo(Serial);
81+
detector.update(camera.image);
82+
83+
// if motion is detected, print coordinates to serial in JSON format
84+
if (detector.isMotionDetected()) {
85+
detector.printAsJsonTo(Serial);
86+
}
87+
}

src/eloquent/fs/spiffs.h

Lines changed: 119 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,135 @@
66

77
#include <FS.h>
88
#include <SPIFFS.h>
9+
#include "../macros.h"
910

1011

1112
namespace Eloquent {
1213
namespace FS {
13-
class SpiffsFile : public File {
14+
/**
15+
* File wrapper
16+
*/
17+
class SpiffsFile {
1418
public:
1519

16-
1720
/**
18-
* @compatibility
21+
* Constructor
1922
* @param filename
2023
* @param mode
2124
*/
22-
static File open(String filename, const char *mode = "r") {
23-
return SPIFFS.open(filename, mode);
25+
SpiffsFile(String filename, const char *mode) :
26+
_filename(filename),
27+
_mode(mode),
28+
_opened(false) {
29+
_isReadable = String(mode).indexOf("r") >= 0 || String(mode).indexOf("+") >= 0;
30+
_isWritable = String(mode).indexOf("w") >= 0;
31+
}
32+
33+
/**
34+
* Open file
35+
* @return
36+
*/
37+
bool open() {
38+
if (_opened)
39+
return true;
40+
41+
close();
42+
_file = SPIFFS.open(_filename, _mode);
43+
44+
if (_file) {
45+
return (_opened = true);
46+
}
47+
48+
return false;
49+
}
50+
51+
/**
52+
*
53+
*/
54+
void close() {
55+
_file.close();
56+
_opened = false;
57+
}
58+
59+
/**
60+
* Get file size
61+
* NOTE: will close the file first!
62+
* @return
63+
*/
64+
size_t size() {
65+
close();
66+
File file = SPIFFS.open(_filename, "r");
67+
size_t s = file.size();
68+
69+
file.close();
70+
71+
return s;
72+
}
73+
74+
/**
75+
*
76+
* @tparam T
77+
* @param data
78+
* @return
79+
*/
80+
template<typename T>
81+
size_t write(T data) {
82+
if (open() && _isWritable) {
83+
return _file.write(data);
84+
}
85+
86+
return 0;
87+
}
88+
89+
/**
90+
* Write raw data of given length
91+
* @tparam T
92+
* @param data
93+
* @param length
94+
* @return
95+
*/
96+
template<typename T>
97+
size_t write(T data, size_t length) {
98+
if (open() && _isWritable) {
99+
return _file.write(data, length);
100+
}
101+
102+
return 0;
103+
}
104+
105+
protected:
106+
String _filename;
107+
const char *_mode;
108+
File _file;
109+
bool _opened;
110+
bool _isReadable;
111+
bool _isWritable;
112+
};
113+
114+
/**
115+
* Spiffs filesystem abstraction
116+
*/
117+
class SpiffsFilesystem {
118+
public:
119+
120+
/**
121+
* Init SPIFFS
122+
* @param format
123+
*/
124+
void begin(bool format = false) {
125+
SPIFFS.begin(format);
126+
}
127+
128+
/**
129+
*
130+
* @param filename
131+
* @return
132+
*/
133+
SpiffsFile writeBinary(String filename) {
134+
return SpiffsFile(filename, "wb");
24135
}
25136
};
26137
}
27-
}
138+
}
139+
140+
ELOQUENT_SINGLETON(Eloquent::FS::SpiffsFilesystem filesystem);

src/eloquent/vision/image/BaseImage.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,18 @@ namespace Eloquent {
224224
jsonEncoder.closeObject();
225225
}
226226

227+
/**
228+
* Save as jpeg
229+
* @tparam Writer
230+
* @param writer
231+
*/
232+
// template<class Writer>
233+
// void writeAsJpegTo(Writer writer) {
234+
// Eloquent::Vision::Jpeg::Encoder<Writer> jpeg(writer);
235+
//
236+
// jpeg.write(buffer, getLength());
237+
// }
238+
227239
protected:
228240
uint16_t _width;
229241
uint16_t _height;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy