OpenCV reference manual (C++ part only for now) is now produced directly from RST, not from TeX.
This commit is contained in:
829
modules/imgproc/doc/feature_detection.rst
Normal file
829
modules/imgproc/doc/feature_detection.rst
Normal file
@@ -0,0 +1,829 @@
|
||||
Feature Detection
|
||||
=================
|
||||
|
||||
.. highlight:: cpp
|
||||
|
||||
|
||||
|
||||
.. index:: Canny
|
||||
|
||||
|
||||
cv::Canny
|
||||
---------
|
||||
|
||||
`id=0.626295418243 Comments from the Wiki <http://opencv.willowgarage.com/wiki/documentation/cpp/imgproc/Canny>`__
|
||||
|
||||
|
||||
|
||||
|
||||
.. cfunction:: void Canny( const Mat\& image, Mat\& edges, double threshold1, double threshold2, int apertureSize=3, bool L2gradient=false )
|
||||
|
||||
Finds edges in an image using Canny algorithm.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
:param image: Single-channel 8-bit input image
|
||||
|
||||
|
||||
:param edges: The output edge map. It will have the same size and the same type as ``image``
|
||||
|
||||
|
||||
:param threshold1: The first threshold for the hysteresis procedure
|
||||
|
||||
|
||||
:param threshold2: The second threshold for the hysteresis procedure
|
||||
|
||||
|
||||
:param apertureSize: Aperture size for the :func:`Sobel` operator
|
||||
|
||||
|
||||
:param L2gradient: Indicates, whether the more accurate :math:`L_2` norm :math:`=\sqrt{(dI/dx)^2 + (dI/dy)^2}` should be used to compute the image gradient magnitude ( ``L2gradient=true`` ), or a faster default :math:`L_1` norm :math:`=|dI/dx|+|dI/dy|` is enough ( ``L2gradient=false`` )
|
||||
|
||||
|
||||
|
||||
The function finds edges in the input image
|
||||
``image``
|
||||
and marks them in the output map
|
||||
``edges``
|
||||
using the Canny algorithm. The smallest value between
|
||||
``threshold1``
|
||||
and
|
||||
``threshold2``
|
||||
is used for edge linking, the largest value is used to find the initial segments of strong edges, see
|
||||
http://en.wikipedia.org/wiki/Canny_edge_detector
|
||||
|
||||
.. index:: cornerEigenValsAndVecs
|
||||
|
||||
|
||||
cv::cornerEigenValsAndVecs
|
||||
--------------------------
|
||||
|
||||
`id=0.211221916008 Comments from the Wiki <http://opencv.willowgarage.com/wiki/documentation/cpp/imgproc/cornerEigenValsAndVecs>`__
|
||||
|
||||
|
||||
|
||||
|
||||
.. cfunction:: void cornerEigenValsAndVecs( const Mat\& src, Mat\& dst, int blockSize, int apertureSize, int borderType=BORDER_DEFAULT )
|
||||
|
||||
Calculates eigenvalues and eigenvectors of image blocks for corner detection.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
:param src: Input single-channel 8-bit or floating-point image
|
||||
|
||||
|
||||
:param dst: Image to store the results. It will have the same size as ``src`` and the type ``CV_32FC(6)``
|
||||
|
||||
|
||||
:param blockSize: Neighborhood size (see discussion)
|
||||
|
||||
|
||||
:param apertureSize: Aperture parameter for the :func:`Sobel` operator
|
||||
|
||||
|
||||
:param boderType: Pixel extrapolation method; see :func:`borderInterpolate`
|
||||
|
||||
|
||||
|
||||
For every pixel
|
||||
:math:`p`
|
||||
, the function
|
||||
``cornerEigenValsAndVecs``
|
||||
considers a
|
||||
``blockSize``
|
||||
:math:`\times`
|
||||
``blockSize``
|
||||
neigborhood
|
||||
:math:`S(p)`
|
||||
. It calculates the covariation matrix of derivatives over the neighborhood as:
|
||||
|
||||
|
||||
|
||||
.. math::
|
||||
|
||||
M = \begin{bmatrix} \sum _{S(p)}(dI/dx)^2 & \sum _{S(p)}(dI/dx dI/dy)^2 \\ \sum _{S(p)}(dI/dx dI/dy)^2 & \sum _{S(p)}(dI/dy)^2 \end{bmatrix}
|
||||
|
||||
|
||||
Where the derivatives are computed using
|
||||
:func:`Sobel`
|
||||
operator.
|
||||
|
||||
After that it finds eigenvectors and eigenvalues of
|
||||
:math:`M`
|
||||
and stores them into destination image in the form
|
||||
:math:`(\lambda_1, \lambda_2, x_1, y_1, x_2, y_2)`
|
||||
where
|
||||
|
||||
|
||||
|
||||
|
||||
* :math:`\lambda_1, \lambda_2`
|
||||
are the eigenvalues of
|
||||
:math:`M`
|
||||
; not sorted
|
||||
|
||||
|
||||
* :math:`x_1, y_1`
|
||||
are the eigenvectors corresponding to
|
||||
:math:`\lambda_1`
|
||||
|
||||
|
||||
* :math:`x_2, y_2`
|
||||
are the eigenvectors corresponding to
|
||||
:math:`\lambda_2`
|
||||
|
||||
|
||||
The output of the function can be used for robust edge or corner detection.
|
||||
|
||||
See also:
|
||||
:func:`cornerMinEigenVal`
|
||||
,
|
||||
:func:`cornerHarris`
|
||||
,
|
||||
:func:`preCornerDetect`
|
||||
|
||||
.. index:: cornerHarris
|
||||
|
||||
|
||||
cv::cornerHarris
|
||||
----------------
|
||||
|
||||
`id=0.781956530281 Comments from the Wiki <http://opencv.willowgarage.com/wiki/documentation/cpp/imgproc/cornerHarris>`__
|
||||
|
||||
|
||||
|
||||
|
||||
.. cfunction:: void cornerHarris( const Mat\& src, Mat\& dst, int blockSize, int apertureSize, double k, int borderType=BORDER_DEFAULT )
|
||||
|
||||
Harris edge detector.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
:param src: Input single-channel 8-bit or floating-point image
|
||||
|
||||
|
||||
:param dst: Image to store the Harris detector responses; will have type ``CV_32FC1`` and the same size as ``src``
|
||||
|
||||
|
||||
:param blockSize: Neighborhood size (see the discussion of :func:`cornerEigenValsAndVecs` )
|
||||
|
||||
|
||||
:param apertureSize: Aperture parameter for the :func:`Sobel` operator
|
||||
|
||||
|
||||
:param k: Harris detector free parameter. See the formula below
|
||||
|
||||
|
||||
:param boderType: Pixel extrapolation method; see :func:`borderInterpolate`
|
||||
|
||||
|
||||
|
||||
The function runs the Harris edge detector on the image. Similarly to
|
||||
:func:`cornerMinEigenVal`
|
||||
and
|
||||
:func:`cornerEigenValsAndVecs`
|
||||
, for each pixel
|
||||
:math:`(x, y)`
|
||||
it calculates a
|
||||
:math:`2\times2`
|
||||
gradient covariation matrix
|
||||
:math:`M^{(x,y)}`
|
||||
over a
|
||||
:math:`\texttt{blockSize} \times \texttt{blockSize}`
|
||||
neighborhood. Then, it computes the following characteristic:
|
||||
|
||||
|
||||
|
||||
.. math::
|
||||
|
||||
\texttt{dst} (x,y) = \mathrm{det} M^{(x,y)} - k \cdot \left ( \mathrm{tr} M^{(x,y)} \right )^2
|
||||
|
||||
|
||||
Corners in the image can be found as the local maxima of this response map.
|
||||
|
||||
|
||||
.. index:: cornerMinEigenVal
|
||||
|
||||
|
||||
cv::cornerMinEigenVal
|
||||
---------------------
|
||||
|
||||
`id=0.604155117868 Comments from the Wiki <http://opencv.willowgarage.com/wiki/documentation/cpp/imgproc/cornerMinEigenVal>`__
|
||||
|
||||
|
||||
|
||||
|
||||
.. cfunction:: void cornerMinEigenVal( const Mat\& src, Mat\& dst, int blockSize, int apertureSize=3, int borderType=BORDER_DEFAULT )
|
||||
|
||||
Calculates the minimal eigenvalue of gradient matrices for corner detection.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
:param src: Input single-channel 8-bit or floating-point image
|
||||
|
||||
|
||||
:param dst: Image to store the minimal eigenvalues; will have type ``CV_32FC1`` and the same size as ``src``
|
||||
|
||||
|
||||
:param blockSize: Neighborhood size (see the discussion of :func:`cornerEigenValsAndVecs` )
|
||||
|
||||
|
||||
:param apertureSize: Aperture parameter for the :func:`Sobel` operator
|
||||
|
||||
|
||||
:param boderType: Pixel extrapolation method; see :func:`borderInterpolate`
|
||||
|
||||
|
||||
|
||||
The function is similar to
|
||||
:func:`cornerEigenValsAndVecs`
|
||||
but it calculates and stores only the minimal eigenvalue of the covariation matrix of derivatives, i.e.
|
||||
:math:`\min(\lambda_1, \lambda_2)`
|
||||
in terms of the formulae in
|
||||
:func:`cornerEigenValsAndVecs`
|
||||
description.
|
||||
|
||||
|
||||
.. index:: cornerSubPix
|
||||
|
||||
|
||||
cv::cornerSubPix
|
||||
----------------
|
||||
|
||||
`id=0.0211213978919 Comments from the Wiki <http://opencv.willowgarage.com/wiki/documentation/cpp/imgproc/cornerSubPix>`__
|
||||
|
||||
|
||||
|
||||
|
||||
.. cfunction:: void cornerSubPix( const Mat\& image, vector<Point2f>\& corners, Size winSize, Size zeroZone, TermCriteria criteria )
|
||||
|
||||
Refines the corner locations.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
:param image: Input image
|
||||
|
||||
|
||||
:param corners: Initial coordinates of the input corners; refined coordinates on output
|
||||
|
||||
|
||||
:param winSize: Half of the side length of the search window. For example, if ``winSize=Size(5,5)`` , then a :math:`5*2+1 \times 5*2+1 = 11 \times 11` search window would be used
|
||||
|
||||
|
||||
:param zeroZone: Half of the size of the dead region in the middle of the search zone over which the summation in the formula below is not done. It is used sometimes to avoid possible singularities of the autocorrelation matrix. The value of (-1,-1) indicates that there is no such size
|
||||
|
||||
|
||||
:param criteria: Criteria for termination of the iterative process of corner refinement. That is, the process of corner position refinement stops either after a certain number of iterations or when a required accuracy is achieved. The ``criteria`` may specify either of or both the maximum number of iteration and the required accuracy
|
||||
|
||||
|
||||
|
||||
The function iterates to find the sub-pixel accurate location of corners, or radial saddle points, as shown in on the picture below.
|
||||
|
||||
|
||||
|
||||
.. image:: ../../pics/cornersubpix.png
|
||||
|
||||
|
||||
|
||||
Sub-pixel accurate corner locator is based on the observation that every vector from the center
|
||||
:math:`q`
|
||||
to a point
|
||||
:math:`p`
|
||||
located within a neighborhood of
|
||||
:math:`q`
|
||||
is orthogonal to the image gradient at
|
||||
:math:`p`
|
||||
subject to image and measurement noise. Consider the expression:
|
||||
|
||||
|
||||
|
||||
.. math::
|
||||
|
||||
\epsilon _i = {DI_{p_i}}^T \cdot (q - p_i)
|
||||
|
||||
|
||||
where
|
||||
:math:`{DI_{p_i}}`
|
||||
is the image gradient at the one of the points
|
||||
:math:`p_i`
|
||||
in a neighborhood of
|
||||
:math:`q`
|
||||
. The value of
|
||||
:math:`q`
|
||||
is to be found such that
|
||||
:math:`\epsilon_i`
|
||||
is minimized. A system of equations may be set up with
|
||||
:math:`\epsilon_i`
|
||||
set to zero:
|
||||
|
||||
|
||||
|
||||
.. math::
|
||||
|
||||
\sum _i(DI_{p_i} \cdot {DI_{p_i}}^T) - \sum _i(DI_{p_i} \cdot {DI_{p_i}}^T \cdot p_i)
|
||||
|
||||
|
||||
where the gradients are summed within a neighborhood ("search window") of
|
||||
:math:`q`
|
||||
. Calling the first gradient term
|
||||
:math:`G`
|
||||
and the second gradient term
|
||||
:math:`b`
|
||||
gives:
|
||||
|
||||
|
||||
|
||||
.. math::
|
||||
|
||||
q = G^{-1} \cdot b
|
||||
|
||||
|
||||
The algorithm sets the center of the neighborhood window at this new center
|
||||
:math:`q`
|
||||
and then iterates until the center keeps within a set threshold.
|
||||
|
||||
|
||||
|
||||
.. index:: goodFeaturesToTrack
|
||||
|
||||
|
||||
cv::goodFeaturesToTrack
|
||||
-----------------------
|
||||
|
||||
`id=0.784762708085 Comments from the Wiki <http://opencv.willowgarage.com/wiki/documentation/cpp/imgproc/goodFeaturesToTrack>`__
|
||||
|
||||
|
||||
|
||||
|
||||
.. cfunction:: void goodFeaturesToTrack( const Mat\& image, vector<Point2f>\& corners, int maxCorners, double qualityLevel, double minDistance, const Mat\& mask=Mat(), int blockSize=3, bool useHarrisDetector=false, double k=0.04 )
|
||||
|
||||
Determines strong corners on an image.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
:param image: The input 8-bit or floating-point 32-bit, single-channel image
|
||||
|
||||
|
||||
:param corners: The output vector of detected corners
|
||||
|
||||
|
||||
:param maxCorners: The maximum number of corners to return. If there are more corners than that will be found, the strongest of them will be returned
|
||||
|
||||
|
||||
:param qualityLevel: Characterizes the minimal accepted quality of image corners; the value of the parameter is multiplied by the by the best corner quality measure (which is the min eigenvalue, see :func:`cornerMinEigenVal` , or the Harris function response, see :func:`cornerHarris` ). The corners, which quality measure is less than the product, will be rejected. For example, if the best corner has the quality measure = 1500, and the ``qualityLevel=0.01`` , then all the corners which quality measure is less than 15 will be rejected.
|
||||
|
||||
|
||||
:param minDistance: The minimum possible Euclidean distance between the returned corners
|
||||
|
||||
|
||||
:param mask: The optional region of interest. If the image is not empty (then it needs to have the type ``CV_8UC1`` and the same size as ``image`` ), it will specify the region in which the corners are detected
|
||||
|
||||
|
||||
:param blockSize: Size of the averaging block for computing derivative covariation matrix over each pixel neighborhood, see :func:`cornerEigenValsAndVecs`
|
||||
|
||||
|
||||
:param useHarrisDetector: Indicates, whether to use operator or :func:`cornerMinEigenVal`
|
||||
|
||||
|
||||
:param k: Free parameter of Harris detector
|
||||
|
||||
|
||||
|
||||
The function finds the most prominent corners in the image or in the specified image region, as described
|
||||
in
|
||||
Shi94
|
||||
:
|
||||
|
||||
|
||||
|
||||
|
||||
#.
|
||||
the function first calculates the corner quality measure at every source image pixel using the
|
||||
:func:`cornerMinEigenVal`
|
||||
or
|
||||
:func:`cornerHarris`
|
||||
|
||||
|
||||
#.
|
||||
then it performs non-maxima suppression (the local maxima in
|
||||
:math:`3\times 3`
|
||||
neighborhood
|
||||
are retained).
|
||||
|
||||
|
||||
#.
|
||||
the next step rejects the corners with the minimal eigenvalue less than
|
||||
:math:`\texttt{qualityLevel} \cdot \max_{x,y} qualityMeasureMap(x,y)`
|
||||
.
|
||||
|
||||
|
||||
#.
|
||||
the remaining corners are then sorted by the quality measure in the descending order.
|
||||
|
||||
|
||||
#.
|
||||
finally, the function throws away each corner
|
||||
:math:`pt_j`
|
||||
if there is a stronger corner
|
||||
:math:`pt_i`
|
||||
(
|
||||
:math:`i < j`
|
||||
) such that the distance between them is less than
|
||||
``minDistance``
|
||||
|
||||
|
||||
The function can be used to initialize a point-based tracker of an object.
|
||||
|
||||
Note that the if the function is called with different values
|
||||
``A``
|
||||
and
|
||||
``B``
|
||||
of the parameter
|
||||
``qualityLevel``
|
||||
, and
|
||||
``A``
|
||||
> {B}, the vector of returned corners with
|
||||
``qualityLevel=A``
|
||||
will be the prefix of the output vector with
|
||||
``qualityLevel=B``
|
||||
.
|
||||
|
||||
See also:
|
||||
:func:`cornerMinEigenVal`
|
||||
,
|
||||
:func:`cornerHarris`
|
||||
,
|
||||
:func:`calcOpticalFlowPyrLK`
|
||||
,
|
||||
:func:`estimateRigidMotion`
|
||||
,
|
||||
:func:`PlanarObjectDetector`
|
||||
,
|
||||
:func:`OneWayDescriptor`
|
||||
|
||||
.. index:: HoughCircles
|
||||
|
||||
|
||||
cv::HoughCircles
|
||||
----------------
|
||||
|
||||
`id=0.474895262744 Comments from the Wiki <http://opencv.willowgarage.com/wiki/documentation/cpp/imgproc/HoughCircles>`__
|
||||
|
||||
|
||||
|
||||
|
||||
.. cfunction:: void HoughCircles( Mat\& image, vector<Vec3f>\& circles, int method, double dp, double minDist, double param1=100, double param2=100, int minRadius=0, int maxRadius=0 )
|
||||
|
||||
Finds circles in a grayscale image using a Hough transform.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
:param image: The 8-bit, single-channel, grayscale input image
|
||||
|
||||
|
||||
:param circles: The output vector of found circles. Each vector is encoded as 3-element floating-point vector :math:`(x, y, radius)`
|
||||
|
||||
|
||||
:param method: Currently, the only implemented method is ``CV_HOUGH_GRADIENT`` , which is basically *21HT* , described in Yuen90 .
|
||||
|
||||
|
||||
:param dp: The inverse ratio of the accumulator resolution to the image resolution. For example, if ``dp=1`` , the accumulator will have the same resolution as the input image, if ``dp=2`` - accumulator will have half as big width and height, etc
|
||||
|
||||
|
||||
:param minDist: Minimum distance between the centers of the detected circles. If the parameter is too small, multiple neighbor circles may be falsely detected in addition to a true one. If it is too large, some circles may be missed
|
||||
|
||||
|
||||
:param param1: The first method-specific parameter. in the case of ``CV_HOUGH_GRADIENT`` it is the higher threshold of the two passed to :func:`Canny` edge detector (the lower one will be twice smaller)
|
||||
|
||||
|
||||
:param param2: The second method-specific parameter. in the case of ``CV_HOUGH_GRADIENT`` it is the accumulator threshold at the center detection stage. The smaller it is, the more false circles may be detected. Circles, corresponding to the larger accumulator values, will be returned first
|
||||
|
||||
|
||||
:param minRadius: Minimum circle radius
|
||||
|
||||
|
||||
:param maxRadius: Maximum circle radius
|
||||
|
||||
|
||||
|
||||
The function finds circles in a grayscale image using some modification of Hough transform. Here is a short usage example:
|
||||
|
||||
|
||||
|
||||
|
||||
::
|
||||
|
||||
|
||||
|
||||
#include <cv.h>
|
||||
#include <highgui.h>
|
||||
#include <math.h>
|
||||
|
||||
using namespace cv;
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
Mat img, gray;
|
||||
if( argc != 2 && !(img=imread(argv[1], 1)).data)
|
||||
return -1;
|
||||
cvtColor(img, gray, CV_BGR2GRAY);
|
||||
// smooth it, otherwise a lot of false circles may be detected
|
||||
GaussianBlur( gray, gray, Size(9, 9), 2, 2 );
|
||||
vector<Vec3f> circles;
|
||||
HoughCircles(gray, circles, CV_HOUGH_GRADIENT,
|
||||
2, gray->rows/4, 200, 100 );
|
||||
for( size_t i = 0; i < circles.size(); i++ )
|
||||
{
|
||||
Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));
|
||||
int radius = cvRound(circles[i][2]);
|
||||
// draw the circle center
|
||||
circle( img, center, 3, Scalar(0,255,0), -1, 8, 0 );
|
||||
// draw the circle outline
|
||||
circle( img, center, radius, Scalar(0,0,255), 3, 8, 0 );
|
||||
}
|
||||
namedWindow( "circles", 1 );
|
||||
imshow( "circles", img );
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
..
|
||||
|
||||
Note that usually the function detects the circles' centers well, however it may fail to find the correct radii. You can assist the function by specifying the radius range (
|
||||
``minRadius``
|
||||
and
|
||||
``maxRadius``
|
||||
) if you know it, or you may ignore the returned radius, use only the center and find the correct radius using some additional procedure.
|
||||
|
||||
See also:
|
||||
:func:`fitEllipse`
|
||||
,
|
||||
:func:`minEnclosingCircle`
|
||||
|
||||
.. index:: HoughLines
|
||||
|
||||
|
||||
cv::HoughLines
|
||||
--------------
|
||||
|
||||
`id=0.877791227007 Comments from the Wiki <http://opencv.willowgarage.com/wiki/documentation/cpp/imgproc/HoughLines>`__
|
||||
|
||||
|
||||
|
||||
|
||||
.. cfunction:: void HoughLines( Mat\& image, vector<Vec2f>\& lines, double rho, double theta, int threshold, double srn=0, double stn=0 )
|
||||
|
||||
Finds lines in a binary image using standard Hough transform.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
:param image: The 8-bit, single-channel, binary source image. The image may be modified by the function
|
||||
|
||||
|
||||
:param lines: The output vector of lines. Each line is represented by a two-element vector :math:`(\rho, \theta)` . :math:`\rho` is the distance from the coordinate origin :math:`(0,0)` (top-left corner of the image) and :math:`\theta` is the line rotation angle in radians ( :math:`0 \sim \textrm{vertical line}, \pi/2 \sim \textrm{horizontal line}` )
|
||||
|
||||
|
||||
:param rho: Distance resolution of the accumulator in pixels
|
||||
|
||||
|
||||
:param theta: Angle resolution of the accumulator in radians
|
||||
|
||||
|
||||
:param threshold: The accumulator threshold parameter. Only those lines are returned that get enough votes ( :math:`>\texttt{threshold}` )
|
||||
|
||||
|
||||
:param srn: For the multi-scale Hough transform it is the divisor for the distance resolution ``rho`` . The coarse accumulator distance resolution will be ``rho`` and the accurate accumulator resolution will be ``rho/srn`` . If both ``srn=0`` and ``stn=0`` then the classical Hough transform is used, otherwise both these parameters should be positive.
|
||||
|
||||
|
||||
:param stn: For the multi-scale Hough transform it is the divisor for the distance resolution ``theta``
|
||||
|
||||
|
||||
|
||||
The function implements standard or standard multi-scale Hough transform algorithm for line detection. See
|
||||
:func:`HoughLinesP`
|
||||
for the code example.
|
||||
|
||||
|
||||
|
||||
.. index:: HoughLinesP
|
||||
|
||||
|
||||
cv::HoughLinesP
|
||||
---------------
|
||||
|
||||
`id=0.855533341526 Comments from the Wiki <http://opencv.willowgarage.com/wiki/documentation/cpp/imgproc/HoughLinesP>`__
|
||||
|
||||
|
||||
|
||||
|
||||
.. cfunction:: void HoughLinesP( Mat\& image, vector<Vec4i>\& lines, double rho, double theta, int threshold, double minLineLength=0, double maxLineGap=0 )
|
||||
|
||||
Finds lines segments in a binary image using probabilistic Hough transform.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
:param image: The 8-bit, single-channel, binary source image. The image may be modified by the function
|
||||
|
||||
|
||||
:param lines: The output vector of lines. Each line is represented by a 4-element vector :math:`(x_1, y_1, x_2, y_2)` , where :math:`(x_1,y_1)` and :math:`(x_2, y_2)` are the ending points of each line segment detected.
|
||||
|
||||
|
||||
:param rho: Distance resolution of the accumulator in pixels
|
||||
|
||||
|
||||
:param theta: Angle resolution of the accumulator in radians
|
||||
|
||||
|
||||
:param threshold: The accumulator threshold parameter. Only those lines are returned that get enough votes ( :math:`>\texttt{threshold}` )
|
||||
|
||||
|
||||
:param minLineLength: The minimum line length. Line segments shorter than that will be rejected
|
||||
|
||||
|
||||
:param maxLineGap: The maximum allowed gap between points on the same line to link them.
|
||||
|
||||
|
||||
|
||||
The function implements probabilistic Hough transform algorithm for line detection, described in
|
||||
Matas00
|
||||
. Below is line detection example:
|
||||
|
||||
|
||||
|
||||
|
||||
::
|
||||
|
||||
|
||||
|
||||
/* This is a standalone program. Pass an image name as a first parameter
|
||||
of the program. Switch between standard and probabilistic Hough transform
|
||||
by changing "#if 1" to "#if 0" and back */
|
||||
#include <cv.h>
|
||||
#include <highgui.h>
|
||||
#include <math.h>
|
||||
|
||||
using namespace cv;
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
Mat src, dst, color_dst;
|
||||
if( argc != 2 || !(src=imread(argv[1], 0)).data)
|
||||
return -1;
|
||||
|
||||
Canny( src, dst, 50, 200, 3 );
|
||||
cvtColor( dst, color_dst, CV_GRAY2BGR );
|
||||
|
||||
#if 0
|
||||
vector<Vec2f> lines;
|
||||
HoughLines( dst, lines, 1, CV_PI/180, 100 );
|
||||
|
||||
for( size_t i = 0; i < lines.size(); i++ )
|
||||
{
|
||||
float rho = lines[i][0];
|
||||
float theta = lines[i][1];
|
||||
double a = cos(theta), b = sin(theta);
|
||||
double x0 = a*rho, y0 = b*rho;
|
||||
Point pt1(cvRound(x0 + 1000*(-b)),
|
||||
cvRound(y0 + 1000*(a)));
|
||||
Point pt2(cvRound(x0 - 1000*(-b)),
|
||||
cvRound(y0 - 1000*(a)));
|
||||
line( color_dst, pt1, pt2, Scalar(0,0,255), 3, 8 );
|
||||
}
|
||||
#else
|
||||
vector<Vec4i> lines;
|
||||
HoughLinesP( dst, lines, 1, CV_PI/180, 80, 30, 10 );
|
||||
for( size_t i = 0; i < lines.size(); i++ )
|
||||
{
|
||||
line( color_dst, Point(lines[i][0], lines[i][1]),
|
||||
Point(lines[i][2], lines[i][3]), Scalar(0,0,255), 3, 8 );
|
||||
}
|
||||
#endif
|
||||
namedWindow( "Source", 1 );
|
||||
imshow( "Source", src );
|
||||
|
||||
namedWindow( "Detected Lines", 1 );
|
||||
imshow( "Detected Lines", color_dst );
|
||||
|
||||
waitKey(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
..
|
||||
|
||||
This is the sample picture the function parameters have been tuned for:
|
||||
|
||||
|
||||
|
||||
.. image:: ../../pics/building.jpg
|
||||
|
||||
|
||||
|
||||
And this is the output of the above program in the case of probabilistic Hough transform
|
||||
|
||||
|
||||
|
||||
.. image:: ../../pics/houghp.png
|
||||
|
||||
|
||||
|
||||
|
||||
.. index:: preCornerDetect
|
||||
|
||||
|
||||
cv::preCornerDetect
|
||||
-------------------
|
||||
|
||||
`id=0.828630230352 Comments from the Wiki <http://opencv.willowgarage.com/wiki/documentation/cpp/imgproc/preCornerDetect>`__
|
||||
|
||||
|
||||
|
||||
|
||||
.. cfunction:: void preCornerDetect( const Mat\& src, Mat\& dst, int apertureSize, int borderType=BORDER_DEFAULT )
|
||||
|
||||
Calculates the feature map for corner detection
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
:param src: The source single-channel 8-bit of floating-point image
|
||||
|
||||
|
||||
:param dst: The output image; will have type ``CV_32F`` and the same size as ``src``
|
||||
|
||||
|
||||
:param apertureSize: Aperture size of :func:`Sobel`
|
||||
|
||||
|
||||
:param borderType: The pixel extrapolation method; see :func:`borderInterpolate`
|
||||
|
||||
|
||||
|
||||
The function calculates the complex spatial derivative-based function of the source image
|
||||
|
||||
|
||||
|
||||
.. math::
|
||||
|
||||
\texttt{dst} = (D_x \texttt{src} )^2 \cdot D_{yy} \texttt{src} + (D_y \texttt{src} )^2 \cdot D_{xx} \texttt{src} - 2 D_x \texttt{src} \cdot D_y \texttt{src} \cdot D_{xy} \texttt{src}
|
||||
|
||||
|
||||
where
|
||||
:math:`D_x`
|
||||
,
|
||||
:math:`D_y`
|
||||
are the first image derivatives,
|
||||
:math:`D_{xx}`
|
||||
,
|
||||
:math:`D_{yy}`
|
||||
are the second image derivatives and
|
||||
:math:`D_{xy}`
|
||||
is the mixed derivative.
|
||||
|
||||
The corners can be found as local maximums of the functions, as shown below:
|
||||
|
||||
|
||||
|
||||
|
||||
::
|
||||
|
||||
|
||||
|
||||
Mat corners, dilated_corners;
|
||||
preCornerDetect(image, corners, 3);
|
||||
// dilation with 3x3 rectangular structuring element
|
||||
dilate(corners, dilated_corners, Mat(), 1);
|
||||
Mat corner_mask = corners == dilated_corners;
|
||||
|
||||
|
||||
..
|
||||
|
2447
modules/imgproc/doc/filtering.rst
Normal file
2447
modules/imgproc/doc/filtering.rst
Normal file
File diff suppressed because it is too large
Load Diff
774
modules/imgproc/doc/geometric_transformations.rst
Normal file
774
modules/imgproc/doc/geometric_transformations.rst
Normal file
@@ -0,0 +1,774 @@
|
||||
Geometric Image Transformations
|
||||
===============================
|
||||
|
||||
.. highlight:: cpp
|
||||
|
||||
|
||||
The functions in this section perform various geometrical transformations of 2D images. That is, they do not change the image content, but deform the pixel grid, and map this deformed grid to the destination image. In fact, to avoid sampling artifacts, the mapping is done in the reverse order, from destination to the source. That is, for each pixel
|
||||
:math:`(x, y)`
|
||||
of the destination image, the functions compute coordinates of the corresponding "donor" pixel in the source image and copy the pixel value, that is:
|
||||
|
||||
|
||||
|
||||
.. math::
|
||||
|
||||
\texttt{dst} (x,y)= \texttt{src} (f_x(x,y), f_y(x,y))
|
||||
|
||||
|
||||
In the case when the user specifies the forward mapping:
|
||||
:math:`\left<g_x, g_y\right>: \texttt{src} \rightarrow \texttt{dst}`
|
||||
, the OpenCV functions first compute the corresponding inverse mapping:
|
||||
:math:`\left<f_x, f_y\right>: \texttt{dst} \rightarrow \texttt{src}`
|
||||
and then use the above formula.
|
||||
|
||||
The actual implementations of the geometrical transformations, from the most generic
|
||||
:ref:`Remap`
|
||||
and to the simplest and the fastest
|
||||
:ref:`Resize`
|
||||
, need to solve the 2 main problems with the above formula:
|
||||
|
||||
|
||||
|
||||
|
||||
#.
|
||||
extrapolation of non-existing pixels. Similarly to the filtering functions, described in the previous section, for some
|
||||
:math:`(x,y)`
|
||||
one of
|
||||
:math:`f_x(x,y)`
|
||||
or
|
||||
:math:`f_y(x,y)`
|
||||
, or they both, may fall outside of the image, in which case some extrapolation method needs to be used. OpenCV provides the same selection of the extrapolation methods as in the filtering functions, but also an additional method
|
||||
``BORDER_TRANSPARENT``
|
||||
, which means that the corresponding pixels in the destination image will not be modified at all.
|
||||
|
||||
|
||||
|
||||
#.
|
||||
interpolation of pixel values. Usually
|
||||
:math:`f_x(x,y)`
|
||||
and
|
||||
:math:`f_y(x,y)`
|
||||
are floating-point numbers (i.e.
|
||||
:math:`\left<f_x, f_y\right>`
|
||||
can be an affine or perspective transformation, or radial lens distortion correction etc.), so a pixel values at fractional coordinates needs to be retrieved. In the simplest case the coordinates can be just rounded to the nearest integer coordinates and the corresponding pixel used, which is called nearest-neighbor interpolation. However, a better result can be achieved by using more sophisticated
|
||||
`interpolation methods <http://en.wikipedia.org/wiki/Multivariate_interpolation>`_
|
||||
, where a polynomial function is fit into some neighborhood of the computed pixel
|
||||
:math:`(f_x(x,y), f_y(x,y))`
|
||||
and then the value of the polynomial at
|
||||
:math:`(f_x(x,y), f_y(x,y))`
|
||||
is taken as the interpolated pixel value. In OpenCV you can choose between several interpolation methods, see
|
||||
:ref:`Resize`
|
||||
.
|
||||
|
||||
|
||||
|
||||
.. index:: convertMaps
|
||||
|
||||
|
||||
cv::convertMaps
|
||||
---------------
|
||||
|
||||
`id=0.830076060616 Comments from the Wiki <http://opencv.willowgarage.com/wiki/documentation/cpp/imgproc/convertMaps>`__
|
||||
|
||||
|
||||
|
||||
|
||||
.. cfunction:: void convertMaps( const Mat\& map1, const Mat\& map2, Mat\& dstmap1, Mat\& dstmap2, int dstmap1type, bool nninterpolation=false )
|
||||
|
||||
Converts image transformation maps from one representation to another
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
:param map1: The first input map of type ``CV_16SC2`` or ``CV_32FC1`` or ``CV_32FC2``
|
||||
|
||||
|
||||
:param map2: The second input map of type ``CV_16UC1`` or ``CV_32FC1`` or none (empty matrix), respectively
|
||||
|
||||
|
||||
:param dstmap1: The first output map; will have type ``dstmap1type`` and the same size as ``src``
|
||||
|
||||
|
||||
:param dstmap2: The second output map
|
||||
|
||||
|
||||
:param dstmap1type: The type of the first output map; should be ``CV_16SC2`` , ``CV_32FC1`` or ``CV_32FC2``
|
||||
|
||||
|
||||
:param nninterpolation: Indicates whether the fixed-point maps will be used for nearest-neighbor or for more complex interpolation
|
||||
|
||||
|
||||
|
||||
The function converts a pair of maps for
|
||||
:func:`remap`
|
||||
from one representation to another. The following options (
|
||||
``(map1.type(), map2.type())``
|
||||
:math:`\rightarrow`
|
||||
``(dstmap1.type(), dstmap2.type())``
|
||||
) are supported:
|
||||
|
||||
|
||||
|
||||
|
||||
#.
|
||||
:math:`\texttt{(CV\_32FC1, CV\_32FC1)} \rightarrow \texttt{(CV\_16SC2, CV\_16UC1)}`
|
||||
. This is the most frequently used conversion operation, in which the original floating-point maps (see
|
||||
:func:`remap`
|
||||
) are converted to more compact and much faster fixed-point representation. The first output array will contain the rounded coordinates and the second array (created only when
|
||||
``nninterpolation=false``
|
||||
) will contain indices in the interpolation tables.
|
||||
|
||||
|
||||
|
||||
#.
|
||||
:math:`\texttt{(CV\_32FC2)} \rightarrow \texttt{(CV\_16SC2, CV\_16UC1)}`
|
||||
. The same as above, but the original maps are stored in one 2-channel matrix.
|
||||
|
||||
|
||||
|
||||
#.
|
||||
the reverse conversion. Obviously, the reconstructed floating-point maps will not be exactly the same as the originals.
|
||||
|
||||
|
||||
See also:
|
||||
:func:`remap`
|
||||
,
|
||||
:func:`undisort`
|
||||
,
|
||||
:func:`initUndistortRectifyMap`
|
||||
|
||||
.. index:: getAffineTransform
|
||||
|
||||
|
||||
cv::getAffineTransform
|
||||
----------------------
|
||||
|
||||
`id=0.578246613742 Comments from the Wiki <http://opencv.willowgarage.com/wiki/documentation/cpp/imgproc/getAffineTransform>`__
|
||||
|
||||
|
||||
|
||||
|
||||
.. cfunction:: Mat getAffineTransform( const Point2f src[], const Point2f dst[] )
|
||||
|
||||
Calculates the affine transform from 3 pairs of the corresponding points
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
:param src: Coordinates of a triangle vertices in the source image
|
||||
|
||||
|
||||
:param dst: Coordinates of the corresponding triangle vertices in the destination image
|
||||
|
||||
|
||||
|
||||
The function calculates the
|
||||
:math:`2 \times 3`
|
||||
matrix of an affine transform such that:
|
||||
|
||||
|
||||
|
||||
.. math::
|
||||
|
||||
\begin{bmatrix} x'_i \\ y'_i \end{bmatrix} = \texttt{map\_matrix} \cdot \begin{bmatrix} x_i \\ y_i \\ 1 \end{bmatrix}
|
||||
|
||||
|
||||
where
|
||||
|
||||
|
||||
|
||||
.. math::
|
||||
|
||||
dst(i)=(x'_i,y'_i),
|
||||
src(i)=(x_i, y_i),
|
||||
i=0,1,2
|
||||
|
||||
|
||||
See also:
|
||||
:func:`warpAffine`
|
||||
,
|
||||
:func:`transform`
|
||||
|
||||
.. index:: getPerspectiveTransform
|
||||
|
||||
|
||||
cv::getPerspectiveTransform
|
||||
---------------------------
|
||||
|
||||
`id=0.124978390322 Comments from the Wiki <http://opencv.willowgarage.com/wiki/documentation/cpp/imgproc/getPerspectiveTransform>`__
|
||||
|
||||
|
||||
|
||||
|
||||
.. cfunction:: Mat getPerspectiveTransform( const Point2f src[], const Point2f dst[] )
|
||||
|
||||
Calculates the perspective transform from 4 pairs of the corresponding points
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
:param src: Coordinates of a quadrange vertices in the source image
|
||||
|
||||
|
||||
:param dst: Coordinates of the corresponding quadrangle vertices in the destination image
|
||||
|
||||
|
||||
|
||||
The function calculates the
|
||||
:math:`3 \times 3`
|
||||
matrix of a perspective transform such that:
|
||||
|
||||
|
||||
|
||||
.. math::
|
||||
|
||||
\begin{bmatrix} t_i x'_i \\ t_i y'_i \\ t_i \end{bmatrix} = \texttt{map\_matrix} \cdot \begin{bmatrix} x_i \\ y_i \\ 1 \end{bmatrix}
|
||||
|
||||
|
||||
where
|
||||
|
||||
|
||||
|
||||
.. math::
|
||||
|
||||
dst(i)=(x'_i,y'_i),
|
||||
src(i)=(x_i, y_i),
|
||||
i=0,1,2
|
||||
|
||||
|
||||
See also:
|
||||
:func:`findHomography`
|
||||
,
|
||||
:func:`warpPerspective`
|
||||
,
|
||||
:func:`perspectiveTransform`
|
||||
|
||||
.. index:: getRectSubPix
|
||||
|
||||
|
||||
cv::getRectSubPix
|
||||
-----------------
|
||||
|
||||
`id=0.0571919909094 Comments from the Wiki <http://opencv.willowgarage.com/wiki/documentation/cpp/imgproc/getRectSubPix>`__
|
||||
|
||||
|
||||
|
||||
|
||||
.. cfunction:: void getRectSubPix( const Mat\& image, Size patchSize, Point2f center, Mat\& dst, int patchType=-1 )
|
||||
|
||||
Retrieves the pixel rectangle from an image with sub-pixel accuracy
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
:param src: Source image
|
||||
|
||||
|
||||
:param patchSize: Size of the extracted patch
|
||||
|
||||
|
||||
:param center: Floating point coordinates of the extracted rectangle center within the source image. The center must be inside the image
|
||||
|
||||
|
||||
:param dst: The extracted patch; will have the size ``patchSize`` and the same number of channels as ``src``
|
||||
|
||||
|
||||
:param patchType: The depth of the extracted pixels. By default they will have the same depth as ``src``
|
||||
|
||||
|
||||
|
||||
The function
|
||||
``getRectSubPix``
|
||||
extracts pixels from
|
||||
``src``
|
||||
:
|
||||
|
||||
|
||||
|
||||
.. math::
|
||||
|
||||
dst(x, y) = src(x + \texttt{center.x} - ( \texttt{dst.cols} -1)*0.5, y + \texttt{center.y} - ( \texttt{dst.rows} -1)*0.5)
|
||||
|
||||
|
||||
where the values of the pixels at non-integer coordinates are retrieved
|
||||
using bilinear interpolation. Every channel of multiple-channel
|
||||
images is processed independently. While the rectangle center
|
||||
must be inside the image, parts of the rectangle may be
|
||||
outside. In this case, the replication border mode (see
|
||||
:func:`borderInterpolate`
|
||||
) is used to extrapolate
|
||||
the pixel values outside of the image.
|
||||
|
||||
See also:
|
||||
:func:`warpAffine`
|
||||
,
|
||||
:func:`warpPerspective`
|
||||
|
||||
.. index:: getRotationMatrix2D
|
||||
|
||||
|
||||
cv::getRotationMatrix2D
|
||||
-----------------------
|
||||
|
||||
`id=0.641646199188 Comments from the Wiki <http://opencv.willowgarage.com/wiki/documentation/cpp/imgproc/getRotationMatrix2D>`__
|
||||
|
||||
|
||||
|
||||
|
||||
.. cfunction:: Mat getRotationMatrix2D( Point2f center, double angle, double scale )
|
||||
|
||||
Calculates the affine matrix of 2d rotation.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
:param center: Center of the rotation in the source image
|
||||
|
||||
|
||||
:param angle: The rotation angle in degrees. Positive values mean counter-clockwise rotation (the coordinate origin is assumed to be the top-left corner)
|
||||
|
||||
|
||||
:param scale: Isotropic scale factor
|
||||
|
||||
|
||||
|
||||
The function calculates the following matrix:
|
||||
|
||||
|
||||
|
||||
.. math::
|
||||
|
||||
\begin{bmatrix} \alpha & \beta & (1- \alpha ) \cdot \texttt{center.x} - \beta \cdot \texttt{center.y} \\ - \beta & \alpha & \beta \cdot \texttt{center.x} - (1- \alpha ) \cdot \texttt{center.y} \end{bmatrix}
|
||||
|
||||
|
||||
where
|
||||
|
||||
|
||||
|
||||
.. math::
|
||||
|
||||
\begin{array}{l} \alpha = \texttt{scale} \cdot \cos \texttt{angle} , \\ \beta = \texttt{scale} \cdot \sin \texttt{angle} \end{array}
|
||||
|
||||
|
||||
The transformation maps the rotation center to itself. If this is not the purpose, the shift should be adjusted.
|
||||
|
||||
See also:
|
||||
:func:`getAffineTransform`
|
||||
,
|
||||
:func:`warpAffine`
|
||||
,
|
||||
:func:`transform`
|
||||
|
||||
.. index:: invertAffineTransform
|
||||
|
||||
|
||||
cv::invertAffineTransform
|
||||
-------------------------
|
||||
|
||||
`id=0.772575709646 Comments from the Wiki <http://opencv.willowgarage.com/wiki/documentation/cpp/imgproc/invertAffineTransform>`__
|
||||
|
||||
|
||||
|
||||
|
||||
.. cfunction:: void invertAffineTransform(const Mat\& M, Mat\& iM)
|
||||
|
||||
Inverts an affine transformation
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
:param M: The original affine transformation
|
||||
|
||||
|
||||
:param iM: The output reverse affine transformation
|
||||
|
||||
|
||||
|
||||
The function computes inverse affine transformation represented by
|
||||
:math:`2 \times 3`
|
||||
matrix
|
||||
``M``
|
||||
:
|
||||
|
||||
|
||||
|
||||
.. math::
|
||||
|
||||
\begin{bmatrix} a_{11} & a_{12} & b_1 \\ a_{21} & a_{22} & b_2 \end{bmatrix}
|
||||
|
||||
|
||||
The result will also be a
|
||||
:math:`2 \times 3`
|
||||
matrix of the same type as
|
||||
``M``
|
||||
.
|
||||
|
||||
|
||||
.. index:: remap
|
||||
|
||||
|
||||
cv::remap
|
||||
---------
|
||||
|
||||
`id=0.948217317394 Comments from the Wiki <http://opencv.willowgarage.com/wiki/documentation/cpp/imgproc/remap>`__
|
||||
|
||||
|
||||
|
||||
|
||||
.. cfunction:: void remap( const Mat\& src, Mat\& dst, const Mat\& map1, const Mat\& map2, int interpolation, int borderMode=BORDER_CONSTANT, const Scalar\& borderValue=Scalar())
|
||||
|
||||
Applies a generic geometrical transformation to an image.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
:param src: Source image
|
||||
|
||||
|
||||
:param dst: Destination image. It will have the same size as ``map1`` and the same type as ``src``
|
||||
|
||||
|
||||
:param map1: The first map of either ``(x,y)`` points or just ``x`` values having type ``CV_16SC2`` , ``CV_32FC1`` or ``CV_32FC2`` . See :func:`convertMaps` for converting floating point representation to fixed-point for speed.
|
||||
|
||||
|
||||
:param map2: The second map of ``y`` values having type ``CV_16UC1`` , ``CV_32FC1`` or none (empty map if map1 is ``(x,y)`` points), respectively
|
||||
|
||||
|
||||
:param interpolation: The interpolation method, see :func:`resize` . The method ``INTER_AREA`` is not supported by this function
|
||||
|
||||
|
||||
:param borderMode: The pixel extrapolation method, see :func:`borderInterpolate` . When the \ ``borderMode=BORDER_TRANSPARENT`` , it means that the pixels in the destination image that corresponds to the "outliers" in the source image are not modified by the function
|
||||
|
||||
|
||||
:param borderValue: A value used in the case of a constant border. By default it is 0
|
||||
|
||||
|
||||
|
||||
The function
|
||||
``remap``
|
||||
transforms the source image using the specified map:
|
||||
|
||||
|
||||
|
||||
.. math::
|
||||
|
||||
\texttt{dst} (x,y) = \texttt{src} (map_x(x,y),map_y(x,y))
|
||||
|
||||
|
||||
Where values of pixels with non-integer coordinates are computed using one of the available interpolation methods.
|
||||
:math:`map_x`
|
||||
and
|
||||
:math:`map_y`
|
||||
can be encoded as separate floating-point maps in
|
||||
:math:`map_1`
|
||||
and
|
||||
:math:`map_2`
|
||||
respectively, or interleaved floating-point maps of
|
||||
:math:`(x,y)`
|
||||
in
|
||||
:math:`map_1`
|
||||
, or
|
||||
fixed-point maps made by using
|
||||
:func:`convertMaps`
|
||||
. The reason you might want to convert from floating to fixed-point
|
||||
representations of a map is that they can yield much faster (~2x) remapping operations. In the converted case,
|
||||
:math:`map_1`
|
||||
contains pairs
|
||||
``(cvFloor(x), cvFloor(y))``
|
||||
and
|
||||
:math:`map_2`
|
||||
contains indices in a table of interpolation coefficients.
|
||||
|
||||
This function can not operate in-place.
|
||||
|
||||
|
||||
.. index:: resize
|
||||
|
||||
|
||||
cv::resize
|
||||
----------
|
||||
|
||||
`id=0.927768028114 Comments from the Wiki <http://opencv.willowgarage.com/wiki/documentation/cpp/imgproc/resize>`__
|
||||
|
||||
|
||||
|
||||
|
||||
.. cfunction:: void resize( const Mat\& src, Mat\& dst, Size dsize, double fx=0, double fy=0, int interpolation=INTER_LINEAR )
|
||||
|
||||
Resizes an image
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
:param src: Source image
|
||||
|
||||
|
||||
:param dst: Destination image. It will have size ``dsize`` (when it is non-zero) or the size computed from ``src.size()``
|
||||
and ``fx`` and ``fy`` . The type of ``dst`` will be the same as of ``src`` .
|
||||
|
||||
|
||||
:param dsize: The destination image size. If it is zero, then it is computed as:
|
||||
|
||||
.. math::
|
||||
|
||||
\texttt{dsize = Size(round(fx*src.cols), round(fy*src.rows))}
|
||||
|
||||
.
|
||||
Either ``dsize`` or both ``fx`` or ``fy`` must be non-zero.
|
||||
|
||||
|
||||
:param fx: The scale factor along the horizontal axis. When 0, it is computed as
|
||||
|
||||
.. math::
|
||||
|
||||
\texttt{(double)dsize.width/src.cols}
|
||||
|
||||
|
||||
|
||||
|
||||
:param fy: The scale factor along the vertical axis. When 0, it is computed as
|
||||
|
||||
.. math::
|
||||
|
||||
\texttt{(double)dsize.height/src.rows}
|
||||
|
||||
|
||||
|
||||
|
||||
:param interpolation: The interpolation method:
|
||||
|
||||
* **INTER_NEAREST** nearest-neighbor interpolation
|
||||
|
||||
* **INTER_LINEAR** bilinear interpolation (used by default)
|
||||
|
||||
* **INTER_AREA** resampling using pixel area relation. It may be the preferred method for image decimation, as it gives moire-free results. But when the image is zoomed, it is similar to the ``INTER_NEAREST`` method
|
||||
|
||||
* **INTER_CUBIC** bicubic interpolation over 4x4 pixel neighborhood
|
||||
|
||||
* **INTER_LANCZOS4** Lanczos interpolation over 8x8 pixel neighborhood
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
The function
|
||||
``resize``
|
||||
resizes an image
|
||||
``src``
|
||||
down to or up to the specified size.
|
||||
Note that the initial
|
||||
``dst``
|
||||
type or size are not taken into account. Instead the size and type are derived from the
|
||||
``src``
|
||||
,
|
||||
``dsize``
|
||||
,
|
||||
``fx``
|
||||
and
|
||||
``fy``
|
||||
. If you want to resize
|
||||
``src``
|
||||
so that it fits the pre-created
|
||||
``dst``
|
||||
, you may call the function as:
|
||||
|
||||
|
||||
|
||||
|
||||
::
|
||||
|
||||
|
||||
|
||||
// explicitly specify dsize=dst.size(); fx and fy will be computed from that.
|
||||
resize(src, dst, dst.size(), 0, 0, interpolation);
|
||||
|
||||
|
||||
..
|
||||
|
||||
If you want to decimate the image by factor of 2 in each direction, you can call the function this way:
|
||||
|
||||
|
||||
|
||||
|
||||
::
|
||||
|
||||
|
||||
|
||||
// specify fx and fy and let the function to compute the destination image size.
|
||||
resize(src, dst, Size(), 0.5, 0.5, interpolation);
|
||||
|
||||
|
||||
..
|
||||
|
||||
See also:
|
||||
:func:`warpAffine`
|
||||
,
|
||||
:func:`warpPerspective`
|
||||
,
|
||||
:func:`remap`
|
||||
.
|
||||
|
||||
|
||||
|
||||
.. index:: warpAffine
|
||||
|
||||
|
||||
cv::warpAffine
|
||||
--------------
|
||||
|
||||
`id=0.796627178227 Comments from the Wiki <http://opencv.willowgarage.com/wiki/documentation/cpp/imgproc/warpAffine>`__
|
||||
|
||||
|
||||
|
||||
|
||||
.. cfunction:: void warpAffine( const Mat\& src, Mat\& dst, const Mat\& M, Size dsize, int flags=INTER_LINEAR, int borderMode=BORDER_CONSTANT, const Scalar\& borderValue=Scalar())
|
||||
|
||||
Applies an affine transformation to an image.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
:param src: Source image
|
||||
|
||||
|
||||
:param dst: Destination image; will have size ``dsize`` and the same type as ``src``
|
||||
|
||||
|
||||
:param M: :math:`2\times 3` transformation matrix
|
||||
|
||||
|
||||
:param dsize: Size of the destination image
|
||||
|
||||
|
||||
:param flags: A combination of interpolation methods, see :func:`resize` , and the optional flag ``WARP_INVERSE_MAP`` that means that ``M`` is the inverse transformation ( :math:`\texttt{dst}\rightarrow\texttt{src}` )
|
||||
|
||||
|
||||
:param borderMode: The pixel extrapolation method, see :func:`borderInterpolate` . When the \ ``borderMode=BORDER_TRANSPARENT`` , it means that the pixels in the destination image that corresponds to the "outliers" in the source image are not modified by the function
|
||||
|
||||
|
||||
:param borderValue: A value used in case of a constant border. By default it is 0
|
||||
|
||||
|
||||
|
||||
The function
|
||||
``warpAffine``
|
||||
transforms the source image using the specified matrix:
|
||||
|
||||
|
||||
|
||||
.. math::
|
||||
|
||||
\texttt{dst} (x,y) = \texttt{src} ( \texttt{M} _{11} x + \texttt{M} _{12} y + \texttt{M} _{13}, \texttt{M} _{21} x + \texttt{M} _{22} y + \texttt{M} _{23})
|
||||
|
||||
|
||||
when the flag
|
||||
``WARP_INVERSE_MAP``
|
||||
is set. Otherwise, the transformation is first inverted with
|
||||
:func:`invertAffineTransform`
|
||||
and then put in the formula above instead of
|
||||
``M``
|
||||
.
|
||||
The function can not operate in-place.
|
||||
|
||||
See also:
|
||||
:func:`warpPerspective`
|
||||
,
|
||||
:func:`resize`
|
||||
,
|
||||
:func:`remap`
|
||||
,
|
||||
:func:`getRectSubPix`
|
||||
,
|
||||
:func:`transform`
|
||||
|
||||
.. index:: warpPerspective
|
||||
|
||||
|
||||
cv::warpPerspective
|
||||
-------------------
|
||||
|
||||
`id=0.733510667556 Comments from the Wiki <http://opencv.willowgarage.com/wiki/documentation/cpp/imgproc/warpPerspective>`__
|
||||
|
||||
|
||||
|
||||
|
||||
.. cfunction:: void warpPerspective( const Mat\& src, Mat\& dst, const Mat\& M, Size dsize, int flags=INTER_LINEAR, int borderMode=BORDER_CONSTANT, const Scalar\& borderValue=Scalar())
|
||||
|
||||
Applies a perspective transformation to an image.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
:param src: Source image
|
||||
|
||||
|
||||
:param dst: Destination image; will have size ``dsize`` and the same type as ``src``
|
||||
|
||||
|
||||
:param M: :math:`3\times 3` transformation matrix
|
||||
|
||||
|
||||
:param dsize: Size of the destination image
|
||||
|
||||
|
||||
:param flags: A combination of interpolation methods, see :func:`resize` , and the optional flag ``WARP_INVERSE_MAP`` that means that ``M`` is the inverse transformation ( :math:`\texttt{dst}\rightarrow\texttt{src}` )
|
||||
|
||||
|
||||
:param borderMode: The pixel extrapolation method, see :func:`borderInterpolate` . When the \ ``borderMode=BORDER_TRANSPARENT`` , it means that the pixels in the destination image that corresponds to the "outliers" in the source image are not modified by the function
|
||||
|
||||
|
||||
:param borderValue: A value used in case of a constant border. By default it is 0
|
||||
|
||||
|
||||
|
||||
The function
|
||||
``warpPerspective``
|
||||
transforms the source image using the specified matrix:
|
||||
|
||||
|
||||
|
||||
.. math::
|
||||
|
||||
\texttt{dst} (x,y) = \texttt{src} \left ( \frac{M_{11} x + M_{12} y + M_{13}}{M_{31} x + M_{32} y + M_{33}} ,
|
||||
\frac{M_{21} x + M_{22} y + M_{23}}{M_{31} x + M_{32} y + M_{33}} \right )
|
||||
|
||||
|
||||
when the flag
|
||||
``WARP_INVERSE_MAP``
|
||||
is set. Otherwise, the transformation is first inverted with
|
||||
:func:`invert`
|
||||
and then put in the formula above instead of
|
||||
``M``
|
||||
.
|
||||
The function can not operate in-place.
|
||||
|
||||
See also:
|
||||
:func:`warpAffine`
|
||||
,
|
||||
:func:`resize`
|
||||
,
|
||||
:func:`remap`
|
||||
,
|
||||
:func:`getRectSubPix`
|
||||
,
|
||||
:func:`perspectiveTransform`
|
404
modules/imgproc/doc/histograms.rst
Normal file
404
modules/imgproc/doc/histograms.rst
Normal file
@@ -0,0 +1,404 @@
|
||||
Histograms
|
||||
==========
|
||||
|
||||
.. highlight:: cpp
|
||||
|
||||
|
||||
|
||||
.. index:: calcHist
|
||||
|
||||
|
||||
cv::calcHist
|
||||
------------
|
||||
|
||||
`id=0.023612377096 Comments from the Wiki <http://opencv.willowgarage.com/wiki/documentation/cpp/imgproc/calcHist>`__
|
||||
|
||||
|
||||
|
||||
|
||||
.. cfunction:: void calcHist( const Mat* arrays, int narrays, const int* channels, const Mat\& mask, MatND\& hist, int dims, const int* histSize, const float** ranges, bool uniform=true, bool accumulate=false )
|
||||
|
||||
|
||||
|
||||
.. cfunction:: 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
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
: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 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 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 hist: The output histogram, 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 histSize: The 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 uniform: Indicates 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
|
||||
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
|
||||
|
||||
::
|
||||
|
||||
|
||||
|
||||
#include <cv.h>
|
||||
#include <highgui.h>
|
||||
|
||||
using namespace cv;
|
||||
|
||||
int main( int argc, char** argv )
|
||||
{
|
||||
Mat src, hsv;
|
||||
if( argc != 2 || !(src=imread(argv[1], 1)).data )
|
||||
return -1;
|
||||
|
||||
cvtColor(src, hsv, CV_BGR2HSV);
|
||||
|
||||
// let's quantize the hue to 30 levels
|
||||
// and the saturation to 32 levels
|
||||
int hbins = 30, sbins = 32;
|
||||
int histSize[] = {hbins, sbins};
|
||||
// hue varies from 0 to 179, see cvtColor
|
||||
float hranges[] = { 0, 180 };
|
||||
// saturation varies from 0 (black-gray-white) to
|
||||
// 255 (pure spectrum color)
|
||||
float sranges[] = { 0, 256 };
|
||||
const float* ranges[] = { hranges, sranges };
|
||||
MatND hist;
|
||||
// we compute the histogram from the 0-th and 1-st channels
|
||||
int channels[] = {0, 1};
|
||||
|
||||
calcHist( &hsv, 1, channels, Mat(), // do not use mask
|
||||
hist, 2, histSize, ranges,
|
||||
true, // the histogram is uniform
|
||||
false );
|
||||
double maxVal=0;
|
||||
minMaxLoc(hist, 0, &maxVal, 0, 0);
|
||||
|
||||
int scale = 10;
|
||||
Mat histImg = Mat::zeros(sbins*scale, hbins*10, CV_8UC3);
|
||||
|
||||
for( int h = 0; h < hbins; h++ )
|
||||
for( int s = 0; s < sbins; s++ )
|
||||
{
|
||||
float binVal = hist.at<float>(h, s);
|
||||
int intensity = cvRound(binVal*255/maxVal);
|
||||
rectangle( histImg, Point(h*scale, s*scale),
|
||||
Point( (h+1)*scale - 1, (s+1)*scale - 1),
|
||||
Scalar::all(intensity),
|
||||
CV_FILLED );
|
||||
}
|
||||
|
||||
namedWindow( "Source", 1 );
|
||||
imshow( "Source", src );
|
||||
|
||||
namedWindow( "H-S Histogram", 1 );
|
||||
imshow( "H-S Histogram", histImg );
|
||||
waitKey();
|
||||
}
|
||||
|
||||
|
||||
..
|
||||
|
||||
|
||||
.. index:: calcBackProject
|
||||
|
||||
|
||||
cv::calcBackProject
|
||||
-------------------
|
||||
|
||||
`id=0.307675677402 Comments from the Wiki <http://opencv.willowgarage.com/wiki/documentation/cpp/imgproc/calcBackProject>`__
|
||||
|
||||
|
||||
|
||||
|
||||
.. cfunction:: void calcBackProject( const Mat* arrays, int narrays, const int* channels, const MatND\& hist, Mat\& backProject, const float** ranges, double scale=1, bool uniform=true )
|
||||
|
||||
|
||||
|
||||
.. cfunction:: void calcBackProject( const Mat* arrays, int narrays, const int* channels, const SparseMat\& hist, Mat\& backProject, const float** ranges, double scale=1, bool uniform=true )
|
||||
|
||||
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 narrays: The 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 hist: The input histogram, a 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 uniform: Indicates 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:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#.
|
||||
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.
|
||||
|
||||
|
||||
|
||||
#.
|
||||
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.
|
||||
|
||||
|
||||
|
||||
#.
|
||||
Find connected components in the resulting picture and choose, for example, the largest component.
|
||||
|
||||
|
||||
That is the approximate algorithm of
|
||||
:func:`CAMShift`
|
||||
color object tracker.
|
||||
|
||||
See also:
|
||||
:func:`calcHist`
|
||||
|
||||
.. index:: compareHist
|
||||
|
||||
|
||||
cv::compareHist
|
||||
---------------
|
||||
|
||||
`id=0.679842058679 Comments from the Wiki <http://opencv.willowgarage.com/wiki/documentation/cpp/imgproc/compareHist>`__
|
||||
|
||||
|
||||
|
||||
|
||||
.. cfunction:: double compareHist( const MatND\& H1, const MatND\& H2, int method )
|
||||
|
||||
|
||||
|
||||
.. cfunction:: double compareHist( const SparseMat\& H1, const SparseMat\& H2, int method )
|
||||
|
||||
Compares two histograms
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
: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:
|
||||
|
||||
|
||||
* **CV_COMP_CORREL** Correlation
|
||||
|
||||
|
||||
* **CV_COMP_CHISQR** Chi-Square
|
||||
|
||||
|
||||
* **CV_COMP_INTERSECT** Intersection
|
||||
|
||||
|
||||
* **CV_COMP_BHATTACHARYYA** Bhattacharyya distance
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
The functions
|
||||
``compareHist``
|
||||
compare two dense or two sparse histograms using the specified method:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
* Correlation (method=CV\_COMP\_CORREL)
|
||||
|
||||
|
||||
.. math::
|
||||
|
||||
d(H_1,H_2) = \frac{\sum_I (H_1(I) - \bar{H_1}) (H_2(I) - \bar{H_2})}{\sqrt{\sum_I(H_1(I) - \bar{H_1})^2 \sum_I(H_2(I) - \bar{H_2})^2}}
|
||||
|
||||
|
||||
where
|
||||
|
||||
|
||||
.. math::
|
||||
|
||||
\bar{H_k} = \frac{1}{N} \sum _J H_k(J)
|
||||
|
||||
|
||||
and
|
||||
:math:`N`
|
||||
is the total number of histogram bins.
|
||||
|
||||
|
||||
|
||||
* Chi-Square (method=CV\_COMP\_CHISQR)
|
||||
|
||||
|
||||
.. math::
|
||||
|
||||
d(H_1,H_2) = \sum _I \frac{\left(H_1(I)-H_2(I)\right)^2}{H_1(I)+H_2(I)}
|
||||
|
||||
|
||||
|
||||
|
||||
* Intersection (method=CV\_COMP\_INTERSECT)
|
||||
|
||||
|
||||
.. math::
|
||||
|
||||
d(H_1,H_2) = \sum _I \min (H_1(I), H_2(I))
|
||||
|
||||
|
||||
|
||||
|
||||
* Bhattacharyya distance (method=CV\_COMP\_BHATTACHARYYA)
|
||||
|
||||
|
||||
.. math::
|
||||
|
||||
d(H_1,H_2) = \sqrt{1 - \frac{1}{\sqrt{\bar{H_1} \bar{H_2} N^2}} \sum_I \sqrt{H_1(I) \cdot H_2(I)}}
|
||||
|
||||
|
||||
|
||||
|
||||
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
|
||||
:func:`calcEMD`
|
||||
function.
|
||||
|
||||
|
||||
.. index:: equalizeHist
|
||||
|
||||
|
||||
cv::equalizeHist
|
||||
----------------
|
||||
|
||||
`id=0.125539341699 Comments from the Wiki <http://opencv.willowgarage.com/wiki/documentation/cpp/imgproc/equalizeHist>`__
|
||||
|
||||
|
||||
|
||||
|
||||
.. cfunction:: void equalizeHist( const Mat\& src, Mat\& dst )
|
||||
|
||||
Equalizes the histogram of a grayscale image.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
:param src: The source 8-bit single channel image
|
||||
|
||||
|
||||
:param dst: The destination image; will have the same size and the same type as ``src``
|
||||
|
||||
|
||||
|
||||
The function equalizes the histogram of the input image using the following algorithm:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#.
|
||||
calculate the histogram
|
||||
:math:`H`
|
||||
for
|
||||
``src``
|
||||
.
|
||||
|
||||
|
||||
#.
|
||||
normalize the histogram so that the sum of histogram bins is 255.
|
||||
|
||||
|
||||
#.
|
||||
compute the integral of the histogram:
|
||||
|
||||
|
||||
.. math::
|
||||
|
||||
H'_i = \sum _{0 \le j < i} H(j)
|
||||
|
||||
|
||||
|
||||
|
||||
#.
|
||||
transform the image using
|
||||
:math:`H'`
|
||||
as a look-up table:
|
||||
:math:`\texttt{dst}(x,y) = H'(\texttt{src}(x,y))`
|
||||
|
||||
|
||||
The algorithm normalizes the brightness and increases the contrast of the image.
|
||||
|
16
modules/imgproc/doc/imgproc.rst
Normal file
16
modules/imgproc/doc/imgproc.rst
Normal file
@@ -0,0 +1,16 @@
|
||||
****************
|
||||
Image Processing
|
||||
****************
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
|
||||
histograms
|
||||
filtering
|
||||
geometric_transformations
|
||||
miscellaneous_transformations
|
||||
structural_analysis_and_shape_descriptors
|
||||
planar_subdivisions
|
||||
motion_analysis_and_object_tracking
|
||||
feature_detection
|
||||
object_detection
|
1440
modules/imgproc/doc/miscellaneous_transformations.rst
Normal file
1440
modules/imgproc/doc/miscellaneous_transformations.rst
Normal file
File diff suppressed because it is too large
Load Diff
227
modules/imgproc/doc/motion_analysis_and_object_tracking.rst
Normal file
227
modules/imgproc/doc/motion_analysis_and_object_tracking.rst
Normal file
@@ -0,0 +1,227 @@
|
||||
Motion Analysis and Object Tracking
|
||||
===================================
|
||||
|
||||
.. highlight:: cpp
|
||||
|
||||
|
||||
|
||||
.. index:: accumulate
|
||||
|
||||
|
||||
cv::accumulate
|
||||
--------------
|
||||
|
||||
`id=0.681079907994 Comments from the Wiki <http://opencv.willowgarage.com/wiki/documentation/cpp/imgproc/accumulate>`__
|
||||
|
||||
|
||||
|
||||
|
||||
.. cfunction:: void accumulate( const Mat\& src, Mat\& dst, const Mat\& mask=Mat() )
|
||||
|
||||
Adds image to the accumulator.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
:param src: The input image, 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 mask: Optional operation mask
|
||||
|
||||
|
||||
|
||||
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 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.
|
||||
|
||||
See also:
|
||||
:func:`accumulateSquare`
|
||||
,
|
||||
:func:`accumulateProduct`
|
||||
,
|
||||
:func:`accumulateWeighted`
|
||||
|
||||
.. index:: accumulateSquare
|
||||
|
||||
|
||||
cv::accumulateSquare
|
||||
--------------------
|
||||
|
||||
`id=0.655955936814 Comments from the Wiki <http://opencv.willowgarage.com/wiki/documentation/cpp/imgproc/accumulateSquare>`__
|
||||
|
||||
|
||||
|
||||
|
||||
.. cfunction:: void accumulateSquare( const Mat\& src, Mat\& dst, const Mat\& mask=Mat() )
|
||||
|
||||
Adds the square of the source image to the accumulator.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
:param src: The input image, 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 mask: Optional operation mask
|
||||
|
||||
|
||||
|
||||
The function adds the input image
|
||||
``src``
|
||||
or its selected region, raised to power 2, to the accumulator
|
||||
``dst``
|
||||
:
|
||||
|
||||
|
||||
|
||||
.. math::
|
||||
|
||||
\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.
|
||||
|
||||
See also:
|
||||
:func:`accumulateSquare`
|
||||
,
|
||||
:func:`accumulateProduct`
|
||||
,
|
||||
:func:`accumulateWeighted`
|
||||
|
||||
.. index:: accumulateProduct
|
||||
|
||||
|
||||
cv::accumulateProduct
|
||||
---------------------
|
||||
|
||||
`id=0.866927763669 Comments from the Wiki <http://opencv.willowgarage.com/wiki/documentation/cpp/imgproc/accumulateProduct>`__
|
||||
|
||||
|
||||
|
||||
|
||||
.. cfunction:: void accumulateProduct( const Mat\& src1, const Mat\& src2, Mat\& dst, const Mat\& mask=Mat() )
|
||||
|
||||
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 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
|
||||
|
||||
|
||||
|
||||
The function adds the product of 2 images or their selected regions to the accumulator
|
||||
``dst``
|
||||
:
|
||||
|
||||
|
||||
|
||||
.. math::
|
||||
|
||||
\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.
|
||||
|
||||
See also:
|
||||
:func:`accumulate`
|
||||
,
|
||||
:func:`accumulateSquare`
|
||||
,
|
||||
:func:`accumulateWeighted`
|
||||
|
||||
.. index:: accumulateWeighted
|
||||
|
||||
|
||||
cv::accumulateWeighted
|
||||
----------------------
|
||||
|
||||
`id=0.956120320296 Comments from the Wiki <http://opencv.willowgarage.com/wiki/documentation/cpp/imgproc/accumulateWeighted>`__
|
||||
|
||||
|
||||
|
||||
|
||||
.. cfunction:: void accumulateWeighted( const Mat\& src, Mat\& dst, double alpha, const Mat\& mask=Mat() )
|
||||
|
||||
Updates the running average.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
:param src: The input image, 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 alpha: Weight of the input image
|
||||
|
||||
|
||||
: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:
|
||||
|
||||
|
||||
|
||||
.. 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.
|
||||
|
||||
See also:
|
||||
:func:`accumulate`
|
||||
,
|
||||
:func:`accumulateSquare`
|
||||
,
|
||||
:func:`accumulateProduct`
|
146
modules/imgproc/doc/object_detection.rst
Normal file
146
modules/imgproc/doc/object_detection.rst
Normal file
@@ -0,0 +1,146 @@
|
||||
Object Detection
|
||||
================
|
||||
|
||||
.. highlight:: cpp
|
||||
|
||||
|
||||
|
||||
.. index:: matchTemplate
|
||||
|
||||
|
||||
cv::matchTemplate
|
||||
-----------------
|
||||
|
||||
`id=0.821462672178 Comments from the Wiki <http://opencv.willowgarage.com/wiki/documentation/cpp/imgproc/matchTemplate>`__
|
||||
|
||||
|
||||
|
||||
|
||||
.. cfunction:: void matchTemplate( const Mat\& image, const Mat\& templ, Mat\& result, int method )
|
||||
|
||||
Compares a template against overlapped image regions.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
:param image: Image where the search is running; should be 8-bit or 32-bit floating-point
|
||||
|
||||
|
||||
:param templ: Searched template; must be not greater than the source image and have the same data type
|
||||
|
||||
|
||||
:param result: A map of comparison results; will be single-channel 32-bit floating-point.
|
||||
If ``image`` is :math:`W \times H` and ``templ`` is :math:`w \times h` then ``result`` will be :math:`(W-w+1) \times (H-h+1)`
|
||||
|
||||
|
||||
:param method: Specifies the comparison method (see below)
|
||||
|
||||
|
||||
|
||||
The function slides through
|
||||
``image``
|
||||
, compares the
|
||||
overlapped patches of size
|
||||
:math:`w \times h`
|
||||
against
|
||||
``templ``
|
||||
using the specified method and stores the comparison results to
|
||||
``result``
|
||||
. Here are the formulas for the available comparison
|
||||
methods (
|
||||
:math:`I`
|
||||
denotes
|
||||
``image``
|
||||
,
|
||||
:math:`T`
|
||||
``template``
|
||||
,
|
||||
:math:`R`
|
||||
``result``
|
||||
). The summation is done over template and/or the
|
||||
image patch:
|
||||
:math:`x' = 0...w-1, y' = 0...h-1`
|
||||
|
||||
|
||||
|
||||
|
||||
* method=CV\_TM\_SQDIFF
|
||||
|
||||
|
||||
.. math::
|
||||
|
||||
R(x,y)= \sum _{x',y'} (T(x',y')-I(x+x',y+y'))^2
|
||||
|
||||
|
||||
|
||||
|
||||
* method=CV\_TM\_SQDIFF\_NORMED
|
||||
|
||||
|
||||
.. math::
|
||||
|
||||
R(x,y)= \frac{\sum_{x',y'} (T(x',y')-I(x+x',y+y'))^2}{\sqrt{\sum_{x',y'}T(x',y')^2 \cdot \sum_{x',y'} I(x+x',y+y')^2}}
|
||||
|
||||
|
||||
|
||||
|
||||
* method=CV\_TM\_CCORR
|
||||
|
||||
|
||||
.. math::
|
||||
|
||||
R(x,y)= \sum _{x',y'} (T(x',y') \cdot I(x+x',y+y'))
|
||||
|
||||
|
||||
|
||||
|
||||
* method=CV\_TM\_CCORR\_NORMED
|
||||
|
||||
|
||||
.. math::
|
||||
|
||||
R(x,y)= \frac{\sum_{x',y'} (T(x',y') \cdot I'(x+x',y+y'))}{\sqrt{\sum_{x',y'}T(x',y')^2 \cdot \sum_{x',y'} I(x+x',y+y')^2}}
|
||||
|
||||
|
||||
|
||||
|
||||
* method=CV\_TM\_CCOEFF
|
||||
|
||||
|
||||
.. math::
|
||||
|
||||
R(x,y)= \sum _{x',y'} (T'(x',y') \cdot I(x+x',y+y'))
|
||||
|
||||
|
||||
where
|
||||
|
||||
|
||||
.. math::
|
||||
|
||||
\begin{array}{l} T'(x',y')=T(x',y') - 1/(w \cdot h) \cdot \sum _{x'',y''} T(x'',y'') \\ I'(x+x',y+y')=I(x+x',y+y') - 1/(w \cdot h) \cdot \sum _{x'',y''} I(x+x'',y+y'') \end{array}
|
||||
|
||||
|
||||
|
||||
|
||||
* method=CV\_TM\_CCOEFF\_NORMED
|
||||
|
||||
|
||||
.. math::
|
||||
|
||||
R(x,y)= \frac{ \sum_{x',y'} (T'(x',y') \cdot I'(x+x',y+y')) }{ \sqrt{\sum_{x',y'}T'(x',y')^2 \cdot \sum_{x',y'} I'(x+x',y+y')^2} }
|
||||
|
||||
|
||||
|
||||
|
||||
After the function finishes the comparison, the best matches can be found as global minimums (when
|
||||
``CV_TM_SQDIFF``
|
||||
was used) or maximums (when
|
||||
``CV_TM_CCORR``
|
||||
or
|
||||
``CV_TM_CCOEFF``
|
||||
was used) using the
|
||||
:func:`minMaxLoc`
|
||||
function. In the case of a color image, template summation in the numerator and each sum in the denominator is done over all of the channels (and separate mean values are used for each channel). That is, the function can take a color template and a color image; the result will still be a single-channel image, which is easier to analyze.
|
||||
|
6
modules/imgproc/doc/planar_subdivisions.rst
Normal file
6
modules/imgproc/doc/planar_subdivisions.rst
Normal file
@@ -0,0 +1,6 @@
|
||||
Planar Subdivisions
|
||||
===================
|
||||
|
||||
.. highlight:: cpp
|
||||
|
||||
|
1086
modules/imgproc/doc/structural_analysis_and_shape_descriptors.rst
Normal file
1086
modules/imgproc/doc/structural_analysis_and_shape_descriptors.rst
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user