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