SmartSpectra C++ SDK
Measure human vitals from video with SmartSpectra C++ SDK.
Loading...
Searching...
No Matches
opencv_hud.hpp
1
2// opencv_hud.hpp
3// Created by greg on 1/3/25.
4// Copyright (C) 2025 Presage Security, Inc.
5//
6// This program is free software; you can redistribute it and/or
7// modify it under the terms of the GNU Lesser General Public
8// License as published by the Free Software Foundation; either
9// version 3 of the License, or (at your option) any later version.
10//
11// This program is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14// Lesser General Public License for more details.
15//
16// You should have received a copy of the GNU Lesser General Public License
17// along with this program; if not, write to the Free Software Foundation,
18// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
21// === standard library includes (if any) ===
22// === third-party includes (if any) ===
23#include <opencv2/core.hpp>
24#include <physiology/modules/messages/metrics.pb.h>
25// === local includes (if any) ===
26#include "opencv_trace_plotter.hpp"
27#include "opencv_value_indicator.hpp"
28#include "opencv_label.hpp"
29
30
31#pragma once
32
33namespace presage::smartspectra::gui {
34
35class OpenCvHud {
36public:
37 OpenCvHud(
38 int x, int y, int width, int height,
39 int max_trace_points = 300,
40 cv::Scalar pulse_confident_color = cv::Scalar(0, 255, 0), // green
41 cv::Scalar pulse_unconfident_color = cv::Scalar(0, 0, 255), // red
42 cv::Scalar breathing_upper_confident_color = cv::Scalar(255, 255, 0), // cyan
43 cv::Scalar breathing_upper_unconfident_color = cv::Scalar(0, 0, 255), // red
44 cv::Scalar breathing_lower_confident_color = cv::Scalar(255, 0, 0), // blue
45 cv::Scalar breathing_lower_unconfident_color = cv::Scalar(0, 0, 255) // red
46 );
47
48 void UpdateWithNewMetrics(const physiology::MetricsBuffer& new_metrics);
49 absl::Status Render(cv::Mat& image);
50
51 static const int minimal_width; // derived
52 static const int minimal_height; // derived
53
54private:
55 static const float no_rate_value_to_display;
56
57 static const int top_plot_area_margin;
58 static const int bottom_plot_area_margin;
59 static const int minimal_plot_area_width; // arbitrary / base on visual experimentation
60 static const int minimal_plot_area_height; // arbitrary / base on visual experimentation
61
62 static const int indicator_width;
63 static const int label_width;
64
65 const int max_trace_points;
66 bool width_sufficient = false;
67 bool height_sufficient = false;
68 cv::Rect2i hud_area;
69
70
71 struct MetricsGroup {
72 OpenCvTracePlotter trace_plotter;
73 OpenCvValueIndicator rate_indicator;
74 OpenCvLabel label;
75 presage::physiology::MeasurementWithConfidence rate;
76 bool display_rate = true;
77 bool rate_is_high_confidence = false;
78 const cv::Scalar confident_color;
79 const cv::Scalar unconfident_color;
80 absl::Status Render(cv::Mat& image);
81 };
82
83 std::unique_ptr<MetricsGroup> pulse_group;
84 std::unique_ptr<MetricsGroup> upper_breathing_group;
85 std::unique_ptr<MetricsGroup> lower_breathing_group;
86
87};
88
89} // namespace presage::smartspectra::gui
Definition opencv_label.hpp:17
Definition opencv_trace_plotter.hpp:33
Definition opencv_value_indicator.hpp:30