20#if defined(__has_include)
21# if __has_include(<peak_icv/types/peak_icv_image.hpp>)
22# include <peak_icv/types/peak_icv_image.hpp>
23# define HAS_PEAK_ICV_IMAGE 1
27#include <peak_ipl/types/peak_ipl_image.hpp>
28#include <peak/device/peak_device.hpp>
29#include <peak/node_map/peak_node_map.hpp>
46class GenericAutoFeatures :
public IAutoFeature
48 static constexpr int moduleVersion = 1;
51 friend class autofeature::BrightnessComponent;
53 explicit GenericAutoFeatures(
const std::shared_ptr<peak::core::Device>& device,
bool advanced =
true)
54 : m_remoteDeviceNodeMap{ device ?
55 device->RemoteDevice()->NodeMaps().at(0) :
56 throw peak::afl::error::InvalidParameterException(
"The given device is not valid!",
PEAK_AFL_STATUS_ERROR) }
57 , m_manager{ m_remoteDeviceNodeMap }
59 const auto isColorCamera = [
this]() {
60 const auto pixelFormatNode = m_remoteDeviceNodeMap->TryFindNode<peak::core::nodes::EnumerationNode>(
"PixelFormat");
61 if (pixelFormatNode ==
nullptr || !pixelFormatNode->IsReadable())
66 for (
const auto& entry : pixelFormatNode->AvailableEntries())
77 catch (
const std::exception&)
86 for (
const auto& controllerType :
94 if (m_manager.IsControllerSupported(autofeature::detail::ToCType(controllerType)))
96 auto controller = CreateController(m_manager, controllerType, advanced);
97 m_controllers.emplace_back(std::move(controller));
101 m_manager.SetGainIPL(m_gain);
106 ~GenericAutoFeatures()
override =
default;
108 PEAK_COMMON_NO_DISCARD
const char*
GetType()
const override
110 return "GenericAutoFeatures";
113 void SetEnabled(
bool enabled)
override
118 void Serialize(peak::common::serialization::IArchive& archive)
const override
120 archive.
SetInt(
"Version", moduleVersion);
121 archive.
SetBool(
"Enabled", m_enabled);
123 for (
const auto& controller : m_controllers)
126 controller->Serialize(*controllerArchive);
128 archive.
SetArchive(controller->GetName(), std::move(controllerArchive));
132 void Deserialize(
const peak::common::serialization::IArchive& archive)
override
134 const auto version{ archive.
GetInt(
"Version") };
137 throw peak::afl::error::CorruptedDataException(
141 m_enabled = archive.
GetBool(
"Enabled");
142 for (
const auto& controller : m_controllers)
144 auto controllerArchive = archive.
GetArchive(controller->GetName());
145 controller->Deserialize(*controllerArchive);
149 PEAK_COMMON_NO_DISCARD
bool IsEnabled()
const override
154 PEAK_COMMON_NO_DISCARD std::vector<autofeature::detail::IController*> GetControllers()
const
156 std::vector<autofeature::detail::IController*> controllers;
158 m_controllers.begin(), m_controllers.end(), std::back_inserter(controllers), [](
const auto& elem) { return elem.get(); });
164 const auto& controllers = GetControllers();
165 const auto result = std::find_if(
166 controllers.begin(), controllers.end(), [controllerType](
const auto* elem) { return elem->GetType() == controllerType; });
167 if (result != controllers.end())
177 const auto& controllers = GetControllers();
178 const auto result = std::find_if(
179 controllers.begin(), controllers.end(), [controllerType](
const auto* elem) { return elem->GetType() == controllerType; });
180 return result != controllers.end();
185 for (
auto* controller : GetControllers())
187 controller->ResetToDefault();
191 void SetGainModule(std::shared_ptr<peak::pipeline::modules::IGain> gainModule)
override
193 m_gainModule = gainModule;
196 void SetColorCorrectionMatrix(
const std::array<float, 9>& ccm)
override
198 m_manager.SetCCM(ccm);
201 PEAK_COMMON_NO_DISCARD peak::common::Any Process(
const peak::common::Any& input)
const override
208 const auto isProcessing = m_manager.Status();
214#if defined(HAS_PEAK_ICV_IMAGE) && defined(WITH_peak_ipl)
215 if (input.
GetType() ==
typeid(peak::icv::Image))
217 m_manager.Process(input.
AnyCast<peak::icv::Image>());
221 if (input.
GetType() ==
typeid(peak::ipl::Image))
223 m_manager.Process(input.
AnyCast<peak::ipl::Image>());
234 PEAK_COMMON_NO_DISCARD std::unique_ptr<autofeature::detail::IController> CreateController(
237 switch (controllerType)
242 return std::make_unique<autofeature::AdvancedAutoFocus>(manager);
244 return std::make_unique<autofeature::BasicAutoFocus>(manager);
247 auto callback = [
this]() {
252 m_gainModule->SetMaster(m_gain.MasterGainValue());
257 return std::make_unique<autofeature::AdvancedAutoBrightness>(manager, callback);
259 return std::make_unique<autofeature::BasicAutoBrightness>(manager, callback);
263 auto callback = [
this]() {
269 m_gainModule->SetRed(m_gain.RedGainValue());
270 m_gainModule->SetGreen(m_gain.GreenGainValue());
271 m_gainModule->SetBlue(m_gain.BlueGainValue());
276 return std::make_unique<autofeature::AdvancedAutoWhiteBalance>(manager, callback);
278 return std::make_unique<autofeature::BasicAutoWhiteBalance>(manager, callback);
283 std::shared_ptr<peak::core::NodeMap> m_remoteDeviceNodeMap{};
285 std::vector<std::unique_ptr<autofeature::detail::IController>> m_controllers{};
286 peak::afl::Manager m_manager;
288 std::shared_ptr<modules::IGain> m_gainModule{};
289 peak::ipl::Gain m_gain{};
291 bool m_enabled{
true };
const std::type_info & GetType() const
Gets the type of the stored value.
Definition peak_common_any.hpp:159
T & AnyCast()
Casts the stored value to the specified type.
Definition peak_common_any.hpp:174
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:416
@ PEAK_AFL_STATUS_ERROR
General error occurred.
Definition peak_afl.h:396
ControllerType
Controller type enumeration.
Definition peak_afl_icontroller.hpp:36
@ WhiteBalance
Automatic white balance controller - manages color correction.
Definition peak_afl_icontroller.hpp:42
@ Brightness
Automatic brightness controller - manages exposure and gain.
Definition peak_afl_icontroller.hpp:40
@ Focus
Automatic focus controller - manages lens focus positioning.
Definition peak_afl_icontroller.hpp:38
PixelFormat
Enum listing all supported pixel formats and their internal IDs.
Definition peak_common_pixel_format.hpp:59
@ Bayer
Definition peak_common_channel.hpp:37
Interface definitions and implementations for individual module types used within a pipeline.
Definition peak_afl_generic_auto_brightness.hpp:35
Interfaces and implementations for defining and controlling data processing pipelines.
Definition peak_afl_generic_auto_brightness.hpp:33