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