Mat
const int BLOCK_SZ = 64;
short XY[BLOCK_SZ*BLOCK_SZ * 2], A[BLOCK_SZ*BLOCK_SZ];
其中XY和A是一个已知大小的容器:
Mat _XY(bh, bw, CV_16SC2, XY), matA;
short* xy = XY + y1*bw * 2;
short* alpha = A + y1*bw;
Mat _matA(bh, bw, CV_16U, A);
这样,改变XY的值就能改变_XY的值,_MatA和A也是,alpha和A(这个是指针)。
Remap
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.
See also
remap(), undistort(), initUndistortRectifyMap()
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.