From 968a17613099bde09d83ce570acb35625016cb5e Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Wed, 4 Jul 2018 22:21:39 +0200 Subject: [PATCH] Update some comments. --- flow.cpp | 2 +- motion_search.frag | 4 ++++ sobel.frag | 15 +++++++++++---- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/flow.cpp b/flow.cpp index 47cebba..e59a481 100644 --- a/flow.cpp +++ b/flow.cpp @@ -494,7 +494,7 @@ int main(void) // Densification. - // Set up an output texture. + // Set up an output texture (initially zero). GLuint dense_flow_tex; glCreateTextures(GL_TEXTURE_2D, 1, &dense_flow_tex); //glTextureStorage2D(dense_flow_tex, 1, GL_RGB16F, level_width, level_height); diff --git a/motion_search.frag b/motion_search.frag index 5f2b6f8..0c5dcc4 100644 --- a/motion_search.frag +++ b/motion_search.frag @@ -95,6 +95,10 @@ void main() } else { initial_u = prev_flow.xy / prev_flow.z; } + + // Note: The flow is in OpenGL coordinates [0..1], but the calculations + // generally come out in pixels since the gradient is in pixels, + // so we need to convert at the end. vec2 u = initial_u; for (uint i = 0; i < num_iterations; ++i) { diff --git a/sobel.frag b/sobel.frag index 4fd12a3..9feab1e 100644 --- a/sobel.frag +++ b/sobel.frag @@ -11,12 +11,19 @@ void main() // There are two common Sobel filters, horizontal and vertical // (see e.g. Wikipedia, or the OpenCV documentation): // - // [-1 0 1] [ 1 2 1] - // [-2 0 2] [ 0 0 0] - // [-1 0 1] [-1 -2 -1] + // [1 0 -1] [-1 -2 -1] + // [2 0 -2] [ 0 0 0] + // [1 0 -1] [ 1 2 1] // Horizontal Vertical // - // Computing both at once allows us to get away with eight + // Note that Wikipedia and OpenCV gives entirely opposite definitions + // with regards to sign! This appears to be an error in the OpenCV + // documentation, forgetting that for convolution, the filters must be + // flipped. We have to flip the vertical matrix again comparing to + // Wikipedia, though, since we have bottom-left origin (y = up) + // and they define y as pointing downwards. + // + // Computing both directions at once allows us to get away with eight // texture samples instead of twelve. float x_left = tc.x - inv_image_size.x; -- 2.39.2