]> git.sesse.net Git - nageru/blobdiff - eval.cpp
Allow symlinked frame files. Useful for testing.
[nageru] / eval.cpp
index e19ce1f541a3fa1d14dd3ebc0ff0a18b74587d58..85783bb58a1a83d95b92391c6fbc37d234f6d3c2 100644 (file)
--- a/eval.cpp
+++ b/eval.cpp
@@ -1,19 +1,31 @@
 // Evaluate a .flo file against ground truth,
 // outputting the average end-point error.
 
-#include <assert.h>
-#include <stdio.h>
+#include "util.h"
 
+#include <assert.h>
 #include <memory>
-
-#include "util.h"
+#include <stdio.h>
 
 using namespace std;
 
+double eval_flow(const char *filename1, const char *filename2);
+
 int main(int argc, char **argv)
 {
-       Flow flow = read_flow(argv[1]);
-       Flow gt = read_flow(argv[2]);
+       double sum_epe = 0.0;
+       int num_flows = 0;
+       for (int i = 1; i < argc; i += 2) {
+               sum_epe += eval_flow(argv[i], argv[i + 1]);
+               ++num_flows;
+       }
+       printf("Average EPE: %.2f pixels\n", sum_epe / num_flows);
+}
+
+double eval_flow(const char *filename1, const char *filename2)
+{
+       Flow flow = read_flow(filename1);
+       Flow gt = read_flow(filename2);
 
        double sum = 0.0;
        for (unsigned y = 0; y < unsigned(flow.height); ++y) {
@@ -25,5 +37,5 @@ int main(int argc, char **argv)
                        sum += hypot(du - gt_du, dv - gt_dv);
                }
        }
-       fprintf(stderr, "Average EPE: %.2f pixels\n", sum / (flow.width * flow.height));
+       return sum / (flow.width * flow.height);
 }