// 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);
} 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) {
// 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;