]> git.sesse.net Git - nageru/blob - eval.cpp
Make the eval tool capable of taking the average over a series of flow files.
[nageru] / eval.cpp
1 // Evaluate a .flo file against ground truth,
2 // outputting the average end-point error.
3
4 #include <assert.h>
5 #include <stdio.h>
6
7 #include <memory>
8
9 #include "util.h"
10
11 using namespace std;
12
13 double eval_flow(const char *filename1, const char *filename2);
14
15 int main(int argc, char **argv)
16 {
17         double sum_epe = 0.0;
18         int num_flows = 0;
19         for (int i = 1; i < argc; i += 2) {
20                 sum_epe += eval_flow(argv[i], argv[i + 1]);
21                 ++num_flows;
22         }
23         fprintf(stderr, "Average EPE: %.2f pixels\n", sum_epe / num_flows);
24 }
25
26 double eval_flow(const char *filename1, const char *filename2)
27 {
28         Flow flow = read_flow(filename1);
29         Flow gt = read_flow(filename2);
30
31         double sum = 0.0;
32         for (unsigned y = 0; y < unsigned(flow.height); ++y) {
33                 for (unsigned x = 0; x < unsigned(flow.width); ++x) {
34                         float du = flow.flow[y * flow.width + x].du;
35                         float dv = flow.flow[y * flow.width + x].dv;
36                         float gt_du = gt.flow[y * flow.width + x].du;
37                         float gt_dv = gt.flow[y * flow.width + x].dv;
38                         sum += hypot(du - gt_du, dv - gt_dv);
39                 }
40         }
41         return sum / (flow.width * flow.height);
42 }