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 class autofeature::BrightnessComponent;
57 explicit GenericAutoFeatures(
const std::shared_ptr<peak::core::Device>& device,
bool advanced =
true)
58 : m_remoteDeviceNodeMap{ device ?
59 device->RemoteDevice()->NodeMaps().at(0) :
60 throw peak::afl::error::InvalidParameterException(
"The given device is not valid!",
PEAK_AFL_STATUS_ERROR) }
61 , 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())
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);
110 ~GenericAutoFeatures()
override =
default;
112 PEAK_COMMON_NO_DISCARD
const char*
GetType()
const override
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::afl::error::CorruptedDataException(
145 m_enabled = archive.
GetBool(
"Enabled");
146 for (
const auto& controller : m_controllers)
148 auto controllerArchive = archive.
GetArchive(controller->GetName());
149 controller->Deserialize(*controllerArchive);
153 PEAK_COMMON_NO_DISCARD
bool IsEnabled()
const override
158 PEAK_COMMON_NO_DISCARD std::vector<autofeature::detail::IController*> GetControllers()
const
160 std::vector<autofeature::detail::IController*> controllers;
162 m_controllers.begin(), m_controllers.end(), std::back_inserter(controllers), [](
const auto& elem) { return elem.get(); });
168 const auto& controllers = GetControllers();
169 const auto result = std::find_if(
170 controllers.begin(), controllers.end(), [controllerType](
const auto* elem) { return elem->GetType() == controllerType; });
171 if (result != controllers.end())
181 const auto& controllers = GetControllers();
182 const auto result = std::find_if(
183 controllers.begin(), controllers.end(), [controllerType](
const auto* elem) { return elem->GetType() == controllerType; });
184 return result != controllers.end();
189 for (
auto* controller : GetControllers())
191 controller->ResetToDefault();
195 void SetGainModule(std::shared_ptr<peak::pipeline::modules::IGain> gainModule)
override
197 m_gainModule = gainModule;
200 void SetColorCorrectionMatrix(
const std::array<float, 9>& ccm)
override
202 m_manager.SetCCM(ccm);
205 PEAK_COMMON_NO_DISCARD peak::common::Any Process(
const peak::common::Any& input)
const override
212 const auto isProcessing = m_manager.Status();
218#if defined(HAS_PEAK_ICV_IMAGE) && defined(WITH_peak_ipl)
219 if (input.
GetType() ==
typeid(peak::icv::Image))
221 m_manager.Process(input.
AnyCast<peak::icv::Image>());
225 if (input.
GetType() ==
typeid(peak::ipl::Image))
227 m_manager.Process(input.
AnyCast<peak::ipl::Image>());
238 PEAK_COMMON_NO_DISCARD std::unique_ptr<autofeature::detail::IController> CreateController(
241 switch (controllerType)
246 return std::make_unique<autofeature::AdvancedAutoFocus>(manager);
248 return std::make_unique<autofeature::BasicAutoFocus>(manager);
251 auto callback = [
this]() {
256 m_gainModule->SetMaster(m_gain.MasterGainValue());
261 return std::make_unique<autofeature::AdvancedAutoBrightness>(manager, callback);
263 return std::make_unique<autofeature::BasicAutoBrightness>(manager, callback);
267 auto callback = [
this]() {
273 m_gainModule->SetRed(m_gain.RedGainValue());
274 m_gainModule->SetGreen(m_gain.GreenGainValue());
275 m_gainModule->SetBlue(m_gain.BlueGainValue());
280 return std::make_unique<autofeature::AdvancedAutoWhiteBalance>(manager, callback);
282 return std::make_unique<autofeature::BasicAutoWhiteBalance>(manager, callback);
287 std::shared_ptr<peak::core::NodeMap> m_remoteDeviceNodeMap{};
289 std::vector<std::unique_ptr<autofeature::detail::IController>> m_controllers{};
290 peak::afl::Manager m_manager;
292 std::shared_ptr<modules::IGain> m_gainModule{};
293 peak::ipl::Gain m_gain{};
295 bool m_enabled{
true };
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 void SetBool(const std::string &key, bool value)=0
Stores a boolean value.
virtual 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 int64_t GetInt(const std::string &key) const =0
Retrieves a 64-bit signed integer by key.
virtual bool GetBool(const std::string &key) const =0
Retrieves a boolean value by key.
virtual std::shared_ptr< IArchive > CreateArchive() const =0
Creates a new, empty archive instance.
virtual void SetArchive(const std::string &key, const std::shared_ptr< IArchive > &value)=0
Stores a nested archive object.
virtual void ResetToDefault()=0
Resets the module to its default state. The enabled state is not reset.
virtual bool IsEnabled() const =0
Checks whether the module is currently enabled.
virtual const char * GetType() const =0
Returns the type identifier of the module.
@ 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
ControllerType
Controller type enumeration.
Definition peak_afl_icontroller.hpp:40
@ WhiteBalance
Automatic white balance controller - manages color correction.
Definition peak_afl_icontroller.hpp:46
@ Brightness
Automatic brightness controller - manages exposure and gain.
Definition peak_afl_icontroller.hpp:44
@ Focus
Automatic focus controller - manages lens focus positioning.
Definition peak_afl_icontroller.hpp:42
PixelFormat
Enum listing all supported pixel formats and their internal IDs.
Definition peak_common_pixel_format.hpp:64
@ Bayer
Definition peak_common_channel.hpp:42
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