Commit 62fa7f66 authored by Vadim Pisarevsky's avatar Vadim Pisarevsky

avoid crash in cvCalcEMD() when one of the histograms has only one non-zero…

avoid crash in cvCalcEMD() when one of the histograms has only one non-zero element (ticket #396). Thanks to nburrus for the patch
parent 0faa75da
...@@ -297,10 +297,14 @@ CV_IMPL float cvCalcEMD2( const CvArr* signature_arr1, ...@@ -297,10 +297,14 @@ CV_IMPL float cvCalcEMD2( const CvArr* signature_arr1,
float val = xp->val; float val = xp->val;
int i = xp->i; int i = xp->i;
int j = xp->j; int j = xp->j;
if( xp == state.enter_x )
continue;
int ci = state.idx1[i]; int ci = state.idx1[i];
int cj = state.idx2[j]; 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]; total_cost += (double)val * state.cost[i][j];
if( flow ) if( flow )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment