IDS peak AFL v2.0.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{
60class Roi : public IFeature<peak::common::Rectangle>
61{
62public:
75 explicit Roi(std::shared_ptr<peak::afl::Controller> controller)
76 : m_controller{ std::move(controller) }
77 {}
78
98 void Set(const peak::common::Rectangle& value) override
99 {
100 if (value.GetX() < 0 || value.GetY() < 0)
101 {
103 "Negative x or y is not supported!", PEAK_AFL_STATUS_INVALID_PARAMETER);
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} // namespace features
199} // namespace autofeature
200} // namespace modules
201} // namespace pipeline
202} // namespace peak
The exception thrown for passing an invalid parameter to a function.
Definition peak_afl.hpp:391
Interface for a hierarchical key-value archive system.
Definition peak_common_iarchive.hpp:59
virtual std::shared_ptr< IArchive > GetArchive(const std::string &key) const =0
Retrieves a nested archive 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.
Base interface for auto feature implementations.
Definition peak_afl_ifeature.hpp:59
peak::common::Rectangle Get() const override
Gets the current region of interest rectangle.
Definition peak_afl_roi.hpp:126
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:75
void Deserialize(const peak::common::serialization::IArchive &archive) override
Deserializes the ROI from an archive.
Definition peak_afl_roi.hpp:176
void Set(const peak::common::Rectangle &value) override
Sets the region of interest rectangle.
Definition peak_afl_roi.hpp:98
@ PEAK_AFL_STATUS_INVALID_PARAMETER
Invalid parameter provided.
Definition peak_afl.h:419
#define PEAK_COMMON_NO_DISCARD
Compatability macro for the nodiscard attribute.
Definition peak_common_defines.h:86
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