@@ -114,6 +114,7 @@ int main( int argc, const char **argv )
114
114
std::cout << " Found " << corr.size () << " matches." << std::endl;
115
115
std::cout << " Time: " << meter.getTimeSec () << " sec." << std::endl;
116
116
double error = 0 ;
117
+ int totalCorrectFlowVectors = 0 ;
117
118
Mat dispErr = Mat::zeros ( from.size (), CV_32FC3 );
118
119
dispErr = Scalar ( 0 , 0 , 1 );
119
120
Mat disp = Mat::zeros ( from.size (), CV_32FC3 );
@@ -123,13 +124,22 @@ int main( int argc, const char **argv )
123
124
{
124
125
const Point2f a = corr[i].first ;
125
126
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
+
128
138
circle ( disp, a, 3 , getFlowColor ( b - a ), -1 );
129
- circle ( dispErr, a, 3 , getFlowColor ( b - c, false , 32 ), -1 );
130
139
}
131
140
132
- error /= corr.size ();
141
+ if (totalCorrectFlowVectors)
142
+ error /= totalCorrectFlowVectors;
133
143
134
144
std::cout << " Average endpoint error: " << error << " px." << std::endl;
135
145
0 commit comments