Skip to content

Commit 3442a8d

Browse files
committed
Handle incorrect flow vectors in gpc_evaluate; fixes opencv/opencv#9183
1 parent 617db6c commit 3442a8d

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

modules/optflow/samples/gpc_evaluate.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ int main( int argc, const char **argv )
114114
std::cout << "Found " << corr.size() << " matches." << std::endl;
115115
std::cout << "Time: " << meter.getTimeSec() << " sec." << std::endl;
116116
double error = 0;
117+
int totalCorrectFlowVectors = 0;
117118
Mat dispErr = Mat::zeros( from.size(), CV_32FC3 );
118119
dispErr = Scalar( 0, 0, 1 );
119120
Mat disp = Mat::zeros( from.size(), CV_32FC3 );
@@ -123,13 +124,22 @@ int main( int argc, const char **argv )
123124
{
124125
const Point2f a = corr[i].first;
125126
const Point2f b = corr[i].second;
126-
const Point2f c = a + gt.at< Point2f >( corr[i].first.y, corr[i].first.x );
127-
error += normL2( b - c );
127+
const Point2f gtDisplacement = gt.at< Point2f >( corr[i].first.y, corr[i].first.x );
128+
129+
// Check that flow vector is correct
130+
if (!cvIsNaN(gtDisplacement.x) && !cvIsNaN(gtDisplacement.y) && gtDisplacement.x < 1e9 && gtDisplacement.y < 1e9)
131+
{
132+
const Point2f c = a + gtDisplacement;
133+
error += normL2( b - c );
134+
circle( dispErr, a, 3, getFlowColor( b - c, false, 32 ), -1 );
135+
++totalCorrectFlowVectors;
136+
}
137+
128138
circle( disp, a, 3, getFlowColor( b - a ), -1 );
129-
circle( dispErr, a, 3, getFlowColor( b - c, false, 32 ), -1 );
130139
}
131140

132-
error /= corr.size();
141+
if (totalCorrectFlowVectors)
142+
error /= totalCorrectFlowVectors;
133143

134144
std::cout << "Average endpoint error: " << error << " px." << std::endl;
135145

0 commit comments

Comments
 (0)