@@ -115,35 +115,39 @@ namespace
115
115
return !cvIsNaN (u.x ) && !cvIsNaN (u.y ) && (fabs (u.x ) < 1e9 ) && (fabs (u.y ) < 1e9 );
116
116
}
117
117
118
- double calcRMSE (const Mat_<Point2f>& flow1 , const Mat_<Point2f>& flow2 )
118
+ void check (const Mat_<Point2f>& gold , const Mat_<Point2f>& flow, double threshold = 0.1 , double expectedAccuracy = 0.95 )
119
119
{
120
- double sum = 0.0 ;
121
- int counter = 0 ;
120
+ threshold = threshold*threshold;
122
121
123
- for (int i = 0 ; i < flow1.rows ; ++i)
122
+ size_t gold_counter = 0 ;
123
+ size_t valid_counter = 0 ;
124
+
125
+ for (int i = 0 ; i < gold.rows ; ++i)
124
126
{
125
- for (int j = 0 ; j < flow1 .cols ; ++j)
127
+ for (int j = 0 ; j < gold .cols ; ++j)
126
128
{
127
- const Point2f u1 = flow1 (i, j);
128
- const Point2f u2 = flow2 (i, j);
129
+ const Point2f u1 = gold (i, j);
130
+ const Point2f u2 = flow (i, j);
129
131
130
- if (isFlowCorrect (u1) && isFlowCorrect (u2) )
132
+ if (isFlowCorrect (u1))
131
133
{
132
- const Point2f diff = u1 - u2;
133
- sum += diff.ddot (diff);
134
- ++counter;
134
+ gold_counter++;
135
+ if (isFlowCorrect (u2))
136
+ {
137
+ const Point2f diff = u1 - u2;
138
+ double err = diff.ddot (diff);
139
+ if (err <= threshold)
140
+ valid_counter++;
141
+ }
135
142
}
136
143
}
137
144
}
138
-
139
- return sqrt (sum / (1e-9 + counter));
145
+ EXPECT_GE (valid_counter, expectedAccuracy * gold_counter);
140
146
}
141
147
}
142
148
143
149
TEST (Video_calcOpticalFlowDual_TVL1, Regression)
144
150
{
145
- const double MAX_RMSE = 0.02 ;
146
-
147
151
const string frame1_path = TS::ptr ()->get_data_path () + " optflow/RubberWhale1.png" ;
148
152
const string frame2_path = TS::ptr ()->get_data_path () + " optflow/RubberWhale2.png" ;
149
153
const string gold_flow_path = TS::ptr ()->get_data_path () + " optflow/tvl1_flow.flo" ;
@@ -167,7 +171,6 @@ TEST(Video_calcOpticalFlowDual_TVL1, Regression)
167
171
ASSERT_EQ (gold.rows , flow.rows );
168
172
ASSERT_EQ (gold.cols , flow.cols );
169
173
170
- const double err = calcRMSE (gold, flow);
171
- EXPECT_LE (err, MAX_RMSE);
174
+ check (gold, flow);
172
175
#endif
173
176
}
0 commit comments