Fix subtle bug when src & dst agree on sparsity but have different dimensions

Remove unused var "total"
Declare vars as locally as possible
pull/415/head
Andy Maloney 12 years ago
parent db9de43fa5
commit 3154cdf8ac
  1. 38
      modules/imgproc/src/histogram.cpp

@ -2592,39 +2592,36 @@ cvCompareHist( const CvHistogram* hist1,
CV_IMPL void CV_IMPL void
cvCopyHist( const CvHistogram* src, CvHistogram** _dst ) cvCopyHist( const CvHistogram* src, CvHistogram** _dst )
{ {
int eq = 0;
int is_sparse;
int i, dims1, dims2;
int size1[CV_MAX_DIM], size2[CV_MAX_DIM], total = 1;
float* ranges[CV_MAX_DIM];
float** thresh = 0;
CvHistogram* dst;
if( !_dst ) if( !_dst )
CV_Error( CV_StsNullPtr, "Destination double pointer is NULL" ); CV_Error( CV_StsNullPtr, "Destination double pointer is NULL" );
dst = *_dst; CvHistogram* dst = *_dst;
if( !CV_IS_HIST(src) || (dst && !CV_IS_HIST(dst)) ) if( !CV_IS_HIST(src) || (dst && !CV_IS_HIST(dst)) )
CV_Error( CV_StsBadArg, "Invalid histogram header[s]" ); CV_Error( CV_StsBadArg, "Invalid histogram header[s]" );
is_sparse = CV_IS_SPARSE_MAT(src->bins); bool eq = false;
dims1 = cvGetDims( src->bins, size1 ); int size1[CV_MAX_DIM];
for( i = 0; i < dims1; i++ ) bool is_sparse = CV_IS_SPARSE_MAT(src->bins);
total *= size1[i]; int dims1 = cvGetDims( src->bins, size1 );
if( dst && is_sparse == CV_IS_SPARSE_MAT(dst->bins)) if( dst && (is_sparse == CV_IS_SPARSE_MAT(dst->bins)))
{ {
dims2 = cvGetDims( dst->bins, size2 ); int size2[CV_MAX_DIM];
int dims2 = cvGetDims( dst->bins, size2 );
if( dims1 == dims2 ) if( dims1 == dims2 )
{ {
int i;
for( i = 0; i < dims1; i++ ) for( i = 0; i < dims1; i++ )
{
if( size1[i] != size2[i] ) if( size1[i] != size2[i] )
break; break;
} }
eq = i == dims1; eq = (i == dims1);
}
} }
if( !eq ) if( !eq )
@ -2636,14 +2633,21 @@ cvCopyHist( const CvHistogram* src, CvHistogram** _dst )
if( CV_HIST_HAS_RANGES( src )) if( CV_HIST_HAS_RANGES( src ))
{ {
float* ranges[CV_MAX_DIM];
float** thresh = 0;
if( CV_IS_UNIFORM_HIST( src )) if( CV_IS_UNIFORM_HIST( src ))
{ {
for( i = 0; i < dims1; i++ ) for( int i = 0; i < dims1; i++ )
ranges[i] = (float*)src->thresh[i]; ranges[i] = (float*)src->thresh[i];
thresh = ranges; thresh = ranges;
} }
else else
{
thresh = src->thresh2; thresh = src->thresh2;
}
cvSetHistBinRanges( dst, thresh, CV_IS_UNIFORM_HIST(src)); cvSetHistBinRanges( dst, thresh, CV_IS_UNIFORM_HIST(src));
} }

Loading…
Cancel
Save