Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

for the fun of it, you could try an analytical solution, like:

 Mat dx;  Sobel(hist,dx,CV_32F,1,0,1); // zeros of the 1st derivative in x are are extremums

but you'd still have to iterate it to check the neighbours for slope, so ...

let's keep it simple: a histogram is a 1d array, and for a a peak value , both neighbour elements have to be <= center.

for (int i=1; i<; ++i)
       float left  =<float>(i-1);
       float cent  =<float>(i);
       float right =<float>(i+1);
       // we have to set a boundary condition for 'plateaus', 
       // so just decide to have the 'cutoff' on the left side
       if ( left < cent  && right <= cent )
               // peak !
       // bonus track, get the valleys, too !
       if ( left > cent  && right >= cent )
               // valley !

you will still have to think of a way to handle the 1st and last element (which are lacking the neighbour).