Skip to content

Commit 158a70b

Browse files
patch WiFi telegram bot + ESP32 camera capture + [experimental] add Local Binary Pattern feature extractor
1 parent 3482e87 commit 158a70b

File tree

8 files changed

+161
-80
lines changed

8 files changed

+161
-80
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* Capture data from VL53L5CX 8x8 Time of Flight sensor
3+
*/
4+
#include <Wire.h>
5+
#include <eloquent.h>
6+
#include <eloquent/modules/vl53l5cx/8x8.h>
7+
8+
9+
10+
void setup() {
11+
Serial.begin(115200);
12+
Wire.begin();
13+
14+
// (optional) turn on high speed communication
15+
Wire.setClock(1000000);
16+
vllcx.highFreq();
17+
18+
// (optional) truncate readings lower than 30 (3 cm) and higher than 500 (50 cm)
19+
vllcx.truncateLowerThan(30);
20+
vllcx.truncateHigherThan(500);
21+
22+
// (optional) rescale distances from millimeters to 0-1 range (aka normalize distances)
23+
vllcx.scaleToRange(0, 1);
24+
25+
if (!vllcx.begin())
26+
eloquent::abort(Serial, "vl53l5cx not found");
27+
28+
Serial.println("vl53l5cx is ok");
29+
}
30+
31+
32+
void loop() {
33+
// await for new data
34+
if (!vllcx.hasNewData() || !vllcx.read())
35+
return;
36+
37+
// print readings to Serial
38+
vllcx.printTo(Serial);
39+
delay(100);
40+
}

examples/VL53L5CX/VL53L5cxSimpleCapture/VL53L5cxSimpleCapture.ino

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

examples/VL53L5CX/VL53L5cxStreamCapture/VL53L5cxStreamCapture.ino

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

src/eloquent/apps/telegram/bot/wifi.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ namespace Eloquent {
3939
*/
4040
bool begin() override {
4141
_telegramBotWifiSecureClient.setCACert(TELEGRAM_CERTIFICATE_ROOT);
42+
43+
return true;
4244
}
4345
};
4446
}

src/eloquent/modules/VL53L5CX.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ namespace Eloquent {
1717
*/
1818
class Vl53l5cx {
1919
public:
20+
const bool USE_SEQUENCE_NUMBER = true;
21+
const bool USE_TIMESTAMP = false;
2022
float distances[64];
2123

2224

@@ -32,7 +34,8 @@ namespace Eloquent {
3234
_sleepDistance(0),
3335
_sleepDebounce(0),
3436
_sleepDebounceCounter(0),
35-
_sleepFails(0) {
37+
_sleepFails(0),
38+
_sequenceNumber(0) {
3639

3740
if (_resolution != 64 && _resolution != 16)
3841
_resolution = 64;
@@ -262,6 +265,7 @@ namespace Eloquent {
262265
uint16_t _sleepDebounce;
263266
uint16_t _sleepDebounceCounter;
264267
uint8_t _sleepFails;
268+
long unsigned int _sequenceNumber;
265269
SparkFun_VL53L5CX _sensor;
266270
VL53L5CX_ResultsData _data;
267271
struct {

src/eloquent/vision/camera/esp32/BaseEsp32Camera.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ namespace Eloquent {
132132
bool concreteCapture() override {
133133
this->_fb = esp_camera_fb_get();
134134

135-
if (this->_fb->len == 0) {
135+
if (this->_fb == NULL || this->_fb->len == 0) {
136136
return setError(Error::CAPTURE_ERROR);
137137
}
138138

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
//
2+
// Created by Simone on 18/06/2022.
3+
//
4+
5+
#pragma once
6+
7+
8+
namespace Eloquent {
9+
namespace Vision {
10+
namespace Features {
11+
/**
12+
* Local Binary Pattern with R=? and P=8
13+
*/
14+
template<uint8_t r>
15+
class LocalBinaryPatternP8 {
16+
public:
17+
18+
/**
19+
*
20+
* @tparam Image
21+
* @param src
22+
* @param dest
23+
*/
24+
template<typename Image>
25+
void transform(Image *src, Image *dest = NULL) {
26+
const uint16_t height = src->getHeight();
27+
const uint16_t width = src->getWidth();
28+
uint32_t i = 0;
29+
30+
if (dest == NULL)
31+
dest = src;
32+
33+
for (uin16_t y = r; y < height - r; y++) {
34+
for (uint16_t x = r; x < width - r; x++) {
35+
const uint8_t pixel = src->at(x, y);
36+
const uint8_t p0 = src->at(x - r, y - r);
37+
const uint8_t p1 = src->at(x, y - r);
38+
const uint8_t p2 = src->at(x + r, y - r);
39+
const uint8_t p3 = src->at(x - r, y);
40+
const uint8_t p4 = src->at(x + r, y);
41+
const uint8_t p5 = src->at(x - r, y + r);
42+
const uint8_t p6 = src->at(x, y + r);
43+
const uint8_t p7 = src->at(x + r, y + r);
44+
45+
const uint8_t lbp =
46+
(p0 > pixel)
47+
| ((p1 > pixel) << 1)
48+
| ((p2 > pixel) << 2)
49+
| ((p3 > pixel) << 3)
50+
| ((p4 > pixel) << 4)
51+
| ((p5 > pixel) << 5)
52+
| ((p6 > pixel) << 6)
53+
| ((p7 > pixel) << 7)
54+
55+
dest.set(i, uniformLookup[lbp]);
56+
i += 1;
57+
}
58+
59+
dest.setWidth(width - 2 * r);
60+
dest.setHeight(height - 2 * r);
61+
}
62+
}
63+
64+
protected:
65+
const uint8_t uniformLookup[256] = {1, 2, 3, 4, 5, 0, 6, 7, 8, 0, 0, 0, 9, 0, 10, 11, 12, 0, 0, 0, 0, 0, 0, 0, 13, 0, 0, 0, 14, 0, 15, 16, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 0, 0, 0, 0, 0, 0, 19, 0, 0, 0, 20, 0, 21, 22, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25, 0, 0, 0, 0, 0, 0, 0, 26, 0, 0, 0, 27, 0, 28, 29, 30, 31, 0, 32, 0, 0, 0, 33, 0, 0, 0, 0, 0, 0, 0, 34, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 35, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 36, 37, 38, 0, 39, 0, 0, 0, 40, 0, 0, 0, 0, 0, 0, 0, 41, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42, 43, 44, 0, 45, 0, 0, 0, 46, 0, 0, 0, 0, 0, 0, 0, 47, 48, 49, 0, 50, 0, 0, 0, 51, 52, 53, 0, 54, 55, 56, 57, 58};
66+
};
67+
68+
/**
69+
* Local Binary Pattern with R=1 and P=8
70+
*/
71+
class LocalBinaryPatternR1P8 : public LocalBinaryPatternP8<1> {};
72+
73+
/**
74+
* Local Binary Pattern with R=2 and P=8
75+
*/
76+
class LocalBinaryPatternR1P8 : public LocalBinaryPatternP8<2> {};
77+
}
78+
}
79+
}

src/eloquent/vision/image/BaseImage.h

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ namespace Eloquent {
111111
}
112112

113113
/**
114-
*
114+
* Get pixel at (x, y)
115115
* @param x
116116
* @param y
117117
*/
@@ -120,7 +120,7 @@ namespace Eloquent {
120120
}
121121

122122
/**
123-
*
123+
* Get pixel at (x, y, z)
124124
* @param x
125125
* @param y
126126
* @param z
@@ -141,6 +141,38 @@ namespace Eloquent {
141141
return buffer[i];
142142
}
143143

144+
/**
145+
* Set pixel at (x, y)
146+
* @param x
147+
* @param y
148+
*/
149+
uint8_t set(uint16_t x, uint16_t y, value) {
150+
return at(x, y, 0, value);
151+
}
152+
153+
/**
154+
* Set pixel at (x, y, z)
155+
* @param x
156+
* @param y
157+
* @param z
158+
*/
159+
uint8_t set(uint16_t x, uint16_t y, uint8_t z, uin8_t value) {
160+
return set(y * getWidth() * getBytesPerPixel() + x * getBytesPerPixel() + z, value);
161+
}
162+
163+
/**
164+
* Set pixel value at given index
165+
* @param i
166+
* @param value
167+
* @return
168+
*/
169+
uint8_t set(uint16_t i, uint8_t value) {
170+
if (i > getLength())
171+
return 0;
172+
173+
return (buffer[i] = value);
174+
}
175+
144176
/**
145177
* Set new buffer and restore to original size
146178
*

0 commit comments

Comments
 (0)