IDS peak AFL v2.0.0
Loading...
Searching...
No Matches
peak_afl_weighted_rois.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{
39enum class Weight
40{
47};
48
63
82
95PEAK_COMMON_NO_DISCARD inline std::string ToString(Weight weight)
96{
97 switch (weight)
98 {
99 case Weight::Weak:
100 return "Weak";
101 case Weight::Medium:
102 return "Medium";
103 case Weight::Strong:
104 return "Strong";
105 }
106
108}
109
128inline std::ostream& operator<<(std::ostream& os, Weight weight)
129{
130 return os << ToString(weight);
131}
132
133namespace features
134{
135namespace detail
136{
137PEAK_COMMON_NO_DISCARD inline Weight ToWeight(const std::string& name)
138{
139 if (name == "Weak")
140 {
141 return Weight::Weak;
142 }
143 if (name == "Medium")
144 {
145 return Weight::Medium;
146 }
147 if (name == "Strong")
148 {
149 return Weight::Strong;
150 }
152}
153
155{
156 switch (weight)
157 {
158 case Weight::Weak:
160 case Weight::Medium:
162 case Weight::Strong:
164 }
165
166 throw peak::afl::error::InternalErrorException("Invalid weight!", PEAK_AFL_STATUS_ERROR);
167}
168
170{
171 switch (weight)
172 {
174 return Weight::Weak;
176 return Weight::Medium;
178 return Weight::Strong;
179 }
180
181 throw peak::afl::error::InternalErrorException("Invalid weight!", PEAK_AFL_STATUS_ERROR);
182}
183
184PEAK_COMMON_NO_DISCARD inline peak_afl_weighted_rectangle ToCType(WeightedROI roi)
185{
186 peak_afl_weighted_rectangle result;
187 result.roi.x = static_cast<uint32_t>(roi.rect.GetX());
188 result.roi.y = static_cast<uint32_t>(roi.rect.GetY());
189 result.roi.width = roi.rect.GetWidth();
190 result.roi.height = roi.rect.GetHeight();
191 result.weight = ToCType(roi.weight);
192 return result;
193}
194
195PEAK_COMMON_NO_DISCARD inline WeightedROI ToWeightedROI(peak_afl_weighted_rectangle roi)
196{
197 const peak::common::Rectangle rect{ { static_cast<int32_t>(roi.roi.x), static_cast<int32_t>(roi.roi.y) },
198 { roi.roi.width, roi.roi.height } };
199 const auto weight = ToWeight(roi.weight);
200 return { rect, weight };
201}
202} // namespace detail
203
236class WeightedRois : public IFeature<std::vector<WeightedROI>>
237{
238public:
251 explicit WeightedRois(std::shared_ptr<peak::afl::Controller> controller)
252 : m_controller{ std::move(controller) }
253 {}
254
272 void Set(const WeightedROI& value)
273 {
274 m_controller->SetWeightedROI(detail::ToCType(value));
275 }
276
295 void Set(const std::vector<WeightedROI>& value) override
296 {
297 std::vector<peak_afl_weighted_rectangle> cRois;
298 cRois.reserve(value.size());
299 std::transform(value.cbegin(), value.cend(), std::back_inserter(cRois), [](const auto& roi) { return detail::ToCType(roi); });
300 m_controller->SetWeightedROIs(cRois);
301 }
302
313 void SetPreset(RoiPreset preset)
314 {
315 m_controller->SetROIPreset(static_cast<peak_afl_roi_preset>(preset));
316 }
317
333 PEAK_COMMON_NO_DISCARD std::vector<WeightedROI> Get() const override
334 {
335 const auto cRois = m_controller->GetWeightedROIs();
336
337 std::vector<WeightedROI> rois;
338 rois.reserve(cRois.size());
339 std::transform(
340 cRois.cbegin(), cRois.cend(), std::back_inserter(rois), [](const auto& cRoi) { return detail::ToWeightedROI(cRoi); });
341 return rois;
342 }
343
360 {
361 std::vector<std::shared_ptr<peak::common::serialization::IArchive>> archives;
362 const auto weightedRois = Get();
363 for (const auto& roi : weightedRois)
364 {
365 auto subArchives = archive.CreateArchive();
366 subArchives->SetInt("X", roi.rect.GetX());
367 subArchives->SetInt("Y", roi.rect.GetY());
368 subArchives->SetInt("Width", roi.rect.GetWidth());
369 subArchives->SetInt("Height", roi.rect.GetHeight());
370 subArchives->SetString("Weight", ToString(roi.weight));
371
372 archives.push_back(subArchives);
373 }
374
375 archive.SetArchiveArray("WeightedRois", archives);
376 }
377
395 {
396 std::vector<WeightedROI> rois;
397 const auto archives = archive.GetArchiveArray("WeightedRois");
398 for (const auto& subArchive : archives)
399 {
401 roi.roi.x = static_cast<uint32_t>(subArchive->GetInt("X"));
402 roi.roi.y = static_cast<uint32_t>(subArchive->GetInt("Y"));
403 roi.roi.width = static_cast<uint32_t>(subArchive->GetInt("Width"));
404 roi.roi.height = static_cast<uint32_t>(subArchive->GetInt("Height"));
405 roi.weight = detail::ToCType(detail::ToWeight(subArchive->GetString("Weight")));
406 rois.emplace_back(detail::ToWeightedROI(roi));
407 }
408
409 Set(rois);
410 }
411
412private:
420 std::shared_ptr<peak::afl::Controller> m_controller;
421};
422} // namespace features
423} // namespace autofeature
424} // namespace modules
425} // namespace pipeline
426} // namespace peak
The exception thrown for signaling an unspecified error.
Definition peak_afl.hpp:340
Interface for a hierarchical key-value archive system.
Definition peak_common_iarchive.hpp:59
virtual std::vector< std::shared_ptr< IArchive > > GetArchiveArray(const std::string &key) const =0
Retrieves an array of nested archives by key.
virtual void SetArchiveArray(const std::string &key, const std::vector< std::shared_ptr< IArchive > > &value)=0
Stores an array of nested archives.
virtual std::shared_ptr< IArchive > CreateArchive() const =0
Creates a new, empty archive instance.
Base interface for auto feature implementations.
Definition peak_afl_ifeature.hpp:59
void Set(const std::vector< WeightedROI > &value) override
Sets multiple weighted regions of interest.
Definition peak_afl_weighted_rois.hpp:295
std::vector< WeightedROI > Get() const override
Gets the current weighted regions of interest.
Definition peak_afl_weighted_rois.hpp:333
WeightedRois(std::shared_ptr< peak::afl::Controller > controller)
Constructs a WeightedRois feature with the specified controller.
Definition peak_afl_weighted_rois.hpp:251
void Serialize(peak::common::serialization::IArchive &archive) const override
Serializes the current weighted ROIs to an archive.
Definition peak_afl_weighted_rois.hpp:359
void Set(const WeightedROI &value)
Sets a single weighted region of interest.
Definition peak_afl_weighted_rois.hpp:272
void Deserialize(const peak::common::serialization::IArchive &archive) override
Deserializes weighted ROIs from an archive.
Definition peak_afl_weighted_rois.hpp:394
void SetPreset(RoiPreset preset)
Sets a predefined region of interest (ROI)
Definition peak_afl_weighted_rois.hpp:313
peak_afl_roi_preset
Predefined ROI preset configurations.
Definition peak_afl.h:1410
@ PEAK_AFL_CONTROLLER_ROI_PRESET_CENTER
Center region preset.
Definition peak_afl.h:1420
@ PEAK_AFL_STATUS_ERROR
General error occurred.
Definition peak_afl.h:399
peak_afl_roi_weight
ROI weight values for focus control.
Definition peak_afl.h:1038
@ PEAK_AFL_CONTROLLER_ROI_WEIGHT_WEAK
Low importance weight.
Definition peak_afl.h:1045
@ PEAK_AFL_CONTROLLER_ROI_WEIGHT_STRONG
High importance weight.
Definition peak_afl.h:1061
@ PEAK_AFL_CONTROLLER_ROI_WEIGHT_MEDIUM
Medium importance weight.
Definition peak_afl.h:1053
std::string ToString(ControllerType mode)
Converts ControllerType enumeration to string representation.
Definition peak_afl_icontroller.hpp:78
RoiPreset
Preset enumeration for the Region of interest.
Definition peak_afl_weighted_rois.hpp:59
Weight
Weight enumeration for weighted regions of interest.
Definition peak_afl_weighted_rois.hpp:40
@ Center
Sets a centered ROI that is one-third of the image dimensions.
Definition peak_afl_weighted_rois.hpp:61
@ Weak
Low importance - minimal influence on auto algorithms.
Definition peak_afl_weighted_rois.hpp:42
@ Medium
Normal importance - standard influence on auto algorithms.
Definition peak_afl_weighted_rois.hpp:44
@ Strong
High importance - strong influence on auto algorithms.
Definition peak_afl_weighted_rois.hpp:46
#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
Weighted region of interest structure.
Definition peak_afl_weighted_rois.hpp:75
peak::common::Rectangle rect
The rectangular region of interest.
Definition peak_afl_weighted_rois.hpp:77
Weight weight
The importance weight for this region.
Definition peak_afl_weighted_rois.hpp:80
uint32_t width
Width of rectangle in pixels.
Definition peak_afl.h:1517
uint32_t height
Height of rectangle in pixels.
Definition peak_afl.h:1524
uint32_t y
Y-coordinate of top-left corner.
Definition peak_afl.h:1510
uint32_t x
X-coordinate of top-left corner.
Definition peak_afl.h:1503
Weighted region of interest for focus control.
Definition peak_afl.h:1539
peak_afl_roi_weight weight
Weight of this region.
Definition peak_afl.h:1554
peak_afl_rectangle roi
Rectangular region definition.
Definition peak_afl.h:1546