MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ compute_normalised_rect()

template<ComputeData InputType = std::shared_ptr<Kakshya::SignalSourceContainer>, ComputeData OutputType = std::vector<Kakshya::DataVariant>>
std::array< float, 4 > MayaFlux::Yantra::VisionExtractor< InputType, OutputType >::compute_normalised_rect ( const VisionAnalysis analysis) const
inline

Compute the normalised crop rectangle for a given VisionAnalysis.

Returns { nx, ny, nw, nh } in image space [0,1]. Used by callers to configure a TextureExecutionContext before GPU dispatch:

auto rect = extractor->compute_normalised_rect(analysis);
ctx->set_output_dimensions(crop_w, crop_h);
ctx->set_push_constants(CropPC { rect[0], rect[1], rect[2], rect[3], crop_w, crop_h });
extractor->apply_operation(datum);
Exceptions
std::out_of_rangeif index exceeds the relevant detection collection.

Definition at line 101 of file VisionExtractor.hpp.

103 {
104 switch (m_mode) {
106 if (m_index >= analysis.frame.boxes.size()) {
107 error<std::out_of_range>(
110 std::source_location::current(),
111 "VisionExtractor: bbox index {} out of range ({})",
112 m_index, analysis.frame.boxes.size());
113 }
114 const auto& b = analysis.frame.boxes[m_index];
115 return { b.x, b.y, b.w, b.h };
116 }
119 if (m_index >= analysis.frame.contours.size()) {
120 error<std::out_of_range>(
123 std::source_location::current(),
124 "VisionExtractor: contour index {} out of range ({})",
125 m_index, analysis.frame.contours.size());
126 }
127 const auto& pts = analysis.frame.contours[m_index].points;
128 float min_x = pts[0].x, max_x = pts[0].x;
129 float min_y = pts[0].y, max_y = pts[0].y;
130 for (const auto& p : pts) {
131 if (p.x < min_x)
132 min_x = p.x;
133 if (p.x > max_x)
134 max_x = p.x;
135 if (p.y < min_y)
136 min_y = p.y;
137 if (p.y > max_y)
138 max_y = p.y;
139 }
140 return { min_x, min_y, max_x - min_x, max_y - min_y };
141 }
142 }
143 return { 0.F, 0.F, 1.F, 1.F };
144 }
size_t b
@ ComputeMatrix
Compute operations (Yantra - algorithms, matrices, DSP)
@ Yantra
DSP algorithms, computational units, matrix operations, Grammar.
@ BBOX
Crop the axis-aligned rectangle of a BoundingBox.
@ CONTOUR_MASKED
Crop the tight bounding rect of a Contour; zero pixels outside polygon.
@ CONTOUR_TIGHT
Crop the tight bounding rect of a Contour; no polygon mask.

References b, MayaFlux::Yantra::BBOX, MayaFlux::Yantra::DetectionSummary::boxes, MayaFlux::Journal::ComputeMatrix, MayaFlux::Yantra::CONTOUR_MASKED, MayaFlux::Yantra::CONTOUR_TIGHT, MayaFlux::Yantra::DetectionSummary::contours, MayaFlux::Yantra::VisionAnalysis::frame, MayaFlux::Yantra::VisionExtractor< InputType, OutputType >::m_index, MayaFlux::Yantra::VisionExtractor< InputType, OutputType >::m_mode, and MayaFlux::Journal::Yantra.

Referenced by MayaFlux::Yantra::VisionExtractor< InputType, OutputType >::apply_operation_internal(), and MayaFlux::Yantra::VisionExtractor< InputType, OutputType >::extract_implementation().

+ Here is the caller graph for this function: