2011-02-23 04:43:26 +08:00
Geometric Image Transformations
===============================
2011-04-18 03:46:02 +08:00
The functions in this section perform various geometrical transformations of 2D images. 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:
2011-02-23 04:43:26 +08:00
.. math ::
2011-02-26 19:05:10 +08:00
\texttt{dst} (x,y)= \texttt{src} (f_x(x,y), f_y(x,y))
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
In case when you specify the forward mapping
:math:`\left<g_x, g_y\right>: \texttt{src} \rightarrow \texttt{dst}` , the OpenCV functions first compute the corresponding inverse mapping
2011-02-26 19:05:10 +08:00
:math:`\left<f_x, f_y\right>: \texttt{dst} \rightarrow \texttt{src}` and then use the above formula.
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
The actual implementations of the geometrical transformations, from the most generic
:ref: `Remap` and to the simplest and the fastest
2011-04-18 03:46:02 +08:00
:ref: `Resize` , need to solve two main problems with the above formula:
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
*
Extrapolation of non-existing pixels. Similarly to the filtering functions described in the previous section, for some
:math: `(x,y)` , either one of
:math: `f_x(x,y)` , or
:math: `f_y(x,y)` , or both of them may fall outside of the image. In this case, an extrapolation method needs to be used. OpenCV provides the same selection of extrapolation methods as in the filtering functions. In addition, it provides the method `` BORDER_TRANSPARENT `` . This means that the corresponding pixels in the destination image will not be modified at all.
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
*
Interpolation of pixel values. Usually
2011-02-26 19:05:10 +08:00
:math: `f_x(x,y)` and
2011-04-18 03:46:02 +08:00
:math: `f_y(x,y)` are floating-point numbers. This means that
:math: `\left<f_x, f_y\right>` can be either an affine or perspective transformation, or radial lens distortion correction, and so on. So, a pixel value 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 can be used. This is called a nearest-neighbor interpolation. However, a better result can be achieved by using more sophisticated `interpolation methods <http://en.wikipedia.org/wiki/Multivariate_interpolation> `_
2011-02-26 19:05:10 +08:00
, where a polynomial function is fit into some neighborhood of the computed pixel
2011-04-18 03:46:02 +08:00
: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` for details.
2011-02-23 04:43:26 +08:00
.. index :: convertMaps
2011-03-09 06:22:24 +08:00
.. _convertMaps:
2011-03-01 05:26:43 +08:00
convertMaps
2011-03-09 06:22:24 +08:00
-----------
.. c:function :: void convertMaps( const Mat& map1, const Mat& map2, Mat& dstmap1, Mat& dstmap2, int dstmap1type, bool nninterpolation=false )
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
Converts image transformation maps from one representation to another.
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
:param map1: The first input map of type ``CV_16SC2`` , ``CV_32FC1`` , or ``CV_32FC2`` .
2011-03-09 06:22:24 +08:00
2011-04-18 03:46:02 +08:00
:param map2: The second input map of type ``CV_16UC1`` , ``CV_32FC1`` , or none (empty matrix), respectively.
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
:param dstmap1: The first output map that has the type ``dstmap1type`` and the same size as ``src`` .
2011-03-09 06:22:24 +08:00
2011-04-18 03:46:02 +08:00
:param dstmap2: The second output map.
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
:param dstmap1type: Type of the first output map that should be ``CV_16SC2`` , ``CV_32FC1`` , or ``CV_32FC2`` .
2011-03-09 06:22:24 +08:00
2011-04-18 03:46:02 +08:00
:param nninterpolation: Flag indicatingwhether the fixed-point maps are used for the nearest-neighbor or for a more complex interpolation.
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
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:
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
*
2011-02-26 19:05:10 +08:00
: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
2011-04-18 03:46:02 +08:00
:func: `remap` ) are converted to a more compact and much faster fixed-point representation. The first output array contains the rounded coordinates and the second array (created only when `` nninterpolation=false `` ) contains indices in the interpolation tables.
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
*
: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.
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
*
Reverse conversion. Obviously, the reconstructed floating-point maps will not be exactly the same as the originals.
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
See Also:
:func: `remap` ,
:func: `undisort` ,
:func: `initUndistortRectifyMap`
2011-03-09 06:22:24 +08:00
2011-02-23 04:43:26 +08:00
.. index :: getAffineTransform
2011-03-09 06:22:24 +08:00
.. _getAffineTransform:
2011-03-01 05:26:43 +08:00
getAffineTransform
2011-02-23 04:43:26 +08:00
----------------------
2011-03-01 05:26:43 +08:00
.. c:function :: Mat getAffineTransform( const Point2f src[], const Point2f dst[] )
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
Calculates the affine transform from three pairs of the corresponding points.
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
:param src: Coordinates of triangle vertices in the source image.
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
:param dst: Coordinates of the corresponding triangle vertices in the destination image.
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
The function calculates the :math: `2 \times 3` matrix of an affine transform so that:
2011-02-23 04:43:26 +08:00
.. math ::
2011-02-26 19:05:10 +08:00
\begin{bmatrix} x'_i \\ y'_i \end{bmatrix} = \texttt{map\_matrix} \cdot \begin{bmatrix} x_i \\ y_i \\ 1 \end{bmatrix}
2011-02-23 04:43:26 +08:00
where
.. math ::
dst(i)=(x'_i,y'_i),
src(i)=(x_i, y_i),
2011-02-26 19:05:10 +08:00
i=0,1,2
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
See Also:
:func: `warpAffine` ,
:func: `transform`
2011-03-09 06:22:24 +08:00
2011-02-23 04:43:26 +08:00
.. index :: getPerspectiveTransform
2011-03-09 06:22:24 +08:00
.. _getPerspectiveTransform:
2011-03-01 05:26:43 +08:00
getPerspectiveTransform
2011-02-23 04:43:26 +08:00
---------------------------
2011-03-09 06:22:24 +08:00
.. c:function :: Mat getPerspectiveTransform( const Point2f src[], const Point2f dst[] )
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
Calculates the perspective transform from four pairs of the corresponding points.
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
:param src: Coordinates of quadrangle vertices in the source image.
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
:param dst: Coordinates of the corresponding quadrangle vertices in the destination image.
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
The function calculates the :math: `3 \times 3` matrix of a perspective transform so that:
2011-02-23 04:43:26 +08:00
.. math ::
2011-02-26 19:05:10 +08:00
\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}
2011-02-23 04:43:26 +08:00
where
.. math ::
dst(i)=(x'_i,y'_i),
src(i)=(x_i, y_i),
2011-02-26 19:05:10 +08:00
i=0,1,2
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
See Also:
:func: `findHomography` ,
:func: `warpPerspective` ,
:func: `perspectiveTransform`
2011-03-09 06:22:24 +08:00
2011-02-23 04:43:26 +08:00
.. index :: getRectSubPix
2011-03-09 06:22:24 +08:00
.. getRectSubPix:
2011-03-01 05:26:43 +08:00
getRectSubPix
2011-02-23 04:43:26 +08:00
-----------------
2011-03-09 06:22:24 +08:00
.. c:function :: void getRectSubPix( const Mat& image, Size patchSize, Point2f center, Mat& dst, int patchType=-1 )
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
Retrieves the pixel rectangle from an image with sub-pixel accuracy.
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
:param src: Source image.
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
:param patchSize: Size of the extracted patch.
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
:param center: Floating point coordinates of the center of the extracted rectangle within the source image. The center must be inside the image.
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
:param dst: Extracted patch that has the size ``patchSize`` and the same number of channels as ``src`` .
2011-03-03 15:29:55 +08:00
2011-04-18 03:46:02 +08:00
:param patchType: Depth of the extracted pixels. By default, they have the same depth as ``src`` .
2011-03-03 15:29:55 +08:00
2011-02-26 19:05:10 +08:00
The function `` getRectSubPix `` extracts pixels from `` src `` :
2011-02-23 04:43:26 +08:00
.. math ::
2011-02-26 19:05:10 +08:00
dst(x, y) = src(x + \texttt{center.x} - ( \texttt{dst.cols} -1)*0.5, y + \texttt{center.y} - ( \texttt{dst.rows} -1)* 0.5)
2011-02-23 04:43:26 +08:00
where the values of the pixels at non-integer coordinates are retrieved
2011-04-18 03:46:02 +08:00
using bilinear interpolation. Every channel of multi-channel
images is processed independently. While the center of the rectangle
2011-02-23 04:43:26 +08:00
must be inside the image, parts of the rectangle may be
2011-02-26 19:05:10 +08:00
outside. In this case, the replication border mode (see
:func: `borderInterpolate` ) is used to extrapolate
2011-02-23 04:43:26 +08:00
the pixel values outside of the image.
2011-04-18 03:46:02 +08:00
See Also:
:func: `warpAffine` ,
:func: `warpPerspective`
2011-03-09 06:22:24 +08:00
2011-02-23 04:43:26 +08:00
.. index :: getRotationMatrix2D
2011-03-09 06:22:24 +08:00
.. _getRotationMatrix2D:
2011-03-01 05:26:43 +08:00
getRotationMatrix2D
2011-02-23 04:43:26 +08:00
-----------------------
2011-03-01 05:26:43 +08:00
.. c:function :: Mat getRotationMatrix2D( Point2f center, double angle, double scale )
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
Calculates an affine matrix of 2D rotation.
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
:param center: Center of the rotation in the source image.
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
:param angle: Rotation angle in degrees. Positive values mean counter-clockwise rotation (the coordinate origin is assumed to be the top-left corner).
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
:param scale: Isotropic scale factor.
2011-02-23 04:43:26 +08:00
The function calculates the following matrix:
.. math ::
2011-02-26 19:05:10 +08:00
\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}
2011-02-23 04:43:26 +08:00
where
.. math ::
2011-02-26 19:05:10 +08:00
\begin{array}{l} \alpha = \texttt{scale} \cdot \cos \texttt{angle} , \\ \beta = \texttt{scale} \cdot \sin \texttt{angle} \end{array}
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
The transformation maps the rotation center to itself. If this is not the target, adjust the shift.
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
See Also:
:func: `getAffineTransform` ,
:func: `warpAffine` ,
:func: `transform`
2011-03-09 06:22:24 +08:00
2011-02-23 04:43:26 +08:00
.. index :: invertAffineTransform
2011-03-09 06:22:24 +08:00
.. _invertAffineTransform:
2011-03-01 05:26:43 +08:00
invertAffineTransform
2011-02-23 04:43:26 +08:00
-------------------------
2011-03-09 06:22:24 +08:00
.. c:function :: void invertAffineTransform(const Mat& M, Mat& iM)
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
Inverts an affine transformation.
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
:param M: Original affine transformation.
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
:param iM: Output reverse affine transformation.
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
The function computes an inverse affine transformation represented by
2011-02-26 19:05:10 +08:00
:math: `2 \times 3` matrix `` M `` :
2011-02-23 04:43:26 +08:00
.. math ::
2011-02-26 19:05:10 +08:00
\begin{bmatrix} a_{11} & a_{12} & b_1 \\ a_{21} & a_{22} & b_2 \end{bmatrix}
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
The result is also a
2011-02-26 19:05:10 +08:00
:math: `2 \times 3` matrix of the same type as `` M `` .
2011-02-23 04:43:26 +08:00
.. index :: remap
2011-03-09 06:22:24 +08:00
.. _remap:
2011-03-01 05:26:43 +08:00
remap
2011-03-09 06:22:24 +08:00
-----
.. c:function :: void remap( const Mat& src, Mat& dst, const Mat& map1, const Mat& map2, int interpolation, int borderMode=BORDER_CONSTANT, const Scalar& borderValue=Scalar())
2011-02-23 04:43:26 +08:00
Applies a generic geometrical transformation to an image.
2011-04-18 03:46:02 +08:00
:param src: Source image.
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
:param dst: Destination image. It has 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 the type ``CV_16SC2`` , ``CV_32FC1`` , or ``CV_32FC2`` . See :func:`convertMaps` for details on converting a floating point representation to fixed-point for speed.
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
:param map2: The second map of ``y`` values having the type ``CV_16UC1`` , ``CV_32FC1`` , or none (empty map if ``map1`` is ``(x,y)`` points), respectively.
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
:param interpolation: Interpolation method (see :func:`resize` ). The method ``INTER_AREA`` is not supported by this function.
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
:param borderMode: Pixel extrapolation method (see :func:`borderInterpolate` ). When \ ``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.
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
:param borderValue: Value used in case of a constant border. By default, it is 0.
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
The function `` remap `` transforms the source image using the specified map:
2011-02-23 04:43:26 +08:00
.. math ::
2011-02-26 19:05:10 +08:00
\texttt{dst} (x,y) = \texttt{src} (map_x(x,y),map_y(x,y))
2011-04-18 03:46:02 +08:00
where values of pixels with non-integer coordinates are computed using one of available interpolation methods.
2011-02-26 19:05:10 +08:00
: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
2011-04-18 03:46:02 +08:00
fixed-point maps created by using
2011-02-26 19:05:10 +08:00
: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.
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
This function cannot operate in-place.
2011-02-23 04:43:26 +08:00
.. index :: resize
2011-03-09 06:22:24 +08:00
.. _resize:
2011-03-01 05:26:43 +08:00
resize
2011-02-23 04:43:26 +08:00
----------
2011-03-09 06:22:24 +08:00
.. c:function :: void resize( const Mat& src, Mat& dst, Size dsize, double fx=0, double fy=0, int interpolation=INTER_LINEAR )
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
Resizes an image.
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
:param src: Source image.
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
:param dst: Destination image. It has size ``dsize`` (when it is non-zero) or the size computed from ``src.size()`` , ``fx`` , and ``fy`` . The type of ``dst`` is the same as of ``src`` .
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
:param dsize: Destination image size. If it is zero, it is computed as:
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
.. math ::
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
\texttt{dsize = Size(round(fx*src.cols), round(fy* src.rows))}
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
Either `` dsize `` or both `` fx `` and `` fy `` must be non-zero.
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
:param fx: Scale factor along the horizontal axis. When it is 0, it is computed as
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
.. math ::
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
\texttt{(double)dsize.width/src.cols}
2011-04-18 03:46:02 +08:00
:param fy: Scale factor along the vertical axis. When it is 0, it is computed as
2011-02-23 04:43:26 +08:00
.. math ::
2011-02-26 19:05:10 +08:00
\texttt{(double)dsize.height/src.rows}
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
:param interpolation: Interpolation method:
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
* **INTER_NEAREST** - a nearest-neighbor interpolation
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
* **INTER_LINEAR** - a bilinear interpolation (used by default)
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
* **INTER_AREA** - resampling using pixel area relation. It may be a preferred method for image decimation, as it gives freer?? results. But when the image is zoomed, it is similar to the `` INTER_NEAREST `` method.
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
* **INTER_CUBIC** - a bicubic interpolation over 4x4 pixel neighborhood
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
* **INTER_LANCZOS4** - a Lanczos interpolation over 8x8 pixel neighborhood
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
The function `` resize `` resizes the 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 follows: ::
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
// explicitly specify dsize=dst.size(); fx and fy will be computed from that.
resize(src, dst, dst.size(), 0, 0, interpolation);
2011-03-01 05:26:43 +08:00
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
If you want to decimate the image by factor of 2 in each direction, you can call the function this way: ::
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
// specify fx and fy and let the function compute the destination image size.
2011-02-26 19:05:10 +08:00
resize(src, dst, Size(), 0.5, 0.5, interpolation);
2011-03-01 05:26:43 +08:00
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
See Also:
:func: `warpAffine` ,
:func: `warpPerspective` ,
:func: `remap`
2011-02-23 04:43:26 +08:00
.. index :: warpAffine
2011-03-09 06:22:24 +08:00
.. _warpAffine:
2011-03-01 05:26:43 +08:00
warpAffine
2011-02-23 04:43:26 +08:00
--------------
2011-03-09 06:22:24 +08:00
.. c:function :: void warpAffine( const Mat& src, Mat& dst, const Mat& M, Size dsize, int flags=INTER_LINEAR, int borderMode=BORDER_CONSTANT, const Scalar& borderValue=Scalar())
2011-02-23 04:43:26 +08:00
Applies an affine transformation to an image.
2011-04-18 03:46:02 +08:00
:param src: Source image.
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
:param dst: Destination image that has the size ``dsize`` and the same type as ``src`` .
2011-03-01 05:26:43 +08:00
2011-04-18 03:46:02 +08:00
:param M: :math:`2\times 3` transformation matrix.
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
:param dsize: Size of the destination image.
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
:param flags: 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}` ).
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
:param borderMode: Pixel extrapolation method (see :func:`borderInterpolate` ). When \ ``borderMode=BORDER_TRANSPARENT`` , it means that the pixels in the destination image corresponding to the "outliers" in the source image are not modified by the function.
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
:param borderValue: Value used in case of a constant border. By default, it is 0.
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
The function `` warpAffine `` transforms the source image using the specified matrix:
2011-02-23 04:43:26 +08:00
.. math ::
2011-03-09 06:22:24 +08:00
\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})
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
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 `` .
2011-04-18 03:46:02 +08:00
The function cannot operate in-place.
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
See Also:
:func: `warpPerspective` ,
:func: `resize` ,
:func: `remap` ,
:func: `getRectSubPix` ,
:func: `transform`
2011-03-09 06:22:24 +08:00
2011-02-23 04:43:26 +08:00
.. index :: warpPerspective
2011-03-09 06:22:24 +08:00
.. _warpPerspective:
2011-03-01 05:26:43 +08:00
warpPerspective
2011-02-23 04:43:26 +08:00
-------------------
2011-03-09 06:22:24 +08:00
.. c:function :: void warpPerspective( const Mat& src, Mat& dst, const Mat& M, Size dsize, int flags=INTER_LINEAR, int borderMode=BORDER_CONSTANT, const Scalar& borderValue=Scalar())
2011-02-23 04:43:26 +08:00
Applies a perspective transformation to an image.
2011-04-18 03:46:02 +08:00
:param src: Source image.
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
:param dst: Destination image that has the size ``dsize`` and the same type as ``src`` .
:param M: :math: `3\times 3` transformation matrix.
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
:param dsize: Size of the destination image.
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
:param flags: 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}` ).
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
:param borderMode: Pixel extrapolation method (see :func:`borderInterpolate` ). When \ ``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.
2011-02-23 04:43:26 +08:00
2011-04-18 03:46:02 +08:00
:param borderValue: Value used in case of a constant border. By default, it is 0.
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
The function `` warpPerspective `` transforms the source image using the specified matrix:
2011-02-23 04:43:26 +08:00
.. 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}} ,
2011-02-26 19:05:10 +08:00
\frac{M_{21} x + M_{22} y + M_{23}}{M_{31} x + M_{32} y + M_{33}} \right )
2011-02-23 04:43:26 +08:00
2011-02-26 19:05:10 +08:00
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 `` .
2011-04-18 03:46:02 +08:00
The function cannot operate in-place.
See Also:
:func: `warpAffine` ,
:func: `resize` ,
:func: `remap` ,
:func: `getRectSubPix` ,
:func: `perspectiveTransform`
2011-03-09 06:22:24 +08:00