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

◆ op_harris_response()

GpuVisionPass::Completed MayaFlux::Yantra::VisionGpuExecutor::op_harris_response ( VisionGpuContexts &  contexts,
const Kinesis::Vision::HarrisParams &  p 
)
private

Compute the Harris response of the current image.

Packs and smooths image gradients before evaluating the response. The response image becomes the working image for a following ExtractPeaks.

Returns
The response image and the original input image.

Zero PeakBuf (binding 2) before pass 0 so its atomicMax starts clean; clear the staged bytes before pass 1 so the accumulated max survives.

Definition at line 10 of file VisionFeatureDispatch.cpp.

13{
14 auto& pixel_ctx = contexts.pixel;
15 auto w = contexts.pass.w;
16 auto h = contexts.pass.h;
18
19 const auto radius = static_cast<uint32_t>(std::ceil(p.sigma * 3.0F));
20 const auto& weights = gaussian_kernel_2d(radius, p.sigma);
21
22 const auto harris_input = contexts.pass.current;
23
24 pixel_ctx.swap_shader({ .shader_path = "harris_grad_pack.comp.spv", .workgroup_size = k_wg2d });
25 pixel_ctx.stage_image(harris_input);
26 pixel_ctx.prepare_output_image(w, h);
27 {
28 const auto f = pixel_ctx.dispatch_async({});
29 foundry.wait_for_fence(f);
30 foundry.release_fence(f);
31 }
32 auto packed = pixel_ctx.get_output_image(0);
33
34 const auto blur_cfg = VisionGpuExecutor::config(VisionOp::GaussianBlur, GaussianBlurParams { .sigma = p.sigma });
35 pixel_ctx.swap_shader(blur_cfg);
36 pixel_ctx.stage_image(packed);
37 pixel_ctx.set_binding_data(2, std::span<const float>(weights));
38 pixel_ctx.set_push_constants(GaussianPC { .radius = radius, .width = w, .height = h });
39 pixel_ctx.prepare_output_image(w, h);
40 {
41 const auto f = pixel_ctx.dispatch_async({});
42 foundry.wait_for_fence(f);
43 foundry.release_fence(f);
44 }
45 auto smoothed = pixel_ctx.get_output_image(0);
46
47 const GpuComputeConfig harris_resp_cfg {
48 .shader_path = "harris_response.comp.spv",
49 .workgroup_size = k_wg2d,
50 .push_constant_size = sizeof(HarrisPC),
51 };
52 pixel_ctx.swap_shader(harris_resp_cfg);
53 pixel_ctx.stage_image(smoothed);
54
55 /** Zero PeakBuf (binding 2) before pass 0 so its atomicMax starts clean;
56 * clear the staged bytes before pass 1 so the accumulated max survives. */
57 const uint32_t peak_reset = 0U;
58 pixel_ctx.set_binding_data(2, std::span<const uint32_t>(&peak_reset, 1));
59 const auto rect = region_rect(p.region, w, h);
60 pixel_ctx.set_push_constants(HarrisPC { .k = p.k, .pass = 0U, .width = w, .height = h, .rect = rect });
61 pixel_ctx.prepare_output_image(w, h);
62 {
63 const auto f = pixel_ctx.dispatch_async({});
64 foundry.wait_for_fence(f);
65 foundry.release_fence(f);
66 }
67
68 pixel_ctx.set_binding_data(2, std::span<const uint32_t>(&peak_reset, 0));
69 pixel_ctx.set_push_constants(HarrisPC { .k = p.k, .pass = 1U, .width = w, .height = h, .rect = rect });
70 {
71 const auto f = pixel_ctx.dispatch_async({});
72 foundry.wait_for_fence(f);
73 foundry.release_fence(f);
74 }
75
76 contexts.pass.current = pixel_ctx.get_output_image(0);
77 contexts.pass.result.structured = std::monostate {};
78 contexts.pass.result.images.harris_response = contexts.pass.current;
79
80 contexts.bound_config = harris_resp_cfg;
81 contexts.bound_staged = smoothed;
82
83 return { .output = contexts.pass.current, .input = harris_input };
84}
float radius
uint32_t h
Definition InkPress.cpp:29
const std::vector< float > & gaussian_kernel_2d(uint32_t radius, float sigma)
2D Gaussian kernel for convolution, cached by (radius, sigma bit pattern).
static GpuComputeConfig config(Kinesis::Vision::VisionOp op, const Kinesis::Vision::VisionParams &params)
GpuComputeConfig for a given VisionOp and its parameters.
MAYAFLUX_API ShaderFoundry & get_shader_foundry()
Get the global shader compiler instance.
PixelRect region_rect(const std::optional< Kinesis::Vision::BoundingBox > &region, uint32_t w, uint32_t h)
Pixel rectangle of a normalised region over a w x h image, clamped to the image.
constexpr std::array< uint32_t, 3 > k_wg2d
Standard 2D workgroup used by all pixel-to-pixel vision shaders.
Portal::Graphics::GpuComputeConfig GpuComputeConfig

References MayaFlux::Yantra::VisionGpuContexts::bound_config, MayaFlux::Yantra::VisionGpuContexts::bound_staged, config(), MayaFlux::Kinesis::Vision::VisionPass< Handle >::current, gaussian_kernel_2d(), MayaFlux::Portal::Graphics::get_shader_foundry(), MayaFlux::Kinesis::Vision::VisionPass< Handle >::h, h, MayaFlux::Kinesis::Vision::ImageOutputs::harris_response, MayaFlux::Kinesis::Vision::VisionResult::images, MayaFlux::Kinesis::Vision::HarrisParams::k, MayaFlux::Yantra::VisionInternal::HarrisPC::k, MayaFlux::Yantra::VisionInternal::k_wg2d, MayaFlux::Yantra::VisionGpuContexts::pass, MayaFlux::Yantra::VisionGpuContexts::pixel, radius, MayaFlux::Yantra::VisionInternal::GaussianPC::radius, MayaFlux::Kinesis::Vision::HarrisParams::region, MayaFlux::Yantra::VisionInternal::region_rect(), MayaFlux::Kinesis::Vision::VisionPass< Handle >::result, MayaFlux::Portal::Graphics::GpuComputeConfig::shader_path, MayaFlux::Kinesis::Vision::GaussianBlurParams::sigma, MayaFlux::Kinesis::Vision::HarrisParams::sigma, MayaFlux::Kinesis::Vision::VisionResult::structured, and MayaFlux::Kinesis::Vision::VisionPass< Handle >::w.

+ Here is the call graph for this function: