6#include "TinyRobotics/communication/Message.h"
7#include "TinyRobotics/communication/MessageSource.h"
9namespace tinyrobotics {
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
52 CameraObstacleDetector(
53 uint8_t threshold = 60,
56 : _threshold(threshold), _trigger(trigger) {}
59 Result process(
const uint8_t* image, size_t width, size_t height) {
60 if (!image || width == 0 || height == 0) {
65 size_t x_start = width / 4;
66 size_t x_end = 3 * width / 4;
67 size_t y_start = height / 3;
68 size_t y_end = height;
73 for (size_t y = y_start; y < y_end; y++) {
74 for (size_t x = x_start; x < x_end; x++) {
75 uint8_t pixel = image[y * width + x];
78 if (pixel < _threshold) {
85 float density = (total > 0) ? (
float)hits / total : 0.0f;
88 Message<
float> msgError(MessageContent::Obstacle, density * 100.0f, Unit::Percent, MessageOrigin::Camera);
89 sendMessage(msgError);
91 return {density > _trigger, density};
Simple obstacle detection algorithm for grayscale camera images.
Definition: CameraObstacleDetector.h:45
Base class for message sources in the TinyRobotics communication framework.
Definition: MessageSource.h:35
Definition: CameraObstacleDetector.h:47
Generic message structure for communication, parameterized by value type.
Definition: Message.h:72