Skip to content

Commit cf97e6e

Browse files
committed
Merge pull request opencv#7806 from alalek:backport_7640
2 parents bc96997 + 10d1b33 commit cf97e6e

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed

modules/video/perf/perf_tvl1optflow.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ PERF_TEST_P(ImagePair, OpticalFlowDual_TVL1, testing::Values(impair("cv/optflow/
2424

2525
Ptr<DenseOpticalFlow> tvl1 = createOptFlow_DualTVL1();
2626

27-
TEST_CYCLE_N(10) tvl1->calc(frame1, frame2, flow);
27+
TEST_CYCLE() tvl1->calc(frame1, frame2, flow);
2828

29-
SANITY_CHECK(flow, 0.5);
29+
SANITY_CHECK_NOTHING();
3030
}

modules/video/test/test_tvl1optflow.cpp

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -115,35 +115,39 @@ namespace
115115
return !cvIsNaN(u.x) && !cvIsNaN(u.y) && (fabs(u.x) < 1e9) && (fabs(u.y) < 1e9);
116116
}
117117

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)
119119
{
120-
double sum = 0.0;
121-
int counter = 0;
120+
threshold = threshold*threshold;
122121

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)
124126
{
125-
for (int j = 0; j < flow1.cols; ++j)
127+
for (int j = 0; j < gold.cols; ++j)
126128
{
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);
129131

130-
if (isFlowCorrect(u1) && isFlowCorrect(u2))
132+
if (isFlowCorrect(u1))
131133
{
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+
}
135142
}
136143
}
137144
}
138-
139-
return sqrt(sum / (1e-9 + counter));
145+
EXPECT_GE(valid_counter, expectedAccuracy * gold_counter);
140146
}
141147
}
142148

143149
TEST(Video_calcOpticalFlowDual_TVL1, Regression)
144150
{
145-
const double MAX_RMSE = 0.02;
146-
147151
const string frame1_path = TS::ptr()->get_data_path() + "optflow/RubberWhale1.png";
148152
const string frame2_path = TS::ptr()->get_data_path() + "optflow/RubberWhale2.png";
149153
const string gold_flow_path = TS::ptr()->get_data_path() + "optflow/tvl1_flow.flo";
@@ -167,7 +171,6 @@ TEST(Video_calcOpticalFlowDual_TVL1, Regression)
167171
ASSERT_EQ(gold.rows, flow.rows);
168172
ASSERT_EQ(gold.cols, flow.cols);
169173

170-
const double err = calcRMSE(gold, flow);
171-
EXPECT_LE(err, MAX_RMSE);
174+
check(gold, flow);
172175
#endif
173176
}

0 commit comments

Comments
 (0)