%.moc.cpp: %.h
moc $< -o $@
-all: futatabi
+all: futatabi flow vis eval
mainwindow.o: ui_mainwindow.h
futatabi: $(OBJS) $(CEF_LIBS)
$(CXX) -o $@ $^ $(LDFLAGS) $(LDLIBS)
+flow: flow.o
+ $(CXX) -o $@ $^ -lepoxy -lSDL2
+eval: eval.o util.o
+ $(CXX) -o $@ $^
+vis: vis.o util.o
+ $(CXX) -o $@ $^
DEPS=$(OBJS:.o=.d)
-include $(DEPS)
--- /dev/null
+// Evaluate a .flo file against ground truth,
+// outputting the average end-point error.
+
+#include <assert.h>
+#include <stdio.h>
+
+#include <memory>
+
+#include "util.h"
+
+using namespace std;
+
+int main(int argc, char **argv)
+{
+ Flow flow = read_flow(argv[1]);
+ Flow gt = read_flow(argv[2]);
+
+ double sum = 0.0;
+ for (unsigned y = 0; y < unsigned(flow.height); ++y) {
+ for (unsigned x = 0; x < unsigned(flow.width); ++x) {
+ float du = flow.flow[y * flow.width + x].du;
+ float dv = flow.flow[y * flow.width + x].dv;
+ float gt_du = gt.flow[y * flow.width + x].du;
+ float gt_dv = gt.flow[y * flow.width + x].dv;
+ sum += hypot(du - gt_du, dv - gt_dv);
+ }
+ }
+ fprintf(stderr, "Average EPE: %.2f pixels\n", sum / (flow.width * flow.height));
+}
#include <assert.h>
#include <stdio.h>
-#include "flow2rgb.h"
+#include "util.h"
#include <algorithm>
#include <memory>
--- /dev/null
+#include <assert.h>
+#include <stdio.h>
+
+#include <memory>
+
+#include "util.h"
+
+using namespace std;
+
+Flow read_flow(const char *filename)
+{
+ FILE *flowfp = fopen(filename, "rb");
+ uint32_t hdr, width, height;
+ fread(&hdr, sizeof(hdr), 1, flowfp);
+ fread(&width, sizeof(width), 1, flowfp);
+ fread(&height, sizeof(height), 1, flowfp);
+
+ unique_ptr<Vec2[]> flow(new Vec2[width * height]);
+ fread(flow.get(), width * height * sizeof(Vec2), 1, flowfp);
+
+ Flow ret;
+ ret.width = width;
+ ret.height = height;
+ ret.flow = move(flow);
+ return ret;
+}
-#ifndef _FLOW2RGB_H
-#define _FLOW2RGB_H 1
+#ifndef _UTIL_H
+#define _UTIL_H 1
#include <math.h>
#include <stdint.h>
-
#include <algorithm>
+#include <memory>
+
+struct Vec2 {
+ float du, dv;
+};
+
+struct Flow {
+ uint32_t width, height;
+ std::unique_ptr<Vec2[]> flow;
+};
+
+Flow read_flow(const char *filename);
// du and dv are in pixels.
inline void flow2rgb(float du, float dv, uint8_t *rr, uint8_t *gg, uint8_t *bb)
*bb = lrintf(b * 255.0f);
}
-#endif // !defined(_FLOW2RGB_H)
+#endif // !defined(_UTIL_H)
--- /dev/null
+// Visualize a .flo file.
+
+#include <assert.h>
+#include <stdio.h>
+
+#include <memory>
+
+#include "util.h"
+
+using namespace std;
+
+int main(int argc, char **argv)
+{
+ if (argc != 3) {
+ fprintf(stderr, "Usage: ./vis input.flo out.ppm\n");
+ exit(1);
+ }
+
+ Flow flow = read_flow(argv[1]);
+
+ FILE *fp = fopen(argv[2], "wb");
+ fprintf(fp, "P6\n%d %d\n255\n", flow.width, flow.height);
+ for (unsigned y = 0; y < unsigned(flow.height); ++y) {
+ for (unsigned x = 0; x < unsigned(flow.width); ++x) {
+ float du = flow.flow[y * flow.width + x].du;
+ float dv = flow.flow[y * flow.width + x].dv;
+
+ uint8_t r, g, b;
+ flow2rgb(du, dv, &r, &g, &b);
+ putc(r, fp);
+ putc(g, fp);
+ putc(b, fp);
+ }
+ }
+ fclose(fp);
+}