IDS peak AFL v1.8.0
Loading...
Searching...
No Matches
peak_afl_roi.hpp
Go to the documentation of this file.
1
10
11#pragma once
12
13#include <peak_afl/peak_afl.hpp>
15
18
19#include <memory>
20
21namespace peak
22{
23namespace pipeline
24{
25namespace modules
26{
27namespace autofeature
28{
29namespace features
30{
31
61class Roi : public IFeature<peak::common::Rectangle>
62{
63public:
76 explicit Roi(std::shared_ptr<peak::afl::Controller> controller)
77 : m_controller{ std::move(controller) }
78 {}
79
99 void Set(const peak::common::Rectangle& value) override
100 {
101 if (value.GetX() < 0 || value.GetY() < 0)
102 {
103 throw peak::common::InvalidParameterException("Negative x or y is not supported!");
104 }
105
106 m_controller->SetROI(
107 { static_cast<uint32_t>(value.GetX()), static_cast<uint32_t>(value.GetY()), value.GetWidth(), value.GetHeight() });
108 }
109
127 {
128 const auto result = m_controller->GetROI();
129 return { static_cast<int32_t>(result.x), static_cast<int32_t>(result.y), result.width, result.height };
130 }
131
148 {
149 auto subArchive = archive.CreateArchive();
150
151 const auto roi = Get();
152 subArchive->SetInt("X", roi.GetX());
153 subArchive->SetInt("Y", roi.GetY());
154 subArchive->SetInt("Width", roi.GetWidth());
155 subArchive->SetInt("Height", roi.GetHeight());
156
157 archive.SetArchive("Roi", subArchive);
158 }
159
177 {
178 const auto subArchive = archive.GetArchive("Roi");
179
180 const auto x = static_cast<int32_t>(subArchive->GetInt("X"));
181 const auto y = static_cast<int32_t>(subArchive->GetInt("Y"));
182 const auto width = static_cast<uint32_t>(subArchive->GetInt("Width"));
183 const auto height = static_cast<uint32_t>(subArchive->GetInt("Height"));
184
185 Set({ x, y, width, height });
186 }
187
188private:
196 std::shared_ptr<peak::afl::Controller> m_controller;
197};
198
199} // namespace features
200} // namespace autofeature
201} // namespace modules
202} // namespace pipeline
203} // namespace peak
Thrown when a function receives an invalid parameter.
Definition peak_common_exceptions.hpp:50
Interface for a hierarchical key-value archive system.
Definition peak_common_iarchive.hpp:59
virtual PEAK_COMMON_NO_DISCARD std::shared_ptr< IArchive > GetArchive(const std::string &key) const =0
Retrieves a nested archive by key.
virtual PEAK_COMMON_NO_DISCARD 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.
Base interface for auto feature implementations.
Definition peak_afl_ifeature.hpp:61
void Serialize(peak::common::serialization::IArchive &archive) const override
Serializes the current ROI to an archive.
Definition peak_afl_roi.hpp:147
Roi(std::shared_ptr< peak::afl::Controller > controller)
Constructs a Roi feature with the specified controller.
Definition peak_afl_roi.hpp:76
void Deserialize(const peak::common::serialization::IArchive &archive) override
Deserializes the ROI from an archive.
Definition peak_afl_roi.hpp:176
PEAK_COMMON_NO_DISCARD peak::common::Rectangle Get() const override
Gets the current region of interest rectangle.
Definition peak_afl_roi.hpp:126
void Set(const peak::common::Rectangle &value) override
Sets the region of interest rectangle.
Definition peak_afl_roi.hpp:99
#define PEAK_COMMON_NO_DISCARD
Compatability macro for the nodiscard attribute.
Definition peak_common_defines.hpp:91
detail::RectangleT< int32_t, uint32_t > Rectangle
Rectangle with integer coordinates and unsigned dimensions.
Definition peak_common_rectangle.hpp:235
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