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 of the destination image, the functions compute coordinates of the corresponding “donor” pixel in the source image and copy the pixel value:
In case when you specify the forward mapping
, the OpenCV functions first compute the corresponding inverse mapping
and then use the above formula.
The actual implementations of the geometrical transformations, from the most generic
remap()
and to the simplest and the fastest
resize()
, need to solve two main problems with the above formula:
BORDER_TRANSPARENT
. This means that the corresponding pixels in the destination image will not be modified at all.resize()
for details.Converts image transformation maps from one representation to another.
void convertMaps
(InputArray map1, InputArray map2, OutputArray dstmap1, OutputArray dstmap2, int dstmap1type, bool nninterpolation=false )¶
cv2.
convertMaps
(map1, map2, dstmap1type[, dstmap1[, dstmap2[, nninterpolation]]]) → dstmap1, dstmap2¶Parameters: |
|
---|
The function converts a pair of maps for
remap()
from one representation to another. The following options ( (map1.type(), map2.type())
(dstmap1.type(), dstmap2.type())
) are supported:
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.See also
Calculates an affine transform from three pairs of the corresponding points.
Mat getAffineTransform
(InputArray src, InputArray dst)¶
Mat getAffineTransform
(const Point2f src[], const Point2f dst[])¶
cv2.
getAffineTransform
(src, dst) → retval¶
CvMat* cvGetAffineTransform
(const CvPoint2D32f* src, const CvPoint2D32f* dst, CvMat* map_matrix)¶
cv.
GetAffineTransform
(src, dst, mapMatrix) → None¶Parameters: |
|
---|
The function calculates the matrix of an affine transform so that:
where
See also
Calculates a perspective transform from four pairs of the corresponding points.
Mat getPerspectiveTransform
(InputArray src, InputArray dst)¶
Mat getPerspectiveTransform
(const Point2f src[], const Point2f dst[])¶
cv2.
getPerspectiveTransform
(src, dst) → retval¶
CvMat* cvGetPerspectiveTransform
(const CvPoint2D32f* src, const CvPoint2D32f* dst, CvMat* map_matrix)¶
cv.
GetPerspectiveTransform
(src, dst, mapMatrix) → None¶Parameters: |
|
---|
The function calculates the matrix of a perspective transform so that:
where
Retrieves a pixel rectangle from an image with sub-pixel accuracy.
void getRectSubPix
(InputArray image, Size patchSize, Point2f center, OutputArray patch, int patchType=-1 )¶
cv2.
getRectSubPix
(image, patchSize, center[, patch[, patchType]]) → patch¶
void cvGetRectSubPix
(const CvArr* src, CvArr* dst, CvPoint2D32f center)¶
cv.
GetRectSubPix
(src, dst, center) → None¶Parameters: |
|
---|
The function getRectSubPix
extracts pixels from src
:
where the values of the pixels at non-integer coordinates are retrieved
using bilinear interpolation. Every channel of multi-channel
images is processed independently. While the center of the rectangle
must be inside the image, parts of the rectangle may be
outside. In this case, the replication border mode (see
borderInterpolate()
) is used to extrapolate
the pixel values outside of the image.
See also
Calculates an affine matrix of 2D rotation.
Mat getRotationMatrix2D
(Point2f center, double angle, double scale)¶
cv2.
getRotationMatrix2D
(center, angle, scale) → retval¶
CvMat* cv2DRotationMatrix
(CvPoint2D32f center, double angle, double scale, CvMat* map_matrix)¶
cv.
GetRotationMatrix2D
(center, angle, scale, mapMatrix) → None¶Parameters: |
|
---|
The function calculates the following matrix:
where
The transformation maps the rotation center to itself. If this is not the target, adjust the shift.
See also
Inverts an affine transformation.
void invertAffineTransform
(InputArray M, OutputArray iM)¶
cv2.
invertAffineTransform
(M[, iM]) → iM¶Parameters: |
|
---|
The function computes an inverse affine transformation represented by
matrix
M
:
The result is also a
matrix of the same type as
M
.
Remaps an image to polar space.
void cvLinearPolar
(const CvArr* src, CvArr* dst, CvPoint2D32f center, double maxRadius, int flags=CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS )¶Parameters: |
|
---|
The function cvLinearPolar
transforms the source image using the following transformation:
Forward transformation (
CV_WARP_INVERSE_MAP
is not set):
Inverse transformation (
CV_WARP_INVERSE_MAP
is set):
where
and
Note
cvCartToPolar()
is used internally thus angles are measured from 0 to 360 with accuracy about 0.3 degrees.Remaps an image to log-polar space.
void cvLogPolar
(const CvArr* src, CvArr* dst, CvPoint2D32f center, double M, int flags=CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS )