SmartSpectra C++ SDK
Measure human vitals from video with SmartSpectra C++ SDK.
Loading...
Searching...
No Matches
camera_tuner.hpp
1// camera_tuner.hpp
2// Created by Greg on 10/10/2025.
3// Copyright (C) 2025 Presage Security, Inc.
4//
5// SPDX-License-Identifier: LGPL-3.0-or-later
6
7#pragma once
8
9// standard library includes
10#include <memory>
11#include <cstdint>
12
13// third-party includes
14#include <absl/status/status.h>
15#include <absl/status/statusor.h>
16#include <physiology/modules/messages/status.h>
17#include <mediapipe/framework/port/opencv_core_inc.h>
18
19// local includes
20#include "video_source.hpp"
21#include "camera_tuner_settings.hpp"
22
23
37
38namespace presage::smartspectra::video_source {
39
43enum class TuningStage {
45 NOT_STARTED,
47 AUTO_WHITE_BALANCE,
49 EXPOSURE_SEARCH,
51 GAIN_SEARCH,
53 COMPLETE,
55 FAILED
56};
57
75public:
80 explicit CameraTuner(CameraTunerSettings settings = {});
81
91 absl::Status SetVideoSource(std::shared_ptr<VideoSource> source);
92
101 std::shared_ptr<VideoSource> GetVideoSource();
102
111 absl::Status StartTuning();
112
117 bool IsTuning() const;
118
123 TuningStage GetCurrentStage() const;
124
135 absl::Status ProcessFrame(presage::physiology::StatusCode status_code,
136 int64_t frame_timestamp);
137
138
143 absl::StatusOr<double> GetTunedExposure() const;
144
149 absl::StatusOr<double> GetTunedGain() const;
150
155 absl::StatusOr<double> GetTunedWhiteBalance() const;
156
166 cv::Mat ProcessFrameForDisplay(const cv::Mat& frame) const;
167
168private:
170 CameraTunerSettings settings_;
171
173 std::shared_ptr<VideoSource> video_source_;
174
176 TuningStage stage_;
177
178 // White balance state
180 bool supports_white_balance_;
182 int wb_frame_counter_;
184 double locked_white_balance_;
185
186 // Exposure reduction state
188 double current_exposure_;
190 int exposure_iteration_count_;
192 int64_t last_frame_timestamp_;
194 double current_framerate_;
196 int exposure_settle_frame_count_;
197
198 // Gain increase state
200 double current_gain_;
202 int gain_iteration_count_;
204 int gain_settle_frame_count_;
205
210 absl::Status ProcessAutoWhiteBalanceStage();
211
218 absl::Status ProcessExposureSearchStage(presage::physiology::StatusCode status_code,
219 int64_t frame_timestamp);
220
226 absl::Status ProcessGainSearchStage(presage::physiology::StatusCode status_code);
227
232 absl::Status ValidateVideoSourceControls();
233};
234
235} // namespace presage::smartspectra::video_source
absl::StatusOr< double > GetTunedGain() const
Get the tuned gain value.
Definition camera_tuner.cpp:111
absl::Status ProcessFrame(presage::physiology::StatusCode status_code, int64_t frame_timestamp)
Process a frame during tuning (synchronous mode).
Definition camera_tuner.cpp:86
bool IsTuning() const
Check if tuning is currently in progress.
Definition camera_tuner.cpp:76
CameraTuner(CameraTunerSettings settings={})
Construct a camera tuner with specified settings.
Definition camera_tuner.cpp:17
absl::Status StartTuning()
Start the tuning process.
Definition camera_tuner.cpp:47
TuningStage GetCurrentStage() const
Get the current tuning stage.
Definition camera_tuner.cpp:82
cv::Mat ProcessFrameForDisplay(const cv::Mat &frame) const
Process a frame for display with optional camera tuning overlay.
Definition camera_tuner.cpp:372
absl::Status SetVideoSource(std::shared_ptr< VideoSource > source)
Set the video source to tune.
Definition camera_tuner.cpp:34
absl::StatusOr< double > GetTunedWhiteBalance() const
Get the tuned white balance value.
Definition camera_tuner.cpp:118
absl::StatusOr< double > GetTunedExposure() const
Get the tuned exposure value.
Definition camera_tuner.cpp:104
std::shared_ptr< VideoSource > GetVideoSource()
Get shared pointer to the video source.
Definition camera_tuner.cpp:43
Configuration parameters for the camera tuning process.
Definition camera_tuner_settings.hpp:14