forked from PhotonVision/photon-libcamera-gl-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgl_hsv_thresholder.h
More file actions
83 lines (68 loc) · 1.92 KB
/
gl_hsv_thresholder.h
File metadata and controls
83 lines (68 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#pragma once
#include <array>
#include <cstdint>
#include <functional>
#include <mutex>
#include <optional>
#include <queue>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#include <EGL/egl.h>
#include <GLES2/gl2.h>
#include "headless_opengl.h"
enum class ProcessType: int32_t {
None = 0,
Hsv,
Gray,
Adaptive,
};
class GlHsvThresholder {
public:
struct DmaBufPlaneData {
int fd;
EGLint offset;
EGLint pitch;
};
explicit GlHsvThresholder(int width, int height);
~GlHsvThresholder();
void start(const std::vector<int> &output_buf_fds);
void release();
void returnBuffer(int fd);
int testFrame(
const std::array<GlHsvThresholder::DmaBufPlaneData, 3> &yuv_plane_data,
EGLint encoding, EGLint range, ProcessType type);
/**
* @brief Set the Hsv Thresholds range, on [0..1]
*
* @param hl Lower hue
* @param sl Sat lower
* @param vl Value lower
* @param hu Upper hue
* @param su Sat Upper
* @param vu Value Upper
* @param hueInverted if the range is [hl, hu] or [hu..180] | [0..hl]
*/
void setHsvThresholds(double hl, double sl, double vl, double hu, double su,
double vu, bool hueInverted);
private:
int m_width;
int m_height;
std::unordered_map<int, GLuint> m_framebuffers; // (dma_buf fd, framebuffer)
std::queue<int> m_renderable;
std::mutex m_renderable_mutex;
GLuint m_quad_vbo = 0;
GLuint m_grayscale_texture = 0;
GLuint m_grayscale_buffer = 0;
GLuint m_min_max_texture = 0;
GLuint m_min_max_framebuffer = 0;
std::vector<GLuint> m_programs = {};
HeadlessData m_status{};
EGLDisplay m_display;
EGLContext m_context;
std::mutex m_hsv_mutex;
double m_hsvLower[3] = {0}; // Hue, sat, value, in [0,1]
double m_hsvUpper[3] = {0}; // Hue, sat, value, in [0,1]
bool m_invertHue;
};