Bug in calcHist when accumulate flag is set to true (Feature #526)
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
fixed sparse histogram update (ticket #526)
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