avoid crash in cvCalcEMD() when one of the histograms has only one non-zero element...
authorVadim Pisarevsky <no@email>
Thu, 29 Jul 2010 11:00:52 +0000 (11:00 +0000)
committerVadim Pisarevsky <no@email>
Thu, 29 Jul 2010 11:00:52 +0000 (11:00 +0000)
modules/imgproc/src/emd.cpp

index f81467c44da3e571243411eac9d6c17cf3c4db57..e6be13ed85dcc39887ffd62d46e9938964fb2a93 100644 (file)
@@ -297,10 +297,14 @@ CV_IMPL float cvCalcEMD2( const CvArr* signature_arr1,
         float val = xp->val;
         int i = xp->i;
         int j = xp->j;
+
+        if( xp == state.enter_x )
+          continue;
+
         int ci = state.idx1[i];
         int cj = state.idx2[j];
 
-        if( xp != state.enter_x && ci >= 0 && cj >= 0 )
+        if( ci >= 0 && cj >= 0 )
         {
             total_cost += (double)val * state.cost[i][j];
             if( flow )