IDS peak AFL v2.0.0
Loading...
Searching...
No Matches
peak_afl_generic_auto_focus.hpp
Go to the documentation of this file.
1
10
11#pragma once
12
13#include <peak_afl/peak_afl.hpp>
20
22
23#include <peak/generic/peak_t_callback_manager.hpp>
24
25#include <memory>
26
27namespace peak
28{
29namespace pipeline
30{
31namespace modules
32{
33namespace autofeature
34{
35namespace detail
36{
37class GenericAutoFocus : public IController
38{
39public:
40 explicit GenericAutoFocus(peak::afl::Manager& manager)
41 : IController(manager)
42 , m_controller{ peak::afl::Controller::Create(PEAK_AFL_CONTROLLER_TYPE_AUTOFOCUS) }
43 , m_skipFrames{ std::make_unique<features::SkipFrames>(m_controller) }
44 , m_hysteresis{ std::make_unique<features::Hysteresis>(m_controller) }
45 , m_weightedRois{ std::make_unique<features::WeightedRois>(m_controller) }
46 , m_sharpnessAlgorithm{ std::make_unique<features::SharpnessAlgorithm>(m_controller) }
47 , m_searchAlgorithm{ std::make_unique<features::SearchAlgorithm>(m_controller) }
48 , m_focusLimit{ std::make_unique<features::FocusLimit>(m_controller) }
49 {
50 GetManager().AddController(m_controller);
51
52 m_controller->RegisterFinishedCallback([this]() { m_FinishedCallbackManager.TriggerCallbacks(); });
53 }
54
55 PEAK_COMMON_NO_DISCARD std::string GetName() const override
56 {
57 return "GenericAutoFocus";
58 }
59
60 void Serialize(peak::common::serialization::IArchive& archive) const override
61 {
62 for (const auto& feature : std::initializer_list<const peak::common::serialization::ISerializable*>{ m_skipFrames.get(),
63 m_hysteresis.get(), m_weightedRois.get(), m_sharpnessAlgorithm.get(), m_searchAlgorithm.get(), m_focusLimit.get() })
64 {
65 feature->Serialize(archive);
66 }
67
68 archive.SetString("Mode", ToString(GetMode()));
69 }
70
71 void Deserialize(const peak::common::serialization::IArchive& archive) override
72 {
73 for (const auto& feature : std::initializer_list<peak::common::serialization::ISerializable*>{ m_skipFrames.get(),
74 m_hysteresis.get(), m_weightedRois.get(), m_sharpnessAlgorithm.get(), m_searchAlgorithm.get(), m_focusLimit.get() })
75 {
76 feature->Deserialize(archive);
77 }
78
79 SetMode(detail::ToControllerMode(archive.GetString("Mode")));
80 }
81
82 void SetMode(ControllerMode mode) override
83 {
84 m_controller->SetMode(ToCType(mode));
85 }
86
88 {
89 return ToControllerMode(m_controller->GetMode());
90 }
91
92 PEAK_COMMON_NO_DISCARD bool IsRunning() const override
93 {
94 return GetMode() != ControllerMode::Off;
95 }
96
97 void ResetToDefault() override
98 {
99 SetMode(ControllerMode::Off);
100 SkipFrames().Set(2);
101 SearchAlgorithm().Set(FocusSearchAlgorithm::GoldenRatio);
102 SharpnessAlgorithm().Set(FocusSharpnessAlgorithm::Tenengrad);
103
104 const auto focusLimit = m_controller->GetDefaultLimit();
105 FocusLimit().Set({ focusLimit.min, focusLimit.max });
106 Hysteresis().Set(8);
107
108 m_controller->SetROIPreset(PEAK_AFL_CONTROLLER_ROI_PRESET_CENTER);
109 }
110
111 PEAK_COMMON_NO_DISCARD features::SkipFrames& SkipFrames() const
112 {
113 return *m_skipFrames;
114 }
115
116 PEAK_COMMON_NO_DISCARD features::Hysteresis& Hysteresis() const
117 {
118 return *m_hysteresis;
119 }
120
121 PEAK_COMMON_NO_DISCARD features::WeightedRois& WeightedROIs() const
122 {
123 return *m_weightedRois;
124 }
125
126 PEAK_COMMON_NO_DISCARD features::SharpnessAlgorithm& SharpnessAlgorithm() const
127 {
128 return *m_sharpnessAlgorithm;
129 }
130
131 PEAK_COMMON_NO_DISCARD features::SearchAlgorithm& SearchAlgorithm() const
132 {
133 return *m_searchAlgorithm;
134 }
135
136 PEAK_COMMON_NO_DISCARD features::FocusLimit& FocusLimit() const
137 {
138 return *m_focusLimit;
139 }
140
142 {
144 }
145
146 IController::FinishedCallbackHandle RegisterFinishedCallback(const IController::FinishedCallback& callback)
147 {
148 return m_FinishedCallbackManager.RegisterCallback(callback);
149 }
150
151 void UnregisterFinishedCallback(IController::FinishedCallbackHandle callbackHandle)
152 {
153 m_FinishedCallbackManager.UnregisterCallback(callbackHandle);
154 }
155
156private:
157 std::shared_ptr<peak::afl::Controller> m_controller;
158 peak::core::TTriggerCallbackManager<IController::FinishedCallbackHandle, IController::FinishedCallback>
159 m_FinishedCallbackManager;
160 std::unique_ptr<features::SkipFrames> m_skipFrames{};
161 std::unique_ptr<features::Hysteresis> m_hysteresis{};
162 std::unique_ptr<features::WeightedRois> m_weightedRois{};
163 std::unique_ptr<features::SharpnessAlgorithm> m_sharpnessAlgorithm{};
164 std::unique_ptr<features::SearchAlgorithm> m_searchAlgorithm{};
165 std::unique_ptr<features::FocusLimit> m_focusLimit{};
166};
167} // namespace detail
168} // namespace autofeature
169} // namespace modules
170} // namespace pipeline
171} // namespace peak
void AddController(const std::shared_ptr< Controller > &controller)
Add a controller to an automanager.
Definition peak_afl.hpp:2245
virtual std::string GetString(const std::string &key) const =0
Retrieves a string value by key.
virtual void SetString(const std::string &key, const std::string &value)=0
Stores a UTF-8 string.
Abstract base interface for all automatic controllers.
Definition peak_afl_icontroller.hpp:227
std::function< void()> FinishedCallback
Callback function type for operation completion notifications.
Definition peak_afl_icontroller.hpp:233
virtual std::string GetName() const =0
Gets the unique name of this controller.
peak::afl::Manager & GetManager()
Gets a reference to the API manager.
Definition peak_afl_icontroller.hpp:368
virtual bool IsRunning() const =0
Checks if the controller is currently running.
FinishedCallback * FinishedCallbackHandle
Handle type for managing callback registrations.
Definition peak_afl_icontroller.hpp:238
virtual ControllerType GetType() const =0
Gets the type of this controller.
virtual ControllerMode GetMode() const =0
Gets the current operational mode of this controller.
virtual void ResetToDefault()=0
Resets the controller to its default configuration.
@ PEAK_AFL_CONTROLLER_TYPE_AUTOFOCUS
Automatic focus controller.
Definition peak_afl.h:529
@ PEAK_AFL_CONTROLLER_ROI_PRESET_CENTER
Center region preset.
Definition peak_afl.h:1420
ControllerMode
Controller operation mode enumeration.
Definition peak_afl_icontroller.hpp:59
ControllerType
Controller type enumeration.
Definition peak_afl_icontroller.hpp:40
std::string ToString(ControllerType mode)
Converts ControllerType enumeration to string representation.
Definition peak_afl_icontroller.hpp:78
@ Off
Controller is disabled - no automatic processing.
Definition peak_afl_icontroller.hpp:61
@ Focus
Automatic focus controller - manages lens focus positioning.
Definition peak_afl_icontroller.hpp:42
@ Tenengrad
Tenengrad algorithm - gradient-based sharpness measurement.
Definition peak_afl_sharpness_algorithm.hpp:48
@ GoldenRatio
Golden ratio search - efficient for unimodal focus curves.
Definition peak_afl_search_algorithm.hpp:49
#define PEAK_COMMON_NO_DISCARD
Compatability macro for the nodiscard attribute.
Definition peak_common_defines.h:86
Interface definitions and implementations for individual module types used within a pipeline.
Definition peak_afl_generic_auto_brightness.hpp:39
Interfaces and implementations for defining and controlling data processing pipelines.
Definition peak_afl_generic_auto_brightness.hpp:37