opencv英文文档
Geometric Image Transformations
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:
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: .. math:
\texttt{dst} (x,y)= \texttt{src} (f_x(x,y), f_y(x,y))
In case when you specify the forward mapping , the OpenCV functions first compute the corresponding inverse mapping and then use the above formula.
convertMaps
Converts image transformation maps from one representation to another.
-
C++:
void
convertMaps
(InputArray
map1, InputArray
map2, OutputArray
dstmap1, OutputArray
dstmap2, int
dstmap1type, bool
nninterpolation=false
)
-
Python:
cv2.
convertMaps
(map1, map2, dstmap1type
[, dstmap1
[, dstmap2
[, nninterpolation
]
]
]
) → dstmap1, dstmap2
-
Parameters: - map1 – The first input map of type CV_16SC2 , CV_32FC1 , or CV_32FC2 .
- map2 – The second input map of type CV_16UC1 , CV_32FC1 , or none (empty matrix), respectively.
- dstmap1 – The first output map that has the type dstmap1type and the same size as src .
- dstmap2 – The second output map.
- dstmap1type – Type of the first output map that should be CV_16SC2 , CV_32FC1 , or CV_32FC2 .
- nninterpolation – Flag indicating whether the fixed-point maps are used for the nearest-neighbor or for a more complex interpolation.
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:
- . This is the most frequently used conversion operation, in which the original floating-point maps (see 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.
- . The same as above but the original maps are stored in one 2-channel matrix.
- Reverse conversion. Obviously, the reconstructed floating-point maps will not be exactly the same as the originals.
- 第一个输出是dst contains pairs (cvFloor(x), cvFloor(y))
- 第二个输出dst contains indices in a table of interpolation coefficients.
- 输出一定都是(CV_16SC2,CV_16UC1)
remap
Applies a generic geometrical transformation to an image.
-
C++:
void
remap
(InputArray
src, OutputArray
dst, InputArray
map1, InputArray
map2, int
interpolation, int
borderMode=BORDER_CONSTANT, const Scalar&
borderValue=Scalar()
)
-
Python:
cv2.
remap
(src, map1, map2, interpolation
[, dst
[, borderMode
[, borderValue
]
]
]
) → dst
-
C:
void
cvRemap
(const CvArr*
src, CvArr*
dst, const CvArr*
mapx, const CvArr*
mapy, int
flags=CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS, CvScalar
fillval=cvScalarAll(0)
)
-
Python:
cv.
Remap
(src, dst, mapx, mapy, flags=CV_INNER_LINEAR+CV_WARP_FILL_OUTLIERS, fillval=(0, 0, 0, 0)
) → None
-
Parameters: - src – Source image.
- dst – Destination image. It has the same size as map1 and the same type as src .
- map1 – The first map of either (x,y) points or just x values having the type CV_16SC2 , CV_32FC1 , or CV_32FC2 . See convertMaps() for details on converting a floating point representation to fixed-point for speed.
- 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.
- interpolation – Interpolation method (see resize() ). The method INTER_AREA is not supported by this function.
- borderMode – Pixel extrapolation method (see 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.
- borderValue – Value used in case of a constant border. By default, it is 0.
The function remap transforms the source image using the specified map:
where values of pixels with non-integer coordinates are computed using one of available interpolation methods. and can be encoded as separate floating-point maps in and respectively, or interleaved floating-point maps of in , or fixed-point maps created by using 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, contains pairs (cvFloor(x), cvFloor(y)) and contains indices in a table of interpolation coefficients.
This function cannot operate in-place.
-
invertAffineTransform
Inverts an affine transformation.
-
C++:
void
invertAffineTransform
(InputArray
M, OutputArray
iM
)