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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
#pragma once
#include "../tracker-pt/pt-api.hpp"
#include "compat/macros.hpp"
#include "options/options.hpp"
#include <track_hat_driver.h>
#include <array>
#include <atomic>
#include <opencv2/core.hpp>
enum model_type : int
{
model_cap = 1,
model_clip_left,
model_clip_right,
model_mini_clip_left,
model_mini_clip_right,
};
namespace trackhat_impl
{
using namespace options;
struct trackhat_settings : opts
{
trackhat_settings();
value<slider_value> exposure{b, "exposure", {0x80, 0x10, 0xff}};
value<slider_value> gain{b, "gain", {16, 0, 47}};
value<slider_value> threshold{b, "threshold", {0x97, 64, 0xff}};
value<slider_value> threshold_2{b, "threshold-2", {0x03, 1, 0xfe}};
value<model_type> model{b, "model", model_mini_clip_left};
value<double> min_pt_size{b, "min-point-size", 2};
value<double> max_pt_size{b, "max-point-size", 8};
value<bool> enable_point_filter{b, "enable-point-filter", true };
value<slider_value> point_filter_coefficient{b, "point-filter-coefficient", { 1.5, 1, 4 }};
};
class setting_receiver : public QObject
{
Q_OBJECT
public:
bool test_and_clear();
public slots:
void settings_changed();
private:
std::atomic<bool> changed{false};
};
} // ns trackhat_impl
using typename trackhat_impl::trackhat_settings;
struct trackhat_metadata final : pt_runtime_traits
{
pt_runtime_traits::pointer<pt_camera> make_camera() const override;
pt_runtime_traits::pointer<pt_point_extractor> make_point_extractor() const override;
pt_runtime_traits::pointer<pt_frame> make_frame() const override;
pt_runtime_traits::pointer<pt_preview> make_preview(int w, int h) const override;
QString get_module_name() const override;
OTR_DISABLE_MOVE_COPY(trackhat_metadata);
trackhat_metadata() = default;
~trackhat_metadata() override = default;
static const QString module_name;
};
struct point
{
int brightness = 0, x, y, W, H;
bool ok = false;
};
struct trackhat_camera final : pt_camera
{
trackhat_camera();
~trackhat_camera() override;
OTR_DISABLE_MOVE_COPY(trackhat_camera);
bool start(const pt_settings& s) override;
void stop() override;
[[nodiscard]] int init_regs();
void set_pt_options();
pt_camera::result get_frame(pt_frame& frame) override;
pt_camera::result get_info() const override;
pt_camera_info get_desired() const override;
QString get_desired_name() const override;
QString get_active_name() const override;
void set_fov(f value) override;
void show_camera_settings() override;
static constexpr int sensor_size = 2940;
static constexpr int sensor_fov = 52;
static constexpr int point_count = TRACK_HAT_NUMBER_OF_POINTS;
private:
enum device_status { th_noinit, th_init, th_detect, th_connect, th_running, };
trackhat_impl::setting_receiver sig;
trackHat_Device_t device {};
device_status status = th_noinit;
TH_ErrorCode error_code = TH_SUCCESS;
pt_settings s{trackhat_metadata::module_name};
trackhat_settings t;
};
struct trackhat_frame final : pt_frame
{
void init_points(const trackHat_ExtendedPoints_t& points, double min_size, double max_size);
trackhat_frame() = default;
~trackhat_frame() override = default;
std::array<point, trackhat_camera::point_count> points;
};
struct trackhat_preview final : pt_preview
{
QImage get_bitmap() override;
void draw_head_center(f x, f y) override;
void set_last_frame(const pt_frame&) override; // NOLINT(misc-unconventional-assign-operator)
trackhat_preview(int w, int h);
~trackhat_preview() override = default;
void draw_points();
void draw_center();
OTR_DISABLE_MOVE_COPY(trackhat_preview);
cv::Mat frame_bgr, frame_bgra;
numeric_types::vec2 center{-1, -1};
std::array<point, trackhat_camera::point_count> points;
};
struct trackhat_extractor final : pt_point_extractor
{
void extract_points(const pt_frame& data, pt_preview&, bool, std::vector<vec2>& points) override;
OTR_DISABLE_MOVE_COPY(trackhat_extractor);
trackhat_extractor() = default;
~trackhat_extractor() override = default;
};
|