Image Resizing
resize
Resizes an image.Input image.
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.
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.
Scale factor along the horizontal axis; when it equals 0, it is computed as (double)dsize.width/src.cols.
Scale factor along the vertical axis; when it equals 0, it is computed as (double)dsize.height/src.rows.
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.Input image.
Output image that has the size dsize and the same type as src.
2×3 transformation matrix.
Size of the output image.
Combination of interpolation methods (see InterpolationFlags) and the optional flag WARP_INVERSE_MAP that means that M is the inverse transformation.
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.
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.Center of the rotation in the source image.
Rotation angle in degrees. Positive values mean counter-clockwise rotation (the coordinate origin is assumed to be the top-left corner).
Isotropic scale factor.
getAffineTransform
Calculates an affine transform from three pairs of the corresponding points.Coordinates of triangle vertices in the source image.
Coordinates of the corresponding triangle vertices in the destination image.
invertAffineTransform
Inverts an affine transformation.Original affine transformation.
Output reverse affine transformation.
Perspective Transformations
warpPerspective
Applies a perspective transformation to an image.Input image.
Output image that has the size dsize and the same type as src.
3×3 transformation matrix.
Size of the output image.
Combination of interpolation methods (INTER_LINEAR or INTER_NEAREST) and the optional flag WARP_INVERSE_MAP.
Pixel extrapolation method (BORDER_CONSTANT or BORDER_REPLICATE).
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.Coordinates of quadrangle vertices in the source image.
Coordinates of the corresponding quadrangle vertices in the destination image.
Method passed to cv::solve.
Generic Remapping
remap
Applies a generic geometrical transformation to an image.Source image.
Destination image. It has the same size as map1 and the same type as src.
The first map of either (x,y) points or just x values having the type CV_16SC2, CV_32FC1, or CV_32FC2.
The second map of y values having the type CV_16UC1, CV_32FC1, or none (empty map if map1 is (x,y) points), respectively.
Interpolation method. The methods INTER_AREA, INTER_LINEAR_EXACT and INTER_NEAREST_EXACT are not supported by this function.
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.
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.Source image.
Size of the extracted patch.
Floating point coordinates of the center of the extracted rectangle within the source image. The center must be inside the image.
Extracted patch that has the size patchSize and the same number of channels as src.
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
