float vr_gamma = 10.0f, vr_delta = 5.0f, vr_alpha = 10.0f;
bool enable_timing = true;
+bool enable_variational_refinement = true; // Just for debugging.
// Some global OpenGL objects.
// TODO: These should really be part of DISComputeFlow.
// Add the differential flow found by the variational refinement to the base flow,
// giving the final flow estimate for this level.
// The output is in diff_flow_tex; we don't need to make a new texture.
- // You can comment out this part if you wish to test disabling of the variational refinement.
- {
+ //
+ // Disabling this doesn't save any time (although we could easily make it so that
+ // it is more efficient), but it helps debug the motion search.
+ if (enable_variational_refinement) {
ScopedTimer timer("Add differential flow", &varref_timer);
add_base_flow.exec(base_flow_tex, du_dv_tex, level_width, level_height);
}
assert(false);
}
+// OpenGL uses a bottom-left coordinate system, .flo files use a top-left coordinate system.
+void flip_coordinate_system(float *dense_flow, unsigned width, unsigned height)
+{
+ for (unsigned i = 0; i < width * height; ++i) {
+ dense_flow[i * 2 + 1] = -dense_flow[i * 2 + 1];
+ }
+}
+
void write_flow(const char *filename, const float *dense_flow, unsigned width, unsigned height)
{
FILE *flowfp = fopen(filename, "wb");
fwrite(&height, 4, 1, flowfp);
for (unsigned y = 0; y < height; ++y) {
int yy = height - y - 1;
- for (unsigned x = 0; x < unsigned(width); ++x) {
- float du = dense_flow[(yy * width + x) * 2 + 0];
- float dv = dense_flow[(yy * width + x) * 2 + 1];
-
- dv = -dv;
-
- fwrite(&du, 4, 1, flowfp);
- fwrite(&dv, 4, 1, flowfp);
- }
+ fwrite(&dense_flow[yy * width * 2], width * 2 * sizeof(float), 1, flowfp);
}
fclose(flowfp);
}
float du = dense_flow[(yy * width + x) * 2 + 0];
float dv = dense_flow[(yy * width + x) * 2 + 1];
- dv = -dv;
-
uint8_t r, g, b;
flow2rgb(du, dv, &r, &g, &b);
putc(r, fp);
{ "alpha", required_argument, 0, 'a' },
{ "delta", required_argument, 0, 'd' },
{ "gamma", required_argument, 0, 'g' },
- { "disable-timing", no_argument, 0, 1000 }
+ { "disable-timing", no_argument, 0, 1000 },
+ { "ignore-variational-refinement", no_argument, 0, 1001 } // Still calculates it, just doesn't apply it.
};
for ( ;; ) {
case 1000:
enable_timing = false;
break;
+ case 1001:
+ enable_variational_refinement = false;
+ break;
default:
fprintf(stderr, "Unknown option '%s'\n", argv[option_index]);
exit(1);
compute_flow.release_texture(final_tex);
+ flip_coordinate_system(dense_flow.get(), width1, height1);
write_flow(flow_filename, dense_flow.get(), width1, height1);
write_ppm("flow.ppm", dense_flow.get(), width1, height1);
compute_flow.release_texture(final_tex);
+ flip_coordinate_system(dense_flow.get(), width, height);
write_flow(flow_filename, dense_flow.get(), width, height);
}