IDS peak AFL v2.0.2
Loading...
Searching...
No Matches
peak_afl_basic_auto_brightness.hpp
Go to the documentation of this file.
1
10
11#pragma once
12
13#include <peak_afl/peak_afl.hpp>
22
25
26#include <utility>
27#include <vector>
28
29namespace peak
30{
31namespace pipeline
32{
33namespace modules
34{
35namespace autofeature
36{
37
57
70PEAK_COMMON_NO_DISCARD inline std::string ToString(AutoBrightnessPolicy policy)
71{
72 switch (policy)
73 {
75 return "ExposureAndGain";
77 return "ExposureOnly";
79 return "GainOnly";
80 }
81
83}
84
85inline std::ostream& operator<<(std::ostream& os, AutoBrightnessPolicy policy)
86{
87 return os << ToString(policy);
88}
89
90namespace detail
91{
92
93PEAK_COMMON_NO_DISCARD inline AutoBrightnessPolicy ToAutoBrightnessPolicy(const std::string& name)
94{
95 if (name == "ExposureAndGain")
96 {
98 }
99 if (name == "ExposureOnly")
100 {
102 }
103 if (name == "GainOnly")
104 {
106 }
107
108 throw peak::afl::error::InternalErrorException("Invalid brightness policy!", PEAK_AFL_STATUS_ERROR);
109}
110} // namespace detail
147{
148 using ProcessingCallback = std::function<void()>;
149
150public:
151 friend BrightnessComponent;
152
169 explicit BasicAutoBrightness(peak::afl::Manager& manager, ProcessingCallback callback)
170 : IController(manager)
171 , m_genericController{ manager, std::move(callback), { BrightnessComponentType::Exposure, BrightnessComponentType::Gain } }
172 {}
173
180 ~BasicAutoBrightness() override = default;
181
201 void SetMode(ControllerMode mode) override
202 {
203 auto* exposureComponent = GetExposureComponent();
204 if (exposureComponent != nullptr)
205 {
206 const auto controllerMode = (m_policy == AutoBrightnessPolicy::ExposureOnly
208 mode :
210
211 exposureComponent->SetMode(controllerMode);
212 }
213
214 auto* gainComponent = GetGainComponent();
215 if (gainComponent != nullptr)
216 {
217 const auto controllerMode = (m_policy == AutoBrightnessPolicy::GainOnly || m_policy == AutoBrightnessPolicy::ExposureAndGain) ?
218 mode :
220
221 gainComponent->SetMode(controllerMode);
222 }
223
224 m_cachedMode = mode;
225 }
226
244 PEAK_COMMON_NO_DISCARD ControllerMode GetMode() const override
245 {
246 auto* const exposureComponent = GetExposureComponent();
247 if (exposureComponent != nullptr)
248 {
249 if (exposureComponent->GetMode() == ControllerMode::Continuous)
250 {
252 }
253 }
254
255 auto* const gainComponent = GetGainComponent();
256 if (gainComponent != nullptr)
257 {
258 return gainComponent->GetMode();
259 }
260
261 return ControllerMode::Off;
262 }
263
275 PEAK_COMMON_NO_DISCARD bool IsRunning() const override
276 {
277 return GetMode() != ControllerMode::Off;
278 }
279
295 {
296 m_genericController.AnalysisAlgorithm().Set(algorithm);
297 }
298
311 {
312 return m_genericController.AnalysisAlgorithm().Get();
313 }
314
330 void SetAutoPercentile(double value)
331 {
332 m_genericController.AutoPercentile().Set(value);
333 }
334
346 PEAK_COMMON_NO_DISCARD double GetAutoPercentile() const
347 {
348 return m_genericController.AutoPercentile().Get();
349 }
350
362 PEAK_COMMON_NO_DISCARD RangeD GetAutoPercentileRange() const
363 {
364 return m_genericController.AutoPercentile().GetRange();
365 }
366
382 void SetAutoTarget(uint32_t value)
383 {
384 m_genericController.AutoTarget().Set(value);
385 }
386
398 PEAK_COMMON_NO_DISCARD uint32_t GetAutoTarget() const
399 {
400 return m_genericController.AutoTarget().Get();
401 }
402
414 PEAK_COMMON_NO_DISCARD peak::common::RangeU GetAutoTargetRange() const
415 {
416 return m_genericController.AutoTarget().GetRange();
417 }
418
435 void SetAutoTolerance(uint32_t value)
436 {
437 m_genericController.AutoTolerance().Set(value);
438 }
439
451 PEAK_COMMON_NO_DISCARD uint32_t GetAutoTolerance() const
452 {
453 return m_genericController.AutoTolerance().Get();
454 }
455
467 PEAK_COMMON_NO_DISCARD peak::common::RangeU GetAutoToleranceRange() const
468 {
469 return m_genericController.AutoTolerance().GetRange();
470 }
471
488 void SetSkipFrames(uint32_t value)
489 {
490 m_genericController.SkipFrames().Set(value);
491 }
492
504 PEAK_COMMON_NO_DISCARD uint32_t GetSkipFrames() const
505 {
506 return m_genericController.SkipFrames().Get();
507 }
508
520 PEAK_COMMON_NO_DISCARD peak::common::RangeU GetSkipFramesRange() const
521 {
522 return m_genericController.SkipFrames().GetRange();
523 }
524
541 {
542 m_genericController.Roi().Set(roi);
543 }
544
556 PEAK_COMMON_NO_DISCARD peak::common::Rectangle GetRoi()
557 {
558 return m_genericController.Roi().Get();
559 }
560
579 {
580 m_policy = policy;
581 SetMode(m_cachedMode);
582 }
583
595 PEAK_COMMON_NO_DISCARD AutoBrightnessPolicy GetPolicy() const
596 {
597 return m_policy;
598 }
599
617 void ResetToDefault() override
618 {
620 m_cachedMode = ControllerMode::Off;
621 m_genericController.ResetToDefault();
622 }
623
641 IController::FinishedCallbackHandle RegisterFinishedCallback(const IController::FinishedCallback& callback)
642 {
643 return m_genericController.RegisterFinishedCallback(callback);
644 }
645
658 void UnregisterFinishedCallback(IController::FinishedCallbackHandle callbackHandle)
659 {
660 m_genericController.UnregisterFinishedCallback(callbackHandle);
661 }
662
680 void SetExposureLimit(const IntervalD& interval)
681 {
682 auto* component = GetExposureComponent();
683 if (component == nullptr)
684 {
686 "Exposure component is not supported for the current device!", PEAK_AFL_STATUS_NOT_SUPPORTED);
687 }
688
689 component->SetLimit(interval);
690 }
691
705 PEAK_COMMON_NO_DISCARD IntervalD GetExposureLimit() const
706 {
707 auto* component = GetExposureComponent();
708 if (component != nullptr)
709 {
710 return component->GetLimit();
711 }
712
714 "Exposure component is not supported for the current device!", PEAK_AFL_STATUS_NOT_SUPPORTED);
715 }
716
734 void SetGainLimit(const IntervalD& interval)
735 {
736 auto* component = GetGainComponent();
737 if (component == nullptr)
738 {
740 "Gain component is not supported for the current device!", PEAK_AFL_STATUS_NOT_SUPPORTED);
741 }
742
743 component->SetLimit(interval);
744 }
745
759 PEAK_COMMON_NO_DISCARD IntervalD GetGainLimit() const
760 {
761 auto* component = GetGainComponent();
762 if (component != nullptr)
763 {
764 return component->GetLimit();
765 }
766
768 "Gain component is not supported for the current device!", PEAK_AFL_STATUS_NOT_SUPPORTED);
769 }
770
771private:
773 detail::GenericAutoBrightness m_genericController;
774 ControllerMode m_cachedMode{ ControllerMode::Off };
775
784 BrightnessComponent* GetExposureComponent() const
785 {
786 return m_genericController.GetComponent(BrightnessComponentType::Exposure);
787 }
788
797 BrightnessComponent* GetGainComponent() const
798 {
799 return m_genericController.GetComponent(BrightnessComponentType::Gain);
800 }
801
810 PEAK_COMMON_NO_DISCARD std::string GetName() const override
811 {
812 return "BasicAutoBrightness";
813 }
814
827 void Serialize(peak::common::serialization::IArchive& archive) const override
828 {
829 m_genericController.Serialize(archive);
830
831 archive.SetString("Policy", ToString(m_policy));
832 }
833
847 void Deserialize(const peak::common::serialization::IArchive& archive) override
848 {
849 m_genericController.Deserialize(archive);
850
851 m_cachedMode = GetMode();
852 SetPolicy(detail::ToAutoBrightnessPolicy(archive.GetString("Policy")));
853 }
854
863 PEAK_COMMON_NO_DISCARD ControllerType GetType() const override
864 {
865 return m_genericController.GetType();
866 }
867};
868
869} // namespace autofeature
870} // namespace modules
871} // namespace pipeline
872} // namespace peak
Central coordination object for automatic camera feature control.
Definition peak_afl.hpp:663
The exception thrown for passing an invalid parameter to a function.
Definition peak_afl.hpp:391
The exception thrown when a functionality is not supported.
Definition peak_afl.hpp:416
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.
void SetRoi(const peak::common::Rectangle &roi)
Sets the region of interest (ROI) for selective brightness analysis.
Definition peak_afl_basic_auto_brightness.hpp:540
void UnregisterFinishedCallback(IController::FinishedCallbackHandle callbackHandle)
Unregisters a previously registered completion callback.
Definition peak_afl_basic_auto_brightness.hpp:658
peak::common::RangeU GetSkipFramesRange() const
Gets the valid range for skip frames values.
Definition peak_afl_basic_auto_brightness.hpp:520
peak::common::RangeU GetAutoToleranceRange() const
Gets the valid range for tolerance values.
Definition peak_afl_basic_auto_brightness.hpp:467
BrightnessAnalysisAlgorithm GetAnalysisAlgorithm() const
Gets the current brightness analysis algorithm.
Definition peak_afl_basic_auto_brightness.hpp:310
BasicAutoBrightness(peak::afl::Manager &manager, ProcessingCallback callback)
Constructs a BasicAutoBrightness controller with the specified manager and callback.
Definition peak_afl_basic_auto_brightness.hpp:169
void SetAutoTarget(uint32_t value)
Sets the target brightness value.
Definition peak_afl_basic_auto_brightness.hpp:382
void SetGainLimit(const IntervalD &interval)
Sets the gain limits for the gain component.
Definition peak_afl_basic_auto_brightness.hpp:734
void SetAutoTolerance(uint32_t value)
Sets the tolerance value for brightness stability control.
Definition peak_afl_basic_auto_brightness.hpp:435
ControllerMode GetMode() const override
Gets the current operation mode of the brightness controller.
Definition peak_afl_basic_auto_brightness.hpp:244
uint32_t GetSkipFrames() const
Gets the current number of frames to skip.
Definition peak_afl_basic_auto_brightness.hpp:504
uint32_t GetAutoTolerance() const
Gets the current tolerance value for brightness stability control.
Definition peak_afl_basic_auto_brightness.hpp:451
peak::common::Rectangle GetRoi()
Gets the current region of interest (ROI) for brightness analysis.
Definition peak_afl_basic_auto_brightness.hpp:556
void SetExposureLimit(const IntervalD &interval)
Sets the exposure time limits for the exposure component.
Definition peak_afl_basic_auto_brightness.hpp:680
IController::FinishedCallbackHandle RegisterFinishedCallback(const IController::FinishedCallback &callback)
Registers a callback function to be invoked when brightness adjustment completes.
Definition peak_afl_basic_auto_brightness.hpp:641
void SetPolicy(AutoBrightnessPolicy policy)
Sets the brightness adjustment policy.
Definition peak_afl_basic_auto_brightness.hpp:578
uint32_t GetAutoTarget() const
Gets the current target brightness value.
Definition peak_afl_basic_auto_brightness.hpp:398
void SetMode(ControllerMode mode) override
Sets the operation mode for the brightness controller.
Definition peak_afl_basic_auto_brightness.hpp:201
void SetAutoPercentile(double value)
Sets the percentile value for brightness calculation.
Definition peak_afl_basic_auto_brightness.hpp:330
AutoBrightnessPolicy GetPolicy() const
Gets the current brightness adjustment policy.
Definition peak_afl_basic_auto_brightness.hpp:595
double GetAutoPercentile() const
Gets the current percentile value for brightness calculation.
Definition peak_afl_basic_auto_brightness.hpp:346
IntervalD GetGainLimit() const
Gets the current gain limits for the gain component.
Definition peak_afl_basic_auto_brightness.hpp:759
void SetSkipFrames(uint32_t value)
Sets the number of frames to skip for performance optimization.
Definition peak_afl_basic_auto_brightness.hpp:488
IntervalD GetExposureLimit() const
Gets the current exposure time limits for the exposure component.
Definition peak_afl_basic_auto_brightness.hpp:705
void ResetToDefault() override
Resets all controller settings to their default values.
Definition peak_afl_basic_auto_brightness.hpp:617
peak::common::RangeU GetAutoTargetRange() const
Gets the valid range for target brightness values.
Definition peak_afl_basic_auto_brightness.hpp:414
bool IsRunning() const override
Checks if the brightness controller is currently running.
Definition peak_afl_basic_auto_brightness.hpp:275
void SetAnalysisAlgorithm(BrightnessAnalysisAlgorithm algorithm)
Sets the brightness analysis algorithm.
Definition peak_afl_basic_auto_brightness.hpp:294
RangeD GetAutoPercentileRange() const
Gets the valid range for percentile values.
Definition peak_afl_basic_auto_brightness.hpp:362
~BasicAutoBrightness() override=default
Destructor for BasicAutoBrightness.
Abstract base interface for all automatic controllers.
Definition peak_afl_icontroller.hpp:227
@ PEAK_AFL_STATUS_NOT_SUPPORTED
Feature or operation not supported.
Definition peak_afl.h:465
@ PEAK_AFL_STATUS_INVALID_PARAMETER
Invalid parameter provided.
Definition peak_afl.h:419
@ PEAK_AFL_STATUS_ERROR
General error occurred.
Definition peak_afl.h:399
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
@ Continuous
Continuous operation - automatic processing on every frame.
Definition peak_afl_icontroller.hpp:63
@ Off
Controller is disabled - no automatic processing.
Definition peak_afl_icontroller.hpp:61
AutoBrightnessPolicy
Auto brightness control policy enumeration.
Definition peak_afl_basic_auto_brightness.hpp:49
BrightnessAnalysisAlgorithm
Brightness analysis algorithm enumeration.
Definition peak_afl_brightness_algorithm.hpp:40
@ GainOnly
Use only gain adjustments, keeping exposure time constant.
Definition peak_afl_basic_auto_brightness.hpp:55
@ ExposureOnly
Use only exposure time adjustments, keeping gain constant.
Definition peak_afl_basic_auto_brightness.hpp:53
@ ExposureAndGain
Use both exposure time and gain adjustments for optimal brightness control.
Definition peak_afl_basic_auto_brightness.hpp:51
@ Gain
Automatic gain component - automatic gain control.
Definition peak_afl_brightness_component.hpp:52
@ Exposure
Exposure time component - controls sensor integration time.
Definition peak_afl_brightness_component.hpp:42
detail::RectangleT< int32_t, uint32_t > Rectangle
Rectangle with integer coordinates and unsigned dimensions.
Definition peak_common_rectangle.hpp:236
detail::RangeT< uint32_t > RangeU
Alias for a range of 32-bit unsigned integers.
Definition peak_common_range.hpp:172
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
peak::common::detail::RangeT< double > RangeD
Type alias for double-precision range values.
Definition peak_afl_ifeature.hpp:26
peak::common::detail::IntervalT< double > IntervalD
Type alias for double-precision interval values.
Definition peak_afl_ifeature.hpp:28