Skip to content

Commit b1408e3

Browse files
committed
Merge pull request #1292 from VladX:gpc_fix
2 parents ffdec47 + 3442a8d commit b1408e3

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-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

modules/optflow/src/sparse_matching_gpc.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,9 @@ Ptr< GPCTrainingSamples > GPCTrainingSamples::create( InputArrayOfArrays imagesF
729729

730730
void GPCDetails::dropOutliers( std::vector< std::pair< Point2i, Point2i > > &corr )
731731
{
732+
if ( corr.size() == 0 )
733+
return;
734+
732735
std::vector< float > mag( corr.size() );
733736

734737
for ( size_t i = 0; i < corr.size(); ++i )

0 commit comments

Comments
 (0)