24#if defined(__has_include)
25# if __has_include(<peak_icv/types/peak_icv_image.hpp>)
26# include <peak_icv/types/peak_icv_image.hpp>
27# define HAS_PEAK_ICV_IMAGE 1
31#include <peak_ipl/types/peak_ipl_image.hpp>
32#include <peak/device/peak_device.hpp>
33#include <peak/node_map/peak_node_map.hpp>
50class GenericAutoFeatures :
public IAutoFeature
52 static constexpr int moduleVersion = 1;
55 friend autofeature::BrightnessComponent;
57 explicit GenericAutoFeatures(
const std::shared_ptr<peak::core::Device>& device,
bool advanced =
true)
58 : m_remoteDeviceNodeMap{ device ? device->RemoteDevice()->NodeMaps().at(0) :
59 throw peak::common::InvalidParameterException(
"The given device is not valid!") }
60 , m_manager{ m_remoteDeviceNodeMap }
63 const auto isColorCamera = [
this]() {
64 const auto pixelFormatNode = m_remoteDeviceNodeMap->TryFindNode<peak::core::nodes::EnumerationNode>(
"PixelFormat");
65 if (pixelFormatNode ==
nullptr || !pixelFormatNode->IsReadable())
70 for (
const auto& entry : pixelFormatNode->AvailableEntries())
74 const auto pixelformat = peak::ipl::PixelFormat(
static_cast<peak::ipl::PixelFormatName
>(entry->Value()));
76 if (pixelformat.IsBayered())
81 catch (
const std::exception&)
90 for (
const auto& controllerType :
98 if (m_manager.IsControllerSupported(autofeature::detail::ToCType(controllerType)))
100 auto controller = CreateController(m_manager, controllerType, advanced);
101 m_controllers.emplace_back(std::move(controller));
105 m_manager.SetGainIPL(m_gain);
107 GenericAutoFeatures::ResetToDefault();
110 ~GenericAutoFeatures()
override =
default;
114 return "GenericAutoFeatures";
117 void SetEnabled(
bool enabled)
override
122 void Serialize(peak::common::serialization::IArchive& archive)
const override
124 archive.
SetInt(
"Version", moduleVersion);
125 archive.
SetBool(
"Enabled", m_enabled);
127 for (
const auto& controller : m_controllers)
130 controller->Serialize(*controllerArchive);
132 archive.
SetArchive(controller->GetName(), std::move(controllerArchive));
136 void Deserialize(
const peak::common::serialization::IArchive& archive)
override
138 const auto version{ archive.
GetInt(
"Version") };
141 throw peak::common::Exception(
"Version " + std::to_string(version) +
" is invalid. Must be at least 1");
144 m_enabled = archive.
GetBool(
"Enabled");
145 for (
const auto& controller : m_controllers)
147 auto controllerArchive = archive.
GetArchive(controller->GetName());
148 controller->Deserialize(*controllerArchive);
159 std::vector<autofeature::detail::IController*> controllers;
161 m_controllers.begin(), m_controllers.end(), std::back_inserter(controllers), [](
const auto& elem) { return elem.get(); });
167 const auto& controllers = GetControllers();
168 const auto result = std::find_if(
169 controllers.begin(), controllers.end(), [controllerType](
const auto* elem) { return elem->GetType() == controllerType; });
170 if (result != controllers.end())
180 const auto& controllers = GetControllers();
181 const auto result = std::find_if(
182 controllers.begin(), controllers.end(), [controllerType](
const auto* elem) { return elem->GetType() == controllerType; });
183 return result != controllers.end();
186 void ResetToDefault()
override
188 for (
auto* controller : GetControllers())
190 controller->ResetToDefault();
194 void SetGainModule(std::shared_ptr<peak::pipeline::modules::IGain> gainModule)
override
196 m_gainModule = gainModule;
199 void SetColorCorrectionMatrix(
const std::array<float, 9>& ccm)
override
201 m_manager.SetCCM(ccm);
211 const auto isProcessing = m_manager.Status();
217#if defined(HAS_PEAK_ICV_IMAGE) && defined(WITH_peak_ipl)
218 if (input.
GetType() ==
typeid(peak::icv::Image))
220 m_manager.Process(input.
AnyCast<peak::icv::Image>());
224 if (input.
GetType() ==
typeid(peak::ipl::Image))
226 m_manager.Process(input.
AnyCast<peak::ipl::Image>());
230 throw peak::common::InvalidCastException(
"Unsupported input type!");
240 switch (controllerType)
245 return std::make_unique<autofeature::AdvancedAutoFocus>(manager);
247 return std::make_unique<autofeature::BasicAutoFocus>(manager);
250 auto callback = [
this]() {
255 m_gainModule->SetMaster(m_gain.MasterGainValue());
260 return std::make_unique<autofeature::AdvancedAutoBrightness>(manager, callback);
262 return std::make_unique<autofeature::BasicAutoBrightness>(manager, callback);
266 auto callback = [
this]() {
272 m_gainModule->SetRed(m_gain.RedGainValue());
273 m_gainModule->SetGreen(m_gain.GreenGainValue());
274 m_gainModule->SetBlue(m_gain.BlueGainValue());
279 return std::make_unique<autofeature::AdvancedAutoWhiteBalance>(manager, callback);
281 return std::make_unique<autofeature::BasicAutoWhiteBalance>(manager, callback);
283 throw peak::common::InternalErrorException(
"Unknown controller type");
286 std::shared_ptr<peak::core::NodeMap> m_remoteDeviceNodeMap{};
288 std::vector<std::unique_ptr<autofeature::detail::IController>> m_controllers{};
289 peak::afl::Manager m_manager;
291 std::shared_ptr<modules::IGain> m_gainModule{};
292 peak::ipl::Gain m_gain{};
294 bool m_enabled{
true };
PEAK_COMMON_NO_DISCARD const std::type_info & GetType() const
Gets the type of the stored value.
Definition peak_common_any.hpp:164
T & AnyCast()
Casts the stored value to the specified type.
Definition peak_common_any.hpp:179
virtual PEAK_COMMON_NO_DISCARD bool GetBool(const std::string &key) const =0
Retrieves a boolean value by key.
virtual void SetBool(const std::string &key, bool value)=0
Stores a boolean value.
virtual PEAK_COMMON_NO_DISCARD std::shared_ptr< IArchive > GetArchive(const std::string &key) const =0
Retrieves a nested archive by key.
virtual void SetInt(const std::string &key, int64_t value)=0
Stores a 64-bit signed integer.
virtual PEAK_COMMON_NO_DISCARD std::shared_ptr< IArchive > CreateArchive() const =0
Creates a new, empty archive instance.
virtual PEAK_COMMON_NO_DISCARD int64_t GetInt(const std::string &key) const =0
Retrieves a 64-bit signed integer by key.
virtual void SetArchive(const std::string &key, const std::shared_ptr< IArchive > &value)=0
Stores a nested archive object.
ControllerType
Controller type enumeration.
Definition peak_afl_icontroller.hpp:41
@ WhiteBalance
Automatic white balance controller - manages color correction.
Definition peak_afl_icontroller.hpp:47
@ Brightness
Automatic brightness controller - manages exposure and gain.
Definition peak_afl_icontroller.hpp:45
@ Focus
Automatic focus controller - manages lens focus positioning.
Definition peak_afl_icontroller.hpp:43
#define PEAK_COMMON_NO_DISCARD
Compatability macro for the nodiscard attribute.
Definition peak_common_defines.hpp:91
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