Bug in calcHist when accumulate flag is set to true (Feature #526)


Added by Mourad Boufarguine over 14 years ago. Updated over 14 years ago.


Status:Done Start date:
Priority:High Due date:
Assignee:- % Done:

0%

Category:imgproc, video
Target version:-
Difficulty: Pull request:

Description

When the accumulate flag is set to true, cvCalcHist crashes in the second call. I had this bug with opencv 2.1 but the problem still exists in svn trunk. I tracked the problem until this function (line 754 in trunk/opencv/modules/imgproc/src/histogram.cpp) :

static void calcHist( const Mat* images, int nimages, const int* channels,
                          const Mat& mask, [[SparseMat]]& hist, int dims, const int* histSize,
                          const float** ranges, bool uniform, bool accumulate, bool keepInt )

A SparseMatIterator iterator 'it' is used without initialization :

        [[SparseMatIterator]] it;
        size_t i, N;

        if( !accumulate )
            hist.create(dims, histSize, CV_32F);
        else
            for( i = 0, N = hist.nzcount(); i < N; i++, ++it )
            {
                int* value = (int*)it.ptr;
                *value = cvRound(*(const float*)value);
            }

To solve the problem, 'it' should be initialized to hist.begin().

            for( i = 0, N = hist.nzcount(), it = hist.begin(); i < N; i++, ++it )

Associated revisions

Revision 79ca6d89
Added by Vadim Pisarevsky over 14 years ago

fixed sparse histogram update (ticket #526)

Revision dea6148a
Added by Marina Kolpakova about 12 years ago

Merge pull request #526 from taka-no-me:fix_compatibility

History

Updated by Vadim Pisarevsky over 14 years ago

thanks! fixed in r3896

  • Status changed from Open to Done
  • (deleted custom field) set to fixed

Also available in: Atom PDF