Purpose: updated the imgproc chapter

This commit is contained in:
Elena Fedotova 2011-04-24 21:02:14 +00:00
parent 91d813bc89
commit e2caf4a3ed
3 changed files with 262 additions and 242 deletions

View File

@ -13,32 +13,32 @@ calcHist
.. c:function:: void calcHist( const Mat* arrays, int narrays, const int* channels, const Mat\& mask, SparseMat\& hist, int dims, const int* histSize, const float** ranges, bool uniform=true, bool accumulate=false )
Calculates histogram of a set of arrays
Calculates a histogram of a set of arrays.
:param arrays: Source arrays. They all should have the same depth, ``CV_8U`` or ``CV_32F`` , and the same size. Each of them can have an arbitrary number of channels
:param arrays: Source arrays. They all should have the same depth, ``CV_8U`` or ``CV_32F`` , and the same size. Each of them can have an arbitrary number of channels.
:param narrays: The number of source arrays
:param narrays: Number of source arrays.
:param channels: The list of ``dims`` channels that are used to compute the histogram. The first array channels are numerated from 0 to ``arrays[0].channels()-1`` , the second array channels are counted from ``arrays[0].channels()`` to ``arrays[0].channels() + arrays[1].channels()-1`` etc.
:param channels: List of the ``dims`` channels used to compute the histogram. The first array channels are numerated from 0 to ``arrays[0].channels()-1`` , the second array channels are counted from ``arrays[0].channels()`` to ``arrays[0].channels() + arrays[1].channels()-1`` etc.
:param mask: The optional mask. If the matrix is not empty, it must be 8-bit array of the same size as ``arrays[i]`` . The non-zero mask elements mark the array elements that are counted in the histogram
:param mask: Optional mask. If the matrix is not empty, it must be an 8-bit array of the same size as ``arrays[i]`` . The non-zero mask elements mark the array elements counted in the histogram.
:param hist: The output histogram, a dense or sparse ``dims`` -dimensional array
:param hist: Output histogram, which is a dense or sparse ``dims`` -dimensional array.
:param dims: The histogram dimensionality; must be positive and not greater than ``CV_MAX_DIMS`` (=32 in the current OpenCV version)
:param dims: Histogram dimensionality that must be positive and not greater than ``CV_MAX_DIMS`` (=32 in the current OpenCV version).
:param histSize: The array of histogram sizes in each dimension
:param histSize: Array of histogram sizes in each dimension.
:param ranges: The array of ``dims`` arrays of the histogram bin boundaries in each dimension. When the histogram is uniform ( ``uniform`` =true), then for each dimension ``i`` it's enough to specify the lower (inclusive) boundary :math:`L_0` of the 0-th histogram bin and the upper (exclusive) boundary :math:`U_{\texttt{histSize}[i]-1}` for the last histogram bin ``histSize[i]-1`` . That is, in the case of uniform histogram each of ``ranges[i]`` is an array of 2 elements. When the histogram is not uniform ( ``uniform=false`` ), then each of ``ranges[i]`` contains ``histSize[i]+1`` elements: :math:`L_0, U_0=L_1, U_1=L_2, ..., U_{\texttt{histSize[i]}-2}=L_{\texttt{histSize[i]}-1}, U_{\texttt{histSize[i]}-1}` . The array elements, which are not between :math:`L_0` and :math:`U_{\texttt{histSize[i]}-1}` , are not counted in the histogram
:param ranges: Array of the ``dims`` arrays of the histogram bin boundaries in each dimension. When the histogram is uniform ( ``uniform`` =true), then for each dimension ``i`` it is enough to specify the lower (inclusive) boundary :math:`L_0` of the 0-th histogram bin and the upper (exclusive) boundary :math:`U_{\texttt{histSize}[i]-1}` for the last histogram bin ``histSize[i]-1`` . That is, in case of a uniform histogram each of ``ranges[i]`` is an array of 2 elements. When the histogram is not uniform ( ``uniform=false`` ), then each of ``ranges[i]`` contains ``histSize[i]+1`` elements: :math:`L_0, U_0=L_1, U_1=L_2, ..., U_{\texttt{histSize[i]}-2}=L_{\texttt{histSize[i]}-1}, U_{\texttt{histSize[i]}-1}` . The array elements, that are not between :math:`L_0` and :math:`U_{\texttt{histSize[i]}-1}` , are not counted in the histogram.
:param uniform: Indicates whether the histogram is uniform or not, see above
:param uniform: Flag indicatinfg whether the histogram is uniform or not (see above).
:param accumulate: Accumulation flag. If it is set, the histogram is not cleared in the beginning (when it is allocated). This feature allows user to compute a single histogram from several sets of arrays, or to update the histogram in time
:param accumulate: Accumulation flag. If it is set, the histogram is not cleared in the beginning when it is allocated. This feature enables you to compute a single histogram from several sets of arrays, or to update the histogram in time.
The functions ``calcHist`` calculate the histogram of one or more
arrays. The elements of a tuple that is used to increment
a histogram bin are taken at the same location from the corresponding
input arrays. The sample below shows how to compute 2D Hue-Saturation histogram for a color imag ::
arrays. The elements of a tuple used to increment
a histogram bin are taken from the corresponding
input arrays at the same location. The sample below shows how to compute a 2D Hue-Saturation histogram for a color image. ::
#include <cv.h>
#include <highgui.h>
@ -53,7 +53,7 @@ input arrays. The sample below shows how to compute 2D Hue-Saturation histogram
cvtColor(src, hsv, CV_BGR2HSV);
// let's quantize the hue to 30 levels
// Quantize the hue to 30 levels
// and the saturation to 32 levels
int hbins = 30, sbins = 32;
int histSize[] = {hbins, sbins};
@ -109,35 +109,37 @@ calcBackProject
Calculates the back projection of a histogram.
:param arrays: Source arrays. They all should have the same depth, ``CV_8U`` or ``CV_32F`` , and the same size. Each of them can have an arbitrary number of channels
:param arrays: Source arrays. They all should have the same depth, ``CV_8U`` or ``CV_32F`` , and the same size. Each of them can have an arbitrary number of channels.
:param narrays: The number of source arrays
:param narrays: Number of source arrays.
:param channels: The list of channels that are used to compute the back projection. The number of channels must match the histogram dimensionality. The first array channels are numerated from 0 to ``arrays[0].channels()-1`` , the second array channels are counted from ``arrays[0].channels()`` to ``arrays[0].channels() + arrays[1].channels()-1`` etc.
:param channels: The list of channels that are used to compute the back projection. The number of channels must match the histogram dimensionality. The first array channels are numerated from 0 to ``arrays[0].channels()-1`` , the second array channels are counted from ``arrays[0].channels()`` to ``arrays[0].channels() + arrays[1].channels()-1`` and so on.
:param hist: The input histogram, a dense or sparse
:param hist: Input histogram that can be dense or sparse.
:param backProject: Destination back projection aray; will be a single-channel array of the same size and the same depth as ``arrays[0]``
:param ranges: The array of arrays of the histogram bin boundaries in each dimension. See :func:`calcHist`
:param scale: The optional scale factor for the output back projection
:param backProject: Destination back projection aray that is a single-channel array of the same size and depth as ``arrays[0]`` .
:param ranges: Array of arrays of the histogram bin boundaries in each dimension. See :func:`calcHist` .
:param scale: Optional scale factor for the output back projection.
:param uniform: Indicates whether the histogram is uniform or not, see above
:param uniform: Flag indicating whether the histogram is uniform or not (see above).
The functions ``calcBackProject`` calculate the back project of the histogram. That is, similarly to ``calcHist`` , at each location ``(x, y)`` the function collects the values from the selected channels in the input images and finds the corresponding histogram bin. But instead of incrementing it, the function reads the bin value, scales it by ``scale`` and stores in ``backProject(x,y)`` . In terms of statistics, the function computes probability of each element value in respect with the empirical probability distribution represented by the histogram. Here is how, for example, you can find and track a bright-colored object in a scene:
The functions ``calcBackProject`` calculate the back project of the histogram. That is, similarly to ``calcHist`` , at each location ``(x, y)`` the function collects the values from the selected channels in the input images and finds the corresponding histogram bin. But instead of incrementing it, the function reads the bin value, scales it by ``scale`` , and stores in ``backProject(x,y)`` . In terms of statistics, the function computes probability of each element value in respect with the empirical probability distribution represented by the histogram. See how, for example, you can find and track a bright-colored object in a scene:
#.
Before the tracking, show the object to the camera such that covers almost the whole frame. Calculate a hue histogram. The histogram will likely have a strong maximums, corresponding to the dominant colors in the object.
Before tracking, show the object to the camera so that it covers almost the whole frame. Calculate a hue histogram. The histogram may have strong maximums, corresponding to the dominant colors in the object.
#.
During the tracking, calculate back projection of a hue plane of each input video frame using that pre-computed histogram. Threshold the back projection to suppress weak colors. It may also have sense to suppress pixels with non sufficient color saturation and too dark or too bright pixels.
When tracking, calculate a back projection of a hue plane of each input video frame using that pre-computed histogram. Threshold the back projection to suppress weak colors. It may also make sense to suppress pixels with non-sufficient color saturation and too dark or too bright pixels.
#.
Find connected components in the resulting picture and choose, for example, the largest component.
That is the approximate algorithm of
This is an approximate algorithm of the
:func:`CAMShift` color object tracker.
See also:
See Also:
:func:`calcHist`
.. index:: compareHist
@ -151,20 +153,20 @@ compareHist
.. c:function:: double compareHist( const SparseMat\& H1, const SparseMat\& H2, int method )
Compares two histograms
Compares two histograms.
:param H1: The first compared histogram
:param H1: The first compared histogram.
:param H2: The second compared histogram of the same size as ``H1``
:param method: The comparison method, one of the following:
:param H2: The second compared histogram of the same size as ``H1`` .
:param method: Comparison method that could be one of the following:
* **CV_COMP_CORREL** Correlation
* **CV_COMP_CORREL** Correlation
* **CV_COMP_CHISQR** Chi-Square
* **CV_COMP_CHISQR** Chi-Square
* **CV_COMP_INTERSECT** Intersection
* **CV_COMP_INTERSECT** Intersection
* **CV_COMP_BHATTACHARYYA** Bhattacharyya distance
* **CV_COMP_BHATTACHARYYA** Bhattacharyya distance
The functions ``compareHist`` compare two dense or two sparse histograms using the specified method:
@ -181,7 +183,7 @@ The functions ``compareHist`` compare two dense or two sparse histograms using t
\bar{H_k} = \frac{1}{N} \sum _J H_k(J)
and
:math:`N` is the total number of histogram bins.
:math:`N` is a total number of histogram bins.
* Chi-Square (method=CV\_COMP\_CHISQR)
@ -204,7 +206,7 @@ The functions ``compareHist`` compare two dense or two sparse histograms using t
The function returns
:math:`d(H_1, H_2)` .
While the function works well with 1-, 2-, 3-dimensional dense histograms, it may not be suitable for high-dimensional sparse histograms, where, because of aliasing and sampling problems the coordinates of non-zero histogram bins can slightly shift. To compare such histograms or more general sparse configurations of weighted points, consider using the
While the function works well with 1-, 2-, 3-dimensional dense histograms, it may not be suitable for high-dimensional sparse histograms. In such histograms, because of aliasing and sampling problems, the coordinates of non-zero histogram bins can slightly shift. To compare such histograms or more general sparse configurations of weighted points, consider using the
:func:`calcEMD` function.
.. index:: equalizeHist
@ -217,28 +219,28 @@ equalizeHist
Equalizes the histogram of a grayscale image.
:param src: The source 8-bit single channel image
:param src: Source 8-bit single channel image.
:param dst: The destination image; will have the same size and the same type as ``src``
:param dst: Destination image of the same size and type as ``src`` .
The function equalizes the histogram of the input image using the following algorithm:
#.
calculate the histogram
:math:`H` for ``src`` .
Calculate the histogram
:math:`H` for ``src`` .
#.
normalize the histogram so that the sum of histogram bins is 255.
Normalize the histogram so that the sum of histogram bins is 255.
#.
compute the integral of the histogram:
Compute the integral of the histogram:
.. math::
H'_i = \sum _{0 \le j < i} H(j)
#.
transform the image using
Transform the image using
:math:`H'` as a look-up table:
:math:`\texttt{dst}(x,y) = H'(\texttt{src}(x,y))`

View File

@ -13,20 +13,20 @@ adaptiveThreshold
Applies an adaptive threshold to an array.
:param src: Source 8-bit single-channel image
:param src: Source 8-bit single-channel image.
:param dst: Destination image; will have the same size and the same type as ``src``
:param dst: Destination image of the same size and the same type as ``src`` .
:param maxValue: The non-zero value assigned to the pixels for which the condition is satisfied. See the discussion
:param maxValue: Non-zero value assigned to the pixels for which the condition is satisfied. See the details below.
:param adaptiveMethod: Adaptive thresholding algorithm to use, ``ADAPTIVE_THRESH_MEAN_C`` or ``ADAPTIVE_THRESH_GAUSSIAN_C`` (see the discussion)
:param adaptiveMethod: Adaptive thresholding algorithm to use, ``ADAPTIVE_THRESH_MEAN_C`` or ``ADAPTIVE_THRESH_GAUSSIAN_C`` . See the details below.
:param thresholdType: Thresholding type; must be one of ``THRESH_BINARY`` or ``THRESH_BINARY_INV``
:param blockSize: The size of a pixel neighborhood that is used to calculate a threshold value for the pixel: 3, 5, 7, and so on
:param thresholdType: Thresholding type that must be either ``THRESH_BINARY`` or ``THRESH_BINARY_INV`` .
:param blockSize: Size of a pixel neighborhood that is used to calculate a threshold value for the pixel: 3, 5, 7, and so on.
:param C: The constant subtracted from the mean or weighted mean (see the discussion); normally, it's positive, but may be zero or negative as well
:param C: Constant subtracted from the mean or weighted mean (see the details below). Normally, it is positive but may be zero or negative as well.
The function transforms a grayscale image to a binary image according to the formulas:
The function transforms a grayscale image to a binary image according to the formulae:
* **THRESH_BINARY**
@ -43,23 +43,25 @@ The function transforms a grayscale image to a binary image according to the for
where
:math:`T(x,y)` is a threshold calculated individually for each pixel.
#.
For the method ``ADAPTIVE_THRESH_MEAN_C`` the threshold value
:math:`T(x,y)` is the mean of a
*
For the method ``ADAPTIVE_THRESH_MEAN_C`` , the threshold value
:math:`T(x,y)` is a mean of the
:math:`\texttt{blockSize} \times \texttt{blockSize}` neighborhood of
:math:`(x, y)` , minus ``C`` .
:math:`(x, y)` minus ``C`` .
#.
For the method ``ADAPTIVE_THRESH_GAUSSIAN_C`` the threshold value
:math:`T(x, y)` is the weighted sum (i.e. cross-correlation with a Gaussian window) of a
*
For the method ``ADAPTIVE_THRESH_GAUSSIAN_C`` , the threshold value
:math:`T(x, y)` is a weighted sum (cross-correlation with a Gaussian window) of the
:math:`\texttt{blockSize} \times \texttt{blockSize}` neighborhood of
:math:`(x, y)` , minus ``C`` . The default sigma (standard deviation) is used for the specified ``blockSize`` , see
:math:`(x, y)` minus ``C`` . The default sigma (standard deviation) is used for the specified ``blockSize`` . See
:func:`getGaussianKernel` .
The function can process the image in-place.
See also:
:func:`threshold`,:func:`blur`,:func:`GaussianBlur`
See Also:
:func:`threshold`,
:func:`blur`,
:func:`GaussianBlur`
.. index:: cvtColor
@ -70,32 +72,33 @@ cvtColor
------------
.. c:function:: void cvtColor( const Mat& src, Mat& dst, int code, int dstCn=0 )
Converts image from one color space to another
Converts an image from one color space to another.
:param src: The source image, 8-bit unsigned, 16-bit unsigned ( ``CV_16UC...`` ) or single-precision floating-point
:param src: Source image: 8-bit unsigned, 16-bit unsigned ( ``CV_16UC...`` ), or single-precision floating-point.
:param dst: The destination image; will have the same size and the same depth as ``src``
:param code: The color space conversion code; see the discussion
:param dst: Destination image of the same size and depth as ``src`` .
:param code: Color space conversion code. See the details below.??/formatting/
:param dstCn: The number of channels in the destination image; if the parameter is 0, the number of the channels will be derived automatically from ``src`` and the ``code``
:param dstCn: Number of channels in the destination image. If the parameter is 0, the number of the channels is derived automatically from ``src`` and ``code`` .
The function converts the input image from one color
space to another. In the case of transformation to-from RGB color space the ordering of the channels should be specified explicitly (RGB or BGR).
The function converts an input image from one color
space to another. In case of transformation to-from RGB color space, the order of the channels should be specified explicitly (RGB or BGR).
The conventional ranges for R, G and B channel values are:
The conventional ranges for R, G, and B channel values are:
*
0 to 255 for ``CV_8U`` images
*
0 to 65535 for ``CV_16U`` images and
0 to 65535 for ``CV_16U`` images
*
0 to 1 for ``CV_32F`` images.
0 to 1 for ``CV_32F`` images
Of course, in the case of linear transformations the range does not matter,
but in the non-linear cases the input RGB image should be normalized to the proper value range in order to get the correct results, e.g. for RGB
:math:`\rightarrow` L*u*v* transformation. For example, if you have a 32-bit floating-point image directly converted from 8-bit image without any scaling, then it will have 0..255 value range, instead of the assumed by the function 0..1. So, before calling ``cvtColor`` , you need first to scale the image down: ::
In case of linear transformations, the range does not matter.
But in case of a non-linear transformation, an input RGB image should be normalized to the proper value range to get the correct results, for example, for RGB
:math:`\rightarrow` L*u*v* transformation. For example, if you have a 32-bit floating-point image directly converted from an 8-bit image without any scaling, then it will have the 0..255 value range, instead of 0..1 assumed by the function. So, before calling ``cvtColor`` , you need first to scale the image down: ::
img *= 1./255;
cvtColor(img, img, CV_BGR2Luv);
@ -123,7 +126,7 @@ The function can do the following transformations:
..
Some more advanced channel reordering can also be done with
More advanced channel reordering can also be done with
:func:`mixChannels` .
*
@ -145,12 +148,12 @@ The function can do the following transformations:
\end{bmatrix}
:math:`X`, :math:`Y` and
:math:`Z` cover the whole value range (in the case of floating-point images
:math:`Z` cover the whole value range (in case of floating-point images,
:math:`Z` may exceed 1).
*
RGB
:math:`\leftrightarrow` YCrCb JPEG (a.k.a. YCC) ( ``CV_BGR2YCrCb, CV_RGB2YCrCb, CV_YCrCb2BGR, CV_YCrCb2RGB`` )
:math:`\leftrightarrow` YCrCb JPEG (or YCC) ( ``CV_BGR2YCrCb, CV_RGB2YCrCb, CV_YCrCb2BGR, CV_YCrCb2RGB`` )
.. math::
@ -182,12 +185,12 @@ The function can do the following transformations:
delta = \left \{ \begin{array}{l l} 128 & \mbox{for 8-bit images} \\ 32768 & \mbox{for 16-bit images} \\ 0.5 & \mbox{for floating-point images} \end{array} \right .
Y, Cr and Cb cover the whole value range.
Y, Cr, and Cb cover the whole value range.
*
RGB :math:`\leftrightarrow` HSV ( ``CV_BGR2HSV, CV_RGB2HSV, CV_HSV2BGR, CV_HSV2RGB`` )
in the case of 8-bit and 16-bit images
R, G and B are converted to floating-point format and scaled to fit the 0 to 1 range
In case of 8-bit and 16-bit images,
R, G, and B are converted to the floating-point format and scaled to fit the 0 to 1 range.
.. math::
@ -201,10 +204,10 @@ The function can do the following transformations:
H \leftarrow \forkthree{{60(G - B)}/{S}}{if $V=R$}{{120+60(B - R)}/{S}}{if $V=G$}{{240+60(R - G)}/{S}}{if $V=B$}
if
If
:math:`H<0` then
:math:`H \leftarrow H+360` On output
:math:`0 \leq V \leq 1`, :math:`0 \leq S \leq 1`, :math:`0 \leq H \leq 360` .
:math:`H \leftarrow H+360` . On output
:math:`0 \leq V \leq 1`, :math:`0 \leq S \leq 1`, :math:`0 \leq H \leq 360` .??
The values are then converted to the destination data type:
@ -221,12 +224,12 @@ The function can do the following transformations:
V <- 65535 V, S <- 65535 S, H <- H
* 32-bit images
H, S, V are left as is
H, S, and V are left as is
*
RGB :math:`\leftrightarrow` HLS ( ``CV_BGR2HLS, CV_RGB2HLS, CV_HLS2BGR, CV_HLS2RGB`` ).
in the case of 8-bit and 16-bit images
R, G and B are converted to floating-point format and scaled to fit the 0 to 1 range.
In case of 8-bit and 16-bit images,
R, G, and B are converted to the floating-point format and scaled to fit the 0 to 1 range.
.. math::
@ -251,9 +254,9 @@ The function can do the following transformations:
{{120+60(B - R)}/{S}}{if $V_{max}=G$ }
{{240+60(R - G)}/{S}}{if $V_{max}=B$ }
if
If
:math:`H<0` then
:math:`H \leftarrow H+360` On output
:math:`H \leftarrow H+360` . On output
:math:`0 \leq L \leq 1`, :math:`0 \leq S \leq 1`, :math:`0 \leq H \leq 360` .
The values are then converted to the destination data type:
@ -274,9 +277,9 @@ The function can do the following transformations:
H, S, V are left as is
*
RGB :math:`\leftrightarrow` CIE L*a*b* ( ``CV_BGR2Lab, CV_RGB2Lab, CV_Lab2BGR, CV_Lab2RGB`` )
in the case of 8-bit and 16-bit images
R, G and B are converted to floating-point format and scaled to fit the 0 to 1 range
RGB :math:`\leftrightarrow` CIE L*a*b* ( ``CV_BGR2Lab, CV_RGB2Lab, CV_Lab2BGR, CV_Lab2RGB`` ).
In case of 8-bit and 16-bit images,
R, G, and B are converted to the floating-point format and scaled to fit the 0 to 1 range.
.. math::
@ -314,8 +317,8 @@ The function can do the following transformations:
delta = \fork{128}{for 8-bit images}{0}{for floating-point images}
On output
:math:`0 \leq L \leq 100`, :math:`-127 \leq a \leq 127`, :math:`-127 \leq b \leq 127` The values are then converted to the destination data type:
This outputs
:math:`0 \leq L \leq 100`, :math:`-127 \leq a \leq 127`, :math:`-127 \leq b \leq 127` . The values are then converted to the destination data type:
* 8-bit images
@ -324,15 +327,15 @@ The function can do the following transformations:
L \leftarrow L*255/100, \; a \leftarrow a + 128, \; b \leftarrow b + 128
* 16-bit images
currently not supported
(currently not supported)
* 32-bit images
L, a, b are left as is
L, a, and b are left as is
*
RGB :math:`\leftrightarrow` CIE L*u*v* ( ``CV_BGR2Luv, CV_RGB2Luv, CV_Luv2BGR, CV_Luv2RGB`` )
in the case of 8-bit and 16-bit images
R, G and B are converted to floating-point format and scaled to fit 0 to 1 range
RGB :math:`\leftrightarrow` CIE L*u*v* ( ``CV_BGR2Luv, CV_RGB2Luv, CV_Luv2BGR, CV_Luv2RGB`` ).
In case of 8-bit and 16-bit images,
R, G, and B are converted to the floating-point format and scaled to fit 0 to 1 range.
.. math::
@ -358,7 +361,7 @@ The function can do the following transformations:
v \leftarrow 13*L*(v' - v_n) \quad \text{where} \quad v_n=0.46831096
On output
This outputs
:math:`0 \leq L \leq 100`, :math:`-134 \leq u \leq 220`, :math:`-140 \leq v \leq 122` .
The values are then converted to the destination data type:
@ -370,29 +373,29 @@ The function can do the following transformations:
L \leftarrow 255/100 L, \; u \leftarrow 255/354 (u + 134), \; v \leftarrow 255/256 (v + 140)
* 16-bit images
currently not supported
(currently not supported)
* 32-bit images
L, u, v are left as is
L, u, and v are left as is
The above formulas for converting RGB to/from various color spaces have been taken from multiple sources on Web, primarily from the Charles Poynton site
The above formulae for converting RGB to/from various color spaces have been taken from multiple sources on the web, primarily from the Charles Poynton site
http://www.poynton.com/ColorFAQ.html
*
Bayer :math:`\rightarrow` RGB ( ``CV_BayerBG2BGR, CV_BayerGB2BGR, CV_BayerRG2BGR, CV_BayerGR2BGR, CV_BayerBG2RGB, CV_BayerGB2RGB, CV_BayerRG2RGB, CV_BayerGR2RGB`` ) The Bayer pattern is widely used in CCD and CMOS cameras. It allows one to get color pictures from a single plane where R,G and B pixels (sensors of a particular component) are interleaved like this:
Bayer :math:`\rightarrow` RGB ( ``CV_BayerBG2BGR, CV_BayerGB2BGR, CV_BayerRG2BGR, CV_BayerGR2BGR, CV_BayerBG2RGB, CV_BayerGB2RGB, CV_BayerRG2RGB, CV_BayerGR2RGB`` ). The Bayer pattern is widely used in CCD and CMOS cameras. It enables you to get color pictures from a single plane where R,G, and B pixels (sensors of a particular component) are interleaved as follows:
.. math::
\newcommand{\Rcell}{\color{red}R} \newcommand{\Gcell}{\color{green}G} \newcommand{\Bcell}{\color{blue}B} \definecolor{BackGray}{rgb}{0.8,0.8,0.8} \begin{array}{ c c c c c } \Rcell & \Gcell & \Rcell & \Gcell & \Rcell \\ \Gcell & \colorbox{BackGray}{\Bcell} & \colorbox{BackGray}{\Gcell} & \Bcell & \Gcell \\ \Rcell & \Gcell & \Rcell & \Gcell & \Rcell \\ \Gcell & \Bcell & \Gcell & \Bcell & \Gcell \\ \Rcell & \Gcell & \Rcell & \Gcell & \Rcell \end{array}
The output RGB components of a pixel are interpolated from 1, 2 or
The output RGB components of a pixel are interpolated from 1, 2, or
4 neighbors of the pixel having the same color. There are several
modifications of the above pattern that can be achieved by shifting
the pattern one pixel left and/or one pixel up. The two letters
:math:`C_1` and
:math:`C_2` in the conversion constants ``CV_Bayer`` :math:`C_1 C_2` ``2BGR`` and ``CV_Bayer`` :math:`C_1 C_2` ``2RGB`` indicate the particular pattern
type - these are components from the second row, second and third
columns, respectively. For example, the above pattern has very
type. These are components from the second row, second and third
columns, respectively. For example, the above pattern has a very
popular "BG" type.
.. index:: distanceTransform
@ -407,38 +410,36 @@ distanceTransform
Calculates the distance to the closest zero pixel for each pixel of the source image.
:param src: 8-bit, single-channel (binary) source image
:param src: 8-bit, single-channel (binary) source image.
:param dst: Output image with calculated distances; will be 32-bit floating-point, single-channel image of the same size as ``src``
:param distanceType: Type of distance; can be ``CV_DIST_L1, CV_DIST_L2`` or ``CV_DIST_C``
:param maskSize: Size of the distance transform mask; can be 3, 5 or ``CV_DIST_MASK_PRECISE`` (the latter option is only supported by the first of the functions). In the case of ``CV_DIST_L1`` or ``CV_DIST_C`` distance type the parameter is forced to 3, because a :math:`3\times 3` mask gives the same result as a :math:`5\times 5` or any larger aperture.
:param dst: Output image with calculated distances. It is a 32-bit floating-point, single-channel image of the same size as ``src`` .
:param distanceType: Type of distance. It can be ``CV_DIST_L1, CV_DIST_L2`` , or ``CV_DIST_C`` .
:param maskSize: Size of the distance transform mask. It can be 3, 5, or ``CV_DIST_MASK_PRECISE`` (the latter option is only supported by the first function??). In case of the ``CV_DIST_L1`` or ``CV_DIST_C`` distance type, the parameter is forced to 3 because a :math:`3\times 3` mask gives the same result as :math:`5\times 5` or any larger aperture.
:param labels: The optional output 2d array of labels - the discrete Voronoi diagram; will have type ``CV_32SC1`` and the same size as ``src`` . See the discussion
:param labels: Optional output 2D array of labels (the discrete Voronoi diagram). It has the type ``CV_32SC1`` and the same size as ``src`` . See the details below.
The functions ``distanceTransform`` calculate the approximate or precise
distance from every binary image pixel to the nearest zero pixel.
(for zero image pixels the distance will obviously be zero).
For zero image pixels, the distance will obviously be zero.
When ``maskSize == CV_DIST_MASK_PRECISE`` and ``distanceType == CV_DIST_L2`` , the function runs the algorithm described in
Felzenszwalb04
.
Felzenszwalb04.
In other cases the algorithm
In other cases, the algorithm
Borgefors86
is used, that is,
for pixel the function finds the shortest path to the nearest zero pixel
is used. This means that
for a pixel the function finds the shortest path to the nearest zero pixel
consisting of basic shifts: horizontal,
vertical, diagonal or knight's move (the latest is available for a
vertical, diagonal, or knight's move (the latest is available for a
:math:`5\times 5` mask). The overall distance is calculated as a sum of these
basic distances. Because the distance function should be symmetric,
all of the horizontal and vertical shifts must have the same cost (that
is denoted as ``a`` ), all the diagonal shifts must have the
same cost (denoted ``b`` ), and all knight's moves must have
the same cost (denoted ``c`` ). For ``CV_DIST_C`` and ``CV_DIST_L1`` types the distance is calculated precisely,
basic distances. Since the distance function should be symmetric,
all of the horizontal and vertical shifts must have the same cost (denoted as ``a`` ), all the diagonal shifts must have the
same cost (denoted as ``b`` ), and all knight's moves must have
the same cost (denoted as ``c`` ). For the ``CV_DIST_C`` and ``CV_DIST_L1`` types, the distance is calculated precisely,
whereas for ``CV_DIST_L2`` (Euclidian distance) the distance
can be calculated only with some relative error (a
can be calculated only with a relative error (a
:math:`5\times 5` mask
gives more accurate results). For ``a``,``b`` and ``c`` OpenCV uses the values suggested in the original paper:
gives more accurate results). For ``a``,``b`` , and ``c`` , OpenCV uses the values suggested in the original paper:
.. table::
@ -451,19 +452,19 @@ gives more accurate results). For ``a``,``b`` and ``c`` OpenCV uses the values s
============== =================== ======================
Typically, for a fast, coarse distance estimation ``CV_DIST_L2``,a
:math:`3\times 3` mask is used, and for a more accurate distance estimation ``CV_DIST_L2`` , a
:math:`3\times 3` mask is used. For a more accurate distance estimation ``CV_DIST_L2`` , a
:math:`5\times 5` mask or the precise algorithm is used.
Note that both the precise and the approximate algorithms are linear on the number of pixels.
The second variant of the function does not only compute the minimum distance for each pixel
:math:`(x, y)`,but it also identifies the nearest the nearest connected
:math:`(x, y)` but also identifies the nearest connected
component consisting of zero pixels. Index of the component is stored in
:math:`\texttt{labels}(x, y)` .
The connected components of zero pixels are also found and marked by the function.
In this mode the complexity is still linear.
That is, the function provides a very fast way to compute Voronoi diagram for the binary image.
Currently, this second variant can only use the approximate distance transform algorithm.
In this mode, the complexity is still linear.
That is, the function provides a very fast way to compute the Voronoi diagram for a binary image.
Currently, the second variant can use only the approximate distance transform algorithm.
.. index:: floodFill
@ -477,41 +478,43 @@ floodFill
Fills a connected component with the given color.
:param image: Input/output 1- or 3-channel, 8-bit or floating-point image. It is modified by the function unless the ``FLOODFILL_MASK_ONLY`` flag is set (in the second variant of the function; see below)
:param image: Input/output 1- or 3-channel, 8-bit, or floating-point image. It is modified by the function unless the ``FLOODFILL_MASK_ONLY`` flag is set in the second variant of the function. See the details below.
:param mask: (For the second function only) Operation mask, should be a single-channel 8-bit image, 2 pixels wider and 2 pixels taller. The function uses and updates the mask, so the user takes responsibility of initializing the ``mask`` content. Flood-filling can't go across non-zero pixels in the mask, for example, an edge detector output can be used as a mask to stop filling at edges. It is possible to use the same mask in multiple calls to the function to make sure the filled area do not overlap. **Note** : because the mask is larger than the filled image, a pixel :math:`(x, y)` in ``image`` will correspond to the pixel :math:`(x+1, y+1)` in the ``mask``
:param seed: The starting point
:param mask: (For the second function only) Operation mask that should be a single-channel 8-bit image, 2 pixels wider and 2 pixels taller. The function uses and updates the mask, so you take responsibility of initializing the ``mask`` content. Flood-filling cannot go across non-zero pixels in the mask. For example, an edge detector output can be used as a mask to stop filling at edges. It is possible to use the same mask in multiple calls to the function to make sure the filled area does not overlap.
**Note** : Since the mask is larger than the filled image, a pixel :math:`(x, y)` in ``image`` corresponds to the pixel :math:`(x+1, y+1)` in the ``mask`` .
:param seed: Starting point.
:param newVal: New value of the repainted domain pixels
:param newVal: New value of the repainted domain pixels.
:param loDiff: Maximal lower brightness/color difference between the currently observed pixel and one of its neighbors belonging to the component, or a seed pixel being added to the component
:param loDiff: Maximal lower brightness/color difference between the currently observed pixel and one of its neighbors belonging to the component, or a seed pixel being added to the component.
:param upDiff: Maximal upper brightness/color difference between the currently observed pixel and one of its neighbors belonging to the component, or a seed pixel being added to the component
:param upDiff: Maximal upper brightness/color difference between the currently observed pixel and one of its neighbors belonging to the component, or a seed pixel being added to the component.
:param rect: The optional output parameter that the function sets to the minimum bounding rectangle of the repainted domain
:param rect: Optional output parameter set by the function to the minimum bounding rectangle of the repainted domain.
:param flags: The operation flags. Lower bits contain connectivity value, 4 (by default) or 8, used within the function. Connectivity determines which neighbors of a pixel are considered. Upper bits can be 0 or a combination of the following flags:
:param flags: Operation flags. Lower bits contain a connectivity value, 4 (default) or 8, used within the function. Connectivity determines which neighbors of a pixel are considered. Upper bits can be 0 or a combination of the following flags:
* **FLOODFILL_FIXED_RANGE** if set, the difference between the current pixel and seed pixel is considered, otherwise the difference between neighbor pixels is considered (i.e. the range is floating)
* **FLOODFILL_FIXED_RANGE** If set, the difference between the current pixel and seed pixel is considered. Otherwise, the difference between neighbor pixels is considered (that is, the range is floating).
* **FLOODFILL_MASK_ONLY** (for the second variant only) if set, the function does not change the image ( ``newVal`` is ignored), but fills the mask
* **FLOODFILL_MASK_ONLY** If set, the function does not change the image ( ``newVal`` is ignored), but fills the mask. The flag can be used for the second variant only.
The functions ``floodFill`` fill a connected component starting from the seed point with the specified color. The connectivity is determined by the color/brightness closeness of the neighbor pixels. The pixel at
:math:`(x,y)` is considered to belong to the repainted domain if:
:math:`(x,y)` is considered to belong to the repainted domain if??:
* grayscale image, floating range
* Grayscale image, floating range
.. math::
\texttt{src} (x',y')- \texttt{loDiff} \leq \texttt{src} (x,y) \leq \texttt{src} (x',y')+ \texttt{upDiff}
* grayscale image, fixed range
* Grayscale image, fixed range
.. math::
\texttt{src} ( \texttt{seed} .x, \texttt{seed} .y)- \texttt{loDiff} \leq \texttt{src} (x,y) \leq \texttt{src} ( \texttt{seed} .x, \texttt{seed} .y)+ \texttt{upDiff}
* color image, floating range
* Color image, floating range
.. math::
@ -525,7 +528,7 @@ The functions ``floodFill`` fill a connected component starting from the seed po
\texttt{src} (x',y')_b- \texttt{loDiff} _b \leq \texttt{src} (x,y)_b \leq \texttt{src} (x',y')_b+ \texttt{upDiff} _b
* color image, fixed range
* Color image, fixed range
.. math::
@ -540,17 +543,17 @@ The functions ``floodFill`` fill a connected component starting from the seed po
\texttt{src} ( \texttt{seed} .x, \texttt{seed} .y)_b- \texttt{loDiff} _b \leq \texttt{src} (x,y)_b \leq \texttt{src} ( \texttt{seed} .x, \texttt{seed} .y)_b+ \texttt{upDiff} _b
where
:math:`src(x',y')` is the value of one of pixel neighbors that is already known to belong to the component. That is, to be added to the connected component, a pixel's color/brightness should be close enough to the:
:math:`src(x',y')` is the value of one of pixel neighbors that is already known to belong to the component. That is, to be added to the connected component, a color/brightness of the pixel should be close enough to:
*
color/brightness of one of its neighbors that are already referred to the connected component in the case of floating range
Color/brightness of one of its neighbors that are already referred to in?? the connected component in case of floating range.
*
color/brightness of the seed point in the case of fixed range.
Color/brightness of the seed point in case of fixed range.
By using these functions you can either mark a connected component with the specified color in-place, or build a mask and then extract the contour or copy the region to another image etc. Various modes of the function are demonstrated in ``floodfill.c`` sample.
Use these functions to either mark a connected component with the specified color in-place, or build a mask and then extract the contour, or copy the region to another image, and so on. Various modes of the function are demonstrated in the ``floodfill.c`` sample.
See also:
See Also:
:func:`findContours`
.. index:: inpaint
@ -561,21 +564,21 @@ inpaint
-----------
.. c:function:: void inpaint( const Mat& src, const Mat& inpaintMask, Mat& dst, double inpaintRadius, int flags )
Inpaints the selected region in the image.
Removes?? the selected region in an image.
:param src: The input 8-bit 1-channel or 3-channel image.
:param src: Input 8-bit 1-channel or 3-channel image.
:param inpaintMask: The inpainting mask, 8-bit 1-channel image. Non-zero pixels indicate the area that needs to be inpainted.
:param inpaintMask: Inpainting mask, 8-bit 1-channel image. Non-zero pixels indicate the area that needs to be inpainted.
:param dst: The output image; will have the same size and the same type as ``src``
:param dst: Output image with the same size and type as ``src`` .
:param inpaintRadius: The radius of a circlular neighborhood of each point inpainted that is considered by the algorithm.
:param inpaintRadius: Radius of a circlular neighborhood of each point inpainted that is considered by the algorithm.
:param flags: The inpainting method, one of the following:
:param flags: Inpainting method that could be one of the following:
* **INPAINT_NS** Navier-Stokes based method.
* **INPAINT_NS** Navier-Stokes based method.
* **INPAINT_TELEA** The method by Alexandru Telea Telea04
* **INPAINT_TELEA** Method by Alexandru Telea Telea04.
The function reconstructs the selected image area from the pixel near the area boundary. The function may be used to remove dust and scratches from a scanned photo, or to remove undesirable objects from still images or video. See
http://en.wikipedia.org/wiki/Inpainting
@ -595,15 +598,15 @@ integral
Calculates the integral of an image.
:param image: The source image, :math:`W \times H` , 8-bit or floating-point (32f or 64f)
:param image: Source image as :math:`W \times H` , 8-bit or floating-point (32f or 64f).
:param sum: The integral image, :math:`(W+1)\times (H+1)` , 32-bit integer or floating-point (32f or 64f)
:param sum: Integral image as :math:`(W+1)\times (H+1)` , 32-bit integer or floating-point (32f or 64f).
:param sqsum: The integral image for squared pixel values, :math:`(W+1)\times (H+1)` , double precision floating-point (64f)
:param sqsum: Integral image for squared pixel values represented as?? :math:`(W+1)\times (H+1)` , double precision floating-point (64f).
:param tilted: The integral for the image rotated by 45 degrees, :math:`(W+1)\times (H+1)` , the same data type as ``sum``
:param tilted: Integral for the image rotated by 45 degrees represented as :math:`(W+1)\times (H+1)` , with the same data type as ``sum`` .
:param sdepth: The desired depth of the integral and the tilted integral images, ``CV_32S`` , ``CV_32F`` or ``CV_64F``
:param sdepth: Desired depth of the integral and the tilted integral images, ``CV_32S`` , ``CV_32F`` , or ``CV_64F`` .
The functions calculate one or more integral images for the source image as following:
@ -619,13 +622,13 @@ The functions calculate one or more integral images for the source image as foll
\texttt{tilted} (X,Y) = \sum _{y<Y,abs(x-X+1) \leq Y-y-1} \texttt{image} (x,y)
Using these integral images, one may calculate sum, mean and standard deviation over a specific up-right or rotated rectangular region of the image in a constant time, for example:
Using these integral images, you can calculate sum, mean and standard deviation over a specific up-right or rotated rectangular region of the image in a constant time, for example:
.. math::
\sum _{x_1 \leq x < x_2, \, y_1 \leq y < y_2} \texttt{image} (x,y) = \texttt{sum} (x_2,y_2)- \texttt{sum} (x_1,y_2)- \texttt{sum} (x_2,y_1)+ \texttt{sum} (x_1,x_1)
It makes possible to do a fast blurring or fast block correlation with variable window size, for example. In the case of multi-channel images, sums for each channel are accumulated independently.
It makes possible to do a fast blurring or fast block correlation with a variable window size, for example. In case of multi-channel images, sums for each channel are accumulated independently.
As a practical example, the next figure shows the calculation of the integral of a straight rectangle ``Rect(3,3,3,2)`` and of a tilted rectangle ``Rect(5,1,2,3)`` . The selected pixels in the original ``image`` are shown, as well as the relative pixels in the integral images ``sum`` and ``tilted`` .
@ -643,25 +646,25 @@ threshold
-------------
.. c:function:: double threshold( const Mat& src, Mat& dst, double thresh, double maxVal, int thresholdType )
Applies a fixed-level threshold to each array element
Applies a fixed-level threshold to each array element.
:param src: Source array (single-channel, 8-bit of 32-bit floating point)
:param dst: Destination array; will have the same size and the same type as ``src``
:param dst: Destination array of the same size and type as ``src`` .
:param thresh: Threshold value
:param thresh: Threshold value.
:param maxVal: Maximum value to use with ``THRESH_BINARY`` and ``THRESH_BINARY_INV`` thresholding types
:param maxVal: Maximum value to use with the ``THRESH_BINARY`` and ``THRESH_BINARY_INV`` thresholding types.
:param thresholdType: Thresholding type (see the discussion)
:param thresholdType: Thresholding type (see the details below).
The function applies fixed-level thresholding
to a single-channel array. The function is typically used to get a
bi-level (binary) image out of a grayscale image (
:func:`compare` could
be also used for this purpose) or for removing a noise, i.e. filtering
be also used for this purpose) or for removing a noise, that is, filtering
out pixels with too small or too large values. There are several
types of thresholding that the function supports that are determined by ``thresholdType`` :
types of thresholding supported by the function. They are determined by ``thresholdType`` :
* **THRESH_BINARY**
@ -694,15 +697,18 @@ types of thresholding that the function supports that are determined by ``thresh
\texttt{dst} (x,y) = \fork{0}{if $\texttt{src}(x,y) > \texttt{thresh}$}{\texttt{src}(x,y)}{otherwise}
Also, the special value ``THRESH_OTSU`` may be combined with
one of the above values. In this case the function determines the optimal threshold
one of the above values. In this case, the function determines the optimal threshold
value using Otsu's algorithm and uses it instead of the specified ``thresh`` .
The function returns the computed threshold value.
Currently, Otsu's method is implemented only for 8-bit images.
.. image:: pics/threshold.png
See also:
:func:`adaptiveThreshold`,:func:`findContours`,:func:`compare`,:func:`min`,:func:`max`
See Also:
:func:`adaptiveThreshold`,
:func:`findContours`,
:func:`compare`,
:func:`min`,:func:`max`
.. index:: watershed
@ -712,38 +718,38 @@ watershed
-------------
.. c:function:: void watershed( const Mat& image, Mat& markers )
Does marker-based image segmentation using watershed algrorithm
Performs a marker-based image segmentation using the watershed algrorithm.
:param image: The input 8-bit 3-channel image.
:param image: Input 8-bit 3-channel image.
:param markers: The input/output 32-bit single-channel image (map) of markers. It should have the same size as ``image``
:param markers: Input/output 32-bit single-channel image (map) of markers. It should have the same size as ``image`` .
The function implements one of the variants
of watershed, non-parametric marker-based segmentation algorithm,
described in
Meyer92
Meyer92??
. Before passing the image to the
function, user has to outline roughly the desired regions in the image ``markers`` with positive (
:math:`>0` ) indices, i.e. every region is
function, you have to roughly outline the desired regions in the image ``markers`` with positive (
:math:`>0` ) indices. So, every region is
represented as one or more connected components with the pixel values
1, 2, 3 etc (such markers can be retrieved from a binary mask
1, 2, 3, and so on. Such markers can be retrieved from a binary mask
using
:func:`findContours` and
:func:`drawContours` , see ``watershed.cpp`` demo).
The markers will be "seeds" of the future image
regions. All the other pixels in ``markers`` , which relation to the
:func:`drawContours` (see the ``watershed.cpp`` demo).
The markers are "seeds" of the future image
regions. All the other pixels in ``markers`` , whose relation to the
outlined regions is not known and should be defined by the algorithm,
should be set to 0's. On the output of the function, each pixel in
markers is set to one of values of the "seed" components, or to -1 at
should be set to 0's. In the function output, each pixel in
markers is set to a value of the "seed" components or to -1 at
boundaries between the regions.
Note, that it is not necessary that every two neighbor connected
components are separated by a watershed boundary (-1's pixels), for
example, in case when such tangent components exist in the initial
**Note**: Every two neighbor connected
components are not necessarily separated by a watershed boundary (-1's pixels); for
example, when such tangent components exist in the initial
marker image. Visual demonstration and usage example of the function
can be found in OpenCV samples directory; see ``watershed.cpp`` demo.
can be found in the OpenCV samples directory (see the ``watershed.cpp`` demo).
See also:
See Also:
:func:`findContours`
.. index:: grabCut
@ -755,32 +761,33 @@ grabCut
.. c:function:: void grabCut(const Mat& image, Mat& mask, Rect rect, Mat& bgdModel, Mat& fgdModel, int iterCount, int mode )
Runs GrabCut algorithm
Runs the GrabCut algorithm.
:param image: The input 8-bit 3-channel image.
:param image: Input 8-bit 3-channel image.
:param mask: The input/output 8-bit single-channel mask. Its elements may have one of four values. The mask is initialize when ``mode==GC_INIT_WITH_RECT``
* **GC_BGD** Certainly a background pixel
:param mask: Input/output 8-bit single-channel mask. Its elements may have one of four values. The mask is initialized when ``mode==GC_INIT_WITH_RECT`` .
* **GC_BGD** defines an obvious background pixel.??
* **GC_FGD** Certainly a foreground (object) pixel
* **GC_FGD** defines an obvious foreground (object) pixel.
* **GC_PR_BGD** Likely a background pixel
* **GC_PR_BGD** defines a possible background pixel.
* **GC_PR_BGD** Likely a foreground pixel
* **GC_PR_BGD** defines a possible foreground pixel.
:param rect: The ROI containing the segmented object. The pixels outside of the ROI are marked as "certainly a background". The parameter is only used when ``mode==GC_INIT_WITH_RECT``
:param rect: ROI containing a segmented object. The pixels outside of the ROI are marked as "obvious background"??. The parameter is only used when ``mode==GC_INIT_WITH_RECT`` .
:param bgdModel, fgdModel: Temporary arrays used for segmentation. Do not modify them while you are processing the same image
:param bgdModel, fgdModel: Temporary arrays used for segmentation. Do not modify them while you are processing the same image.
:param iterCount: The number of iterations the algorithm should do before returning the result. Note that the result can be refined with further calls with the ``mode==GC_INIT_WITH_MASK`` or ``mode==GC_EVAL``
:param iterCount: Number of iterations the algorithm should make before returning the result. Note that the result can be refined with further calls with ``mode==GC_INIT_WITH_MASK`` or ``mode==GC_EVAL`` .
:param mode: The operation mode
:param mode: Operation mode that could be one of the following:
* **GC_INIT_WITH_RECT** The function initializes the state and the mask using the provided rectangle. After that it runs ``iterCount`` iterations of the algorithm
* **GC_INIT_WITH_RECT** The function initializes the state and the mask using the provided rectangle. After that it runs ``iterCount`` iterations of the algorithm.
* **GC_INIT_WITH_MASK** The function initializes the state using the provided mask. Note that ``GC_INIT_WITH_RECT`` and ``GC_INIT_WITH_MASK`` can be combined, then all the pixels outside of the ROI are automatically initialized with ``GC_BGD``.
* **GC_INIT_WITH_MASK** The function initializes the state using the provided mask. Note that ``GC_INIT_WITH_RECT`` and ``GC_INIT_WITH_MASK`` can be combined. Then, all the pixels outside of the ROI are automatically initialized with ``GC_BGD`` .
* **GC_EVAL** The value means that algorithm should just resume.
* **GC_EVAL** The value means that algorithm should just resume.
The function implements the `GrabCut image segmentation algorithm <http://en.wikipedia.org/wiki/GrabCut>`_.
See the sample grabcut.cpp on how to use the function.
See the sample grabcut.cpp to learn how to use the function.

View File

@ -9,39 +9,41 @@ accumulate
--------------
.. c:function:: void accumulate( const Mat\& src, Mat\& dst, const Mat\& mask=Mat() )
Adds image to the accumulator.
Adds an image to the accumulator.
:param src: The input image, 1- or 3-channel, 8-bit or 32-bit floating point
:param src: Input image as 1- or 3-channel, 8-bit or 32-bit floating point.
:param dst: The accumulator image with the same number of channels as input image, 32-bit or 64-bit floating-point
:param dst: Accumulator image with the same number of channels as input image, 32-bit or 64-bit floating-point.
:param mask: Optional operation mask
:param mask: Optional operation mask.
The function adds ``src`` , or some of its elements, to ``dst`` :
The function adds ``src`` or some of its elements to ``dst`` :
.. math::
\texttt{dst} (x,y) \leftarrow \texttt{dst} (x,y) + \texttt{src} (x,y) \quad \text{if} \quad \texttt{mask} (x,y) \ne 0
The function supports multi-channel images; each channel is processed independently.
The function supports multi-channel images. Each channel is processed independently.
The functions ``accumulate*`` can be used, for example, to collect statistic of background of a scene, viewed by a still camera, for the further foreground-background segmentation.
The functions ``accumulate*`` can be used, for example, to collect statistics of a scene background viewed by a still camera and for the further foreground-background segmentation.
See also:
:func:`accumulateSquare`,:func:`accumulateProduct`,:func:`accumulateWeighted`
See Also:
:func:`accumulateSquare`,
:func:`accumulateProduct`,
:func:`accumulateWeighted`
.. index:: accumulateSquare
accumulateSquare
--------------------
.. c:function:: void accumulateSquare( const Mat\& src, Mat\& dst, const Mat\& mask=Mat() )
Adds the square of the source image to the accumulator.
Adds the square of a source image to the accumulator.
:param src: The input image, 1- or 3-channel, 8-bit or 32-bit floating point
:param src: Input image as 1- or 3-channel, 8-bit or 32-bit floating point.
:param dst: The accumulator image with the same number of channels as input image, 32-bit or 64-bit floating-point
:param dst: Accumulator image with the same number of channels as input image, 32-bit or 64-bit floating-point.
:param mask: Optional operation mask
:param mask: Optional operation mask.
The function adds the input image ``src`` or its selected region, raised to power 2, to the accumulator ``dst`` :
@ -49,10 +51,13 @@ The function adds the input image ``src`` or its selected region, raised to powe
\texttt{dst} (x,y) \leftarrow \texttt{dst} (x,y) + \texttt{src} (x,y)^2 \quad \text{if} \quad \texttt{mask} (x,y) \ne 0
The function supports multi-channel images; each channel is processed independently.
The function supports multi-channel images Each channel is processed independently.
See Also:
:func:`accumulateSquare`,
:func:`accumulateProduct`,
:func:`accumulateWeighted`
See also:
:func:`accumulateSquare`,:func:`accumulateProduct`,:func:`accumulateWeighted`
.. index:: accumulateProduct
accumulateProduct
@ -61,12 +66,13 @@ accumulateProduct
Adds the per-element product of two input images to the accumulator.
:param src1: The first input image, 1- or 3-channel, 8-bit or 32-bit floating point
:param src1: The first input image, 1- or 3-channel, 8-bit or 32-bit floating point.
:param src2: The second input image of the same type and the same size as ``src1``
:param dst: Accumulator with the same number of channels as input images, 32-bit or 64-bit floating-point
:param src2: The second input image of the same type and the same size as ``src1`` .
:param dst: Accumulator with the same number of channels as input images, 32-bit or 64-bit floating-point.
:param mask: Optional operation mask
:param mask: Optional operation mask.
The function adds the product of 2 images or their selected regions to the accumulator ``dst`` :
@ -74,34 +80,39 @@ The function adds the product of 2 images or their selected regions to the accum
\texttt{dst} (x,y) \leftarrow \texttt{dst} (x,y) + \texttt{src1} (x,y) \cdot \texttt{src2} (x,y) \quad \text{if} \quad \texttt{mask} (x,y) \ne 0
The function supports multi-channel images; each channel is processed independently.
The function supports multi-channel images. Each channel is processed independently.
See Also:
:func:`accumulate`,
:func:`accumulateSquare`,
:func:`accumulateWeighted`
See also:
:func:`accumulate`,:func:`accumulateSquare`,:func:`accumulateWeighted`
.. index:: accumulateWeighted
accumulateWeighted
----------------------
.. c:function:: void accumulateWeighted( const Mat\& src, Mat\& dst, double alpha, const Mat\& mask=Mat() )
Updates the running average.
Updates a running average.
:param src: The input image, 1- or 3-channel, 8-bit or 32-bit floating point
:param src: Input image as 1- or 3-channel, 8-bit or 32-bit floating point.
:param dst: The accumulator image with the same number of channels as input image, 32-bit or 64-bit floating-point
:param dst: Accumulator image with the same number of channels as input image, 32-bit or 64-bit floating-point.
:param alpha: Weight of the input image
:param alpha: Weight of the input image.
:param mask: Optional operation mask
:param mask: Optional operation mask.
The function calculates the weighted sum of the input image ``src`` and the accumulator ``dst`` so that ``dst`` becomes a running average of frame sequence:
The function calculates the weighted sum of the input image ``src`` and the accumulator ``dst`` so that ``dst`` becomes a running average of a frame sequence:
.. math::
\texttt{dst} (x,y) \leftarrow (1- \texttt{alpha} ) \cdot \texttt{dst} (x,y) + \texttt{alpha} \cdot \texttt{src} (x,y) \quad \text{if} \quad \texttt{mask} (x,y) \ne 0
that is, ``alpha`` regulates the update speed (how fast the accumulator "forgets" about earlier images).
The function supports multi-channel images; each channel is processed independently.
That is, ``alpha`` regulates the update speed (how fast the accumulator "forgets" about earlier images).
The function supports multi-channel images. Each channel is processed independently.
See also:
:func:`accumulate`,:func:`accumulateSquare`,:func:`accumulateProduct`
See Also:
:func:`accumulate`,
:func:`accumulateSquare`,
:func:`accumulateProduct`