Image Resizing
resize
Resizes an image.InputArray
Input image.
OutputArray
Output image; it has the 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.
Size
Output image size; if it equals zero, it is computed as dsize = Size(round(fxsrc.cols), round(fysrc.rows)). Either dsize or both fx and fy must be non-zero.
double
default:"0"
Scale factor along the horizontal axis; when it equals 0, it is computed as (double)dsize.width/src.cols.
double
default:"0"
Scale factor along the vertical axis; when it equals 0, it is computed as (double)dsize.height/src.rows.
int
default:"INTER_LINEAR"
Interpolation method. See InterpolationFlags.
- C++
- Python
To shrink an image, it will generally look best with INTER_AREA interpolation, whereas to enlarge an image, it will generally look best with INTER_CUBIC (slow) or INTER_LINEAR (faster but still looks OK).
Affine Transformations
warpAffine
Applies an affine transformation to an image.InputArray
Input image.
OutputArray
Output image that has the size dsize and the same type as src.
InputArray
2×3 transformation matrix.
Size
Size of the output image.
int
default:"INTER_LINEAR"
Combination of interpolation methods (see InterpolationFlags) and the optional flag WARP_INVERSE_MAP that means that M is the inverse transformation.
int
default:"BORDER_CONSTANT"
Pixel extrapolation method; 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.
Scalar
default:"Scalar()"
Value used in case of a constant border; by default, it is 0.
The function cannot operate in-place.
getRotationMatrix2D
Calculates an affine matrix of 2D rotation.Point2f
Center of the rotation in the source image.
double
Rotation angle in degrees. Positive values mean counter-clockwise rotation (the coordinate origin is assumed to be the top-left corner).
double
Isotropic scale factor.
getAffineTransform
Calculates an affine transform from three pairs of the corresponding points.Point2f[]
Coordinates of triangle vertices in the source image.
Point2f[]
Coordinates of the corresponding triangle vertices in the destination image.
invertAffineTransform
Inverts an affine transformation.InputArray
Original affine transformation.
OutputArray
Output reverse affine transformation.
Perspective Transformations
warpPerspective
Applies a perspective transformation to an image.InputArray
Input image.
OutputArray
Output image that has the size dsize and the same type as src.
InputArray
3×3 transformation matrix.
Size
Size of the output image.
int
default:"INTER_LINEAR"
Combination of interpolation methods (INTER_LINEAR or INTER_NEAREST) and the optional flag WARP_INVERSE_MAP.
int
default:"BORDER_CONSTANT"
Pixel extrapolation method (BORDER_CONSTANT or BORDER_REPLICATE).
Scalar
default:"Scalar()"
Value used in case of a constant border; by default, it equals 0.
The function cannot operate in-place.
getPerspectiveTransform
Calculates a perspective transform from four pairs of the corresponding points.Point2f[]
Coordinates of quadrangle vertices in the source image.
Point2f[]
Coordinates of the corresponding quadrangle vertices in the destination image.
int
default:"DECOMP_LU"
Method passed to cv::solve.
Generic Remapping
remap
Applies a generic geometrical transformation to an image.InputArray
Source image.
OutputArray
Destination image. It has the same size as map1 and the same type as src.
InputArray
The first map of either (x,y) points or just x values having the type CV_16SC2, CV_32FC1, or CV_32FC2.
InputArray
The second map of y values having the type CV_16UC1, CV_32FC1, or none (empty map if map1 is (x,y) points), respectively.
int
Interpolation method. The methods INTER_AREA, INTER_LINEAR_EXACT and INTER_NEAREST_EXACT are not supported by this function.
int
default:"BORDER_CONSTANT"
Pixel extrapolation method. 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.
Scalar
default:"Scalar()"
Value used in case of a constant border. By default, it is 0.
This function cannot operate in-place. Due to current implementation limitations the size of an input and output images should be less than 32767x32767.
getRectSubPix
Retrieves a pixel rectangle from an image with sub-pixel accuracy.InputArray
Source image.
Size
Size of the extracted patch.
Point2f
Floating point coordinates of the center of the extracted rectangle within the source image. The center must be inside the image.
OutputArray
Extracted patch that has the size patchSize and the same number of channels as src.
int
default:"-1"
Depth of the extracted pixels. By default, they have the same depth as src.
Enumerations
InterpolationFlags
Interpolation algorithm:INTER_NEAREST- Nearest neighbor interpolationINTER_LINEAR- Bilinear interpolationINTER_CUBIC- Bicubic interpolationINTER_AREA- Resampling using pixel area relation (preferred for image decimation)INTER_LANCZOS4- Lanczos interpolation over 8x8 neighborhoodINTER_LINEAR_EXACT- Bit exact bilinear interpolationINTER_NEAREST_EXACT- Bit exact nearest neighbor interpolationINTER_MAX- Mask for interpolation codesWARP_FILL_OUTLIERS- Flag, fills all of the destination image pixelsWARP_INVERSE_MAP- Flag, inverse transformation
WarpPolarMode
Polar mapping mode:WARP_POLAR_LINEAR- Remaps an image to/from polar spaceWARP_POLAR_LOG- Remaps an image to/from semilog-polar space
