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 594cfa9

Browse files
RGBHistogram
1 parent 30d35b1 commit 594cfa9

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/**
2+
* Example on how to use the RGBHistogram class.
3+
* It computes the (binned) frequency histogram of R, G, B values in an image.
4+
*/
5+
#define CAMERA_MODEL_M5STACK_WIDE
6+
#define FRAME_SIZE FRAMESIZE_QVGA
7+
#define NUM_BINS 16
8+
9+
#include <EloquentArduino.h>
10+
#include <eloquentarduino/vision/camera/ESP32Camera.h>
11+
#include <eloquentarduino/vision/processing/RGBHistogram.h>
12+
13+
14+
Eloquent::Vision::Camera::ESP32Camera camera(PIXFORMAT_RGB565);
15+
Eloquent::Vision::Processing::RGBHistogram<NUM_BINS> hist;
16+
17+
18+
/**
19+
* Function prototype
20+
*/
21+
void printHistogram(uint16_t *hist, char bar = '|', uint8_t divisor = 10);
22+
23+
24+
/**
25+
*
26+
*/
27+
void setup() {
28+
Serial.begin(115200);
29+
camera.begin(FRAME_SIZE);
30+
delay(4000);
31+
}
32+
33+
34+
/**
35+
*
36+
*/
37+
void loop() {
38+
camera_fb_t *frame = camera.capture();
39+
40+
// actually compute histogram
41+
hist.update(frame->buf, frame->len);
42+
43+
// the hist object has the attributes rHistogram, gHistrogram, bHistogram
44+
// that contain the calculated histograms
45+
//printHistogram(hist.gHistogram);
46+
delay(4000);
47+
}
48+
49+
50+
/**
51+
* Print histogram on the serial monitor
52+
*/
53+
void printHistogram(uint16_t *hist, char bar, uint8_t divisor) {
54+
// for each bin
55+
for (uint8_t i = 0; i < NUM_BINS; i++) {
56+
Serial.printf("%-2d ", i);
57+
58+
// print row proportional to its height
59+
for (uint16_t j = hist[i] / divisor; j > 0; j--) {
60+
Serial.print(bar);
61+
}
62+
63+
Serial.println();
64+
}
65+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
// Created by Simone on 07/09/2021.
3+
//
4+
5+
#ifndef ELOQUENTARDUINO_RGBHISTOGRAM_H
6+
#define ELOQUENTARDUINO_RGBHISTOGRAM_H
7+
8+
9+
10+
class RGBHistogram {
11+
12+
};
13+
14+
15+
16+
#endif //ELOQUENTARDUINO_RGBHISTOGRAM_H

0 commit comments

Comments
(0)

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