Accessing Histograms
There are several ways to access a histogram's data. The most straightforward method is to use OpenCV's accessor functions.
double cvQueryHistValue_1D( CvHistogram* hist, int idx0 ); double cvQueryHistValue_2D( CvHistogram* hist, int idx0, int idx1 ); double cvQueryHistValue_3D( CvHistogram* hist, int idx0, int idx1, int idx2 ); double cvQueryHistValue_nD( CvHistogram* hist, int* idxN );
Each of these functions returns a floating-point number for the value in the appropriate bin. Similarly, you can set (or get) histogram bin values with the functions that return a pointer to a bin (not to a bin's value):
float* cvGetHistValue_1D( CvHistogram* hist, int idx0 ); float* cvGetHistValue_2D( CvHistogram* hist, int idx0, int idx1 ); float* cvGetHistValue_3D( CvHistogram* hist, int idx0, int idx1, int idx2 ); float* cvGetHistValue_nD( CvHistogram* hist, int* idxN );
These functions look a lot like the cvGetReal*D and
cvPtr*D families of functions, and in fact they are
pretty much the same thing. Inside of these calls are essentially those same matrix
accessors called with the matrix hist->bins passed on
to them. Similarly, the functions for sparse histograms inherit the behavior of the corresponding sparse matrix functions. If
you attempt to access a nonexistent bin using a GetHist*() function in a sparse histogram, then that bin is automatically
created and its value set to 0. Note that QueryHist*()
functions do not create missing bins.
This leads us to the more general ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access