IDS peak AFL v2.1.0
Loading...
Searching...
No Matches
peak_afl_weighted_rois.hpp
Go to the documentation of this file.
1
6
7#pragma once
8
11
14
15#include <memory>
16
17namespace peak
18{
19namespace pipeline
20{
21namespace modules
22{
23namespace autofeature
24{
35enum class Weight
36{
43};
44
59
78
91PEAK_COMMON_NO_DISCARD inline std::string ToString(Weight weight)
92{
93 switch (weight)
94 {
95 case Weight::Weak:
96 return "Weak";
97 case Weight::Medium:
98 return "Medium";
99 case Weight::Strong:
100 return "Strong";
101 }
102
104}
105
124inline std::ostream& operator<<(std::ostream& os, Weight weight)
125{
126 return os << ToString(weight);
127}
128
129namespace features
130{
131namespace detail
132{
133PEAK_COMMON_NO_DISCARD inline Weight ToWeight(const std::string& name)
134{
135 if (name == "Weak")
136 {
137 return Weight::Weak;
138 }
139 if (name == "Medium")
140 {
141 return Weight::Medium;
142 }
143 if (name == "Strong")
144 {
145 return Weight::Strong;
146 }
148}
149
150PEAK_COMMON_NO_DISCARD inline peak_afl_roi_weight ToCType(Weight weight)
151{
152 switch (weight)
153 {
154 case Weight::Weak:
156 case Weight::Medium:
158 case Weight::Strong:
160 }
161
162 throw peak::afl::error::InternalErrorException("Invalid weight!", PEAK_AFL_STATUS_ERROR);
163}
164
165PEAK_COMMON_NO_DISCARD inline Weight ToWeight(peak_afl_roi_weight weight)
166{
167 switch (weight)
168 {
170 return Weight::Weak;
172 return Weight::Medium;
174 return Weight::Strong;
175 }
176
177 throw peak::afl::error::InternalErrorException("Invalid weight!", PEAK_AFL_STATUS_ERROR);
178}
179
180PEAK_COMMON_NO_DISCARD inline peak_afl_weighted_rectangle ToCType(WeightedROI roi)
181{
182 peak_afl_weighted_rectangle result;
183 result.roi.x = static_cast<uint32_t>(roi.rect.GetX());
184 result.roi.y = static_cast<uint32_t>(roi.rect.GetY());
185 result.roi.width = roi.rect.GetWidth();
186 result.roi.height = roi.rect.GetHeight();
187 result.weight = ToCType(roi.weight);
188 return result;
189}
190
191PEAK_COMMON_NO_DISCARD inline WeightedROI ToWeightedROI(peak_afl_weighted_rectangle roi)
192{
193 const peak::common::Rectangle rect{ { static_cast<int32_t>(roi.roi.x), static_cast<int32_t>(roi.roi.y) },
194 { roi.roi.width, roi.roi.height } };
195 const auto weight = ToWeight(roi.weight);
196 return { rect, weight };
197}
198} // namespace detail
199
232class WeightedRois : public IFeature<std::vector<WeightedROI>>
233{
234public:
247 explicit WeightedRois(std::shared_ptr<peak::afl::Controller> controller)
248 : m_controller{ std::move(controller) }
249 {}
250
268 void Set(const WeightedROI& value)
269 {
270 m_controller->SetWeightedROI(detail::ToCType(value));
271 }
272
291 void Set(const std::vector<WeightedROI>& value) override
292 {
293 std::vector<peak_afl_weighted_rectangle> cRois;
294 cRois.reserve(value.size());
295 std::transform(value.cbegin(), value.cend(), std::back_inserter(cRois), [](const auto& roi) { return detail::ToCType(roi); });
296 m_controller->SetWeightedROIs(cRois);
297 }
298
309 void SetPreset(RoiPreset preset)
310 {
311 m_controller->SetROIPreset(static_cast<peak_afl_roi_preset>(preset));
312 }
313
329 PEAK_COMMON_NO_DISCARD std::vector<WeightedROI> Get() const override
330 {
331 const auto cRois = m_controller->GetWeightedROIs();
332
333 std::vector<WeightedROI> rois;
334 rois.reserve(cRois.size());
335 std::transform(
336 cRois.cbegin(), cRois.cend(), std::back_inserter(rois), [](const auto& cRoi) { return detail::ToWeightedROI(cRoi); });
337 return rois;
338 }
339
356 {
357 std::vector<std::shared_ptr<peak::common::serialization::IArchive>> archives;
358 const auto weightedRois = Get();
359 for (const auto& roi : weightedRois)
360 {
361 auto subArchives = archive.CreateArchive();
362 subArchives->SetInt("X", roi.rect.GetX());
363 subArchives->SetInt("Y", roi.rect.GetY());
364 subArchives->SetInt("Width", roi.rect.GetWidth());
365 subArchives->SetInt("Height", roi.rect.GetHeight());
366 subArchives->SetString("Weight", ToString(roi.weight));
367
368 archives.push_back(subArchives);
369 }
370
371 archive.SetArchiveArray("WeightedRois", archives);
372 }
373
391 {
392 std::vector<WeightedROI> rois;
393 const auto archives = archive.GetArchiveArray("WeightedRois");
394 for (const auto& subArchive : archives)
395 {
397 roi.roi.x = static_cast<uint32_t>(subArchive->GetInt("X"));
398 roi.roi.y = static_cast<uint32_t>(subArchive->GetInt("Y"));
399 roi.roi.width = static_cast<uint32_t>(subArchive->GetInt("Width"));
400 roi.roi.height = static_cast<uint32_t>(subArchive->GetInt("Height"));
401 roi.weight = detail::ToCType(detail::ToWeight(subArchive->GetString("Weight")));
402 rois.emplace_back(detail::ToWeightedROI(roi));
403 }
404
405 Set(rois);
406 }
407
408private:
416 std::shared_ptr<peak::afl::Controller> m_controller;
417};
418} // namespace features
419} // namespace autofeature
420} // namespace modules
421} // namespace pipeline
422} // namespace peak
The exception thrown for signaling an unspecified error.
Definition peak_afl.hpp:385
Interface for a hierarchical key-value archive system.
Definition peak_common_iarchive.hpp:54
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:55
void Set(const std::vector< WeightedROI > &value) override
Sets multiple weighted regions of interest.
Definition peak_afl_weighted_rois.hpp:291
std::vector< WeightedROI > Get() const override
Gets the current weighted regions of interest.
Definition peak_afl_weighted_rois.hpp:329
WeightedRois(std::shared_ptr< peak::afl::Controller > controller)
Constructs a WeightedRois feature with the specified controller.
Definition peak_afl_weighted_rois.hpp:247
void Serialize(peak::common::serialization::IArchive &archive) const override
Serializes the current weighted ROIs to an archive.
Definition peak_afl_weighted_rois.hpp:355
void Set(const WeightedROI &value)
Sets a single weighted region of interest.
Definition peak_afl_weighted_rois.hpp:268
void Deserialize(const peak::common::serialization::IArchive &archive) override
Deserializes weighted ROIs from an archive.
Definition peak_afl_weighted_rois.hpp:390
void SetPreset(RoiPreset preset)
Sets a predefined region of interest (ROI)
Definition peak_afl_weighted_rois.hpp:309
peak_afl_roi_preset
Predefined ROI preset configurations.
Definition peak_afl.h:1407
@ PEAK_AFL_CONTROLLER_ROI_PRESET_CENTER
Center region preset.
Definition peak_afl.h:1417
@ PEAK_AFL_STATUS_ERROR
General error occurred.
Definition peak_afl.h:396
peak_afl_roi_weight
ROI weight values for focus control.
Definition peak_afl.h:1035
@ PEAK_AFL_CONTROLLER_ROI_WEIGHT_WEAK
Low importance weight.
Definition peak_afl.h:1042
@ PEAK_AFL_CONTROLLER_ROI_WEIGHT_STRONG
High importance weight.
Definition peak_afl.h:1058
@ PEAK_AFL_CONTROLLER_ROI_WEIGHT_MEDIUM
Medium importance weight.
Definition peak_afl.h:1050
std::string ToString(ControllerType mode)
Converts ControllerType enumeration to string representation.
Definition peak_afl_icontroller.hpp:74
RoiPreset
Preset enumeration for the Region of interest.
Definition peak_afl_weighted_rois.hpp:55
Weight
Weight enumeration for weighted regions of interest.
Definition peak_afl_weighted_rois.hpp:36
@ Center
Sets a centered ROI that is one-third of the image dimensions.
Definition peak_afl_weighted_rois.hpp:57
@ Weak
Low importance - minimal influence on auto algorithms.
Definition peak_afl_weighted_rois.hpp:38
@ Medium
Normal importance - standard influence on auto algorithms.
Definition peak_afl_weighted_rois.hpp:40
@ Strong
High importance - strong influence on auto algorithms.
Definition peak_afl_weighted_rois.hpp:42
detail::RectangleT< int32_t, uint32_t > Rectangle
Rectangle with integer coordinates and unsigned dimensions.
Definition peak_common_rectangle.hpp:231
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
Weighted region of interest structure.
Definition peak_afl_weighted_rois.hpp:71
peak::common::Rectangle rect
The rectangular region of interest.
Definition peak_afl_weighted_rois.hpp:73
Weight weight
The importance weight for this region.
Definition peak_afl_weighted_rois.hpp:76
uint32_t width
Width of rectangle in pixels.
Definition peak_afl.h:1514
uint32_t height
Height of rectangle in pixels.
Definition peak_afl.h:1521
uint32_t y
Y-coordinate of top-left corner.
Definition peak_afl.h:1507
uint32_t x
X-coordinate of top-left corner.
Definition peak_afl.h:1500
Weighted region of interest for focus control.
Definition peak_afl.h:1536
peak_afl_roi_weight weight
Weight of this region.
Definition peak_afl.h:1551
peak_afl_rectangle roi
Rectangular region definition.
Definition peak_afl.h:1543