:param image:Source images (though you may pass CvMat** as well)
:param back_project:Destination back projection image of the same type as the source images
:param hist:Histogram
The function calculates the back project of the histogram. For each
tuple of pixels at the same position of all input single-channel images
the function puts the value of the histogram bin, corresponding to the
tuple in the destination image. In terms of statistics, the value of
each output image pixel is the probability of the observed tuple given
the distribution (histogram). For example, to find a red object in the
picture, one may do the following:
#.
Calculate a hue histogram for the red object assuming the image contains only this object. The histogram is likely to have a strong maximum, corresponding to red color.
#.
Calculate back projection of a hue plane of input image where the object is searched, using the histogram. Threshold the image.
#.
Find connected components in the resulting picture and choose the right component using some additional criteria, for example, the largest connected component.
That is the approximate algorithm of Camshift color object tracker, except for the 3rd step, instead of which CAMSHIFT algorithm is used to locate the object on the back projection given the previous object position.
Locates a template within an image by using a histogram comparison.
:param images:Source images (though, you may pass CvMat** as well)
:param dst:Destination image
:param patch_size:Size of the patch slid though the source image
:param hist:Histogram
:param method:Comparison method, passed to :ref:`CompareHist` (see description of that function)
:param factor:Normalization factor for histograms, will affect the normalization scale of the destination image, pass 1 if unsure
The function calculates the back projection by comparing histograms of the source image patches with the given histogram. Taking measurement results from some image at each location over ROI creates an array
``image``
. These results might be one or more of hue,
``x``
derivative,
``y``
derivative, Laplacian filter, oriented Gabor filter, etc. Each measurement output is collected into its own separate image. The
``image``
image array is a collection of these measurement images. A multi-dimensional histogram
``hist``
is constructed by sampling from the
``image``
image array. The final histogram is normalized. The
``hist``
histogram has as many dimensions as the number of elements in
``image``
array.
Each new image is measured and then converted into an
``image``
image array over a chosen ROI. Histograms are taken from this
``image``
image in an area covered by a "patch" with an anchor at center as shown in the picture below. The histogram is normalized using the parameter
``norm_factor``
so that it may be compared with
``hist``
. The calculated histogram is compared to the model histogram;
``hist``
uses The function
``cvCompareHist``
with the comparison method=
``method``
). The resulting output is placed at the location corresponding to the patch anchor in the probability image
``dst``
. This process is repeated as the patch is slid over the ROI. Iterative histogram update by subtracting trailing pixels covered by the patch and adding newly covered pixels to the histogram can save a lot of operations, though it is not implemented yet.
:param image:Source images (though you may pass CvMat** as well)
:param hist:Pointer to the histogram
:param accumulate:Accumulation flag. If it is set, the histogram is not cleared in the beginning. This feature allows user to compute a single histogram from several images, or to update the histogram online
:param mask:The operation mask, determines what pixels of the source images are counted
The function calculates the histogram of one or more
single-channel images. The elements of a tuple that is used to increment
a histogram bin are taken at the same location from the corresponding
..cfunction:: CvHistogram* cvCreateHist( int dims, int* sizes, int type, float** ranges=NULL, int uniform=1 )
Creates a histogram.
:param dims:Number of histogram dimensions
:param sizes:Array of the histogram dimension sizes
:param type:Histogram representation format: ``CV_HIST_ARRAY`` means that the histogram data is represented as a multi-dimensional dense array CvMatND; ``CV_HIST_SPARSE`` means that histogram data is represented as a multi-dimensional sparse array CvSparseMat
:param ranges:Array of ranges for the histogram bins. Its meaning depends on the ``uniform`` parameter value. The ranges are used for when the histogram is calculated or backprojected to determine which histogram bin corresponds to which value/tuple of values from the input image(s)
:param uniform:Uniformity flag; if not 0, the histogram has evenly
spaced bins and for every :math:`0<=i<cDims```ranges[i]``
is an array of two numbers: lower and upper boundaries for the i-th
histogram dimension.
The whole range [lower,upper] is then split
into ``dims[i]`` equal parts to determine the ``i-th`` input
tuple value ranges for every histogram bin. And if ``uniform=0`` ,
then ``i-th`` element of ``ranges`` array contains ``dims[i]+1`` elements: :math:`\texttt{lower}_0, \texttt{upper}_0,
return a pointer to the specified bin of the 1D, 2D, 3D or N-D histogram. In the case of a sparse histogram the function creates a new bin and sets it to 0, unless it exists already.
The macros return the value of the specified bin of the 1D, 2D, 3D or N-D histogram. In the case of a sparse histogram the function returns 0, if the bin is not present in the histogram no new bin is created.
..cfunction:: void cvSetHistBinRanges( CvHistogram* hist, float** ranges, int uniform=1 )
Sets the bounds of the histogram bins.
:param hist:Histogram
:param ranges:Array of bin ranges arrays, see :ref:`CreateHist`
:param uniform:Uniformity flag, see :ref:`CreateHist`
The function is a stand-alone function for setting bin ranges in the histogram. For a more detailed description of the parameters
``ranges``
and
``uniform``
see the
:ref:`CalcHist`
function, that can initialize the ranges as well. Ranges for the histogram bins must be set before the histogram is calculated or the backproject of the histogram is calculated.