Skip to content

warpPerspective

Image processingfunctionOpenCV 5.0.0
import { warpPerspective } from '@banou/opencv-wasm'

Use after await initOpenCV(). See the initialization and named imports guide.

example: samples/cpp/snippets/warpPerspective_demo.cpp An example program shows using cv::getPerspectiveTransform and cv::warpPerspective for image warping Applies a perspective transformation to an image.

The function warpPerspective transforms the source image using the specified matrix:

\texttt{dst} (x,y) =  \texttt{src} \left ( \frac{M_{11} x + M_{12} y + M_{13}}{M_{31} x + M_{32} y + M_{33}} ,
     \frac{M_{21} x + M_{22} y + M_{23}}{M_{31} x + M_{32} y + M_{33}} \right )

when the flag #WARP_INVERSE_MAP is set. Otherwise, the transformation is first inverted with invert and then put in the formula above instead of M. The function cannot operate in-place.

See: warpAffine, resize, remap, getRectSubPix, perspectiveTransform

warpPerspective(src: Mat, dst: Mat, M: Mat, dsize: Size, flags: number, borderMode: number, borderValue: Scalar, hint: number): void;
5 available overloads
warpPerspective(src: Mat, dst: Mat, M: Mat, dsize: Size): void;
warpPerspective(src: Mat, dst: Mat, M: Mat, dsize: Size, flags: number): void;
warpPerspective(src: Mat, dst: Mat, M: Mat, dsize: Size, flags: number, borderMode: number): void;
warpPerspective(src: Mat, dst: Mat, M: Mat, dsize: Size, flags: number, borderMode: number, borderValue: Scalar): void;
warpPerspective(src: Mat, dst: Mat, M: Mat, dsize: Size, flags: number, borderMode: number, borderValue: Scalar, hint: number): void;
src

input image.

dst

Output destination, filled by the native operation. output image that has the size dsize and the same type as src .

M

3\times 3 transformation matrix.

dsize

size of the output image.

flags

combination of interpolation methods (#INTER_LINEAR or #INTER_NEAREST) and the optional flag #WARP_INVERSE_MAP, that sets M as the inverse transformation ( \texttt{dst}\rightarrow\texttt{src} ).

borderMode

pixel extrapolation method (#BORDER_CONSTANT or #BORDER_REPLICATE).

borderValue

value used in case of a constant border; by default, it equals 0.

hint

Implementation modification flags. Set #ALGO_HINT_APPROX to use FP16 precision (if available) for linear calculation for faster speed. See #AlgorithmHint.

These signatures describe this package. Upstream documentation can mention optional backends that are absent from this build. Check runtime compatibility before choosing a backend or file format.