- 操作系统:ubuntu22.04
- OpenCV版本:OpenCV4.9
- IDE:Visual Studio Code
- 编程语言:C++11
算法描述
计算四对对应点之间的透视变换。
该函数计算 3×3 的透视变换矩阵,使得:
t i x i ′ t i y i ′ t i \] = map_matrix ⋅ \[ x i y i 1 \] \\begin{bmatrix} t_i x'_i \\\\ t_i y'_i \\\\ t_i \\end{bmatrix} = \\texttt{map\\_matrix} \\cdot \\begin{bmatrix} x_i \\\\ y_i \\\\ 1 \\end{bmatrix} tixi′tiyi′ti =map_matrix⋅ xiyi1
其中,
d s t ( i ) = ( x i ′ , y i ′ ) , s r c ( i ) = ( x i , y i ) , i = 0 , 1 , 2 , 3 dst(i)=(x'_i,y'_i), src(i)=(x_i, y_i), i=0,1,2,3 dst(i)=(xi′,yi′),src(i)=(xi,yi),i=0,1,2,3
getPerspectiveTransform() 函数用于计算一个 3×3 的透视变换矩阵,该矩阵将源图像中的四边形映射到目标图像中的另一个四边形。这种变换可以实现图像的透视校正,例如将倾斜的图像拉直或调整视角。
### 函数原型1
```cpp
Mat cv::getPerspectiveTransform
(
InputArray src,
InputArray dst,
int solveMethod = DECOMP_LU
)
```
### 函数参数1
* 参数src 源图像中四边形顶点的坐标。
* 参数dst 目标图像中对应四边形顶点的坐标。
* 参数solveMethod 传递给 cv::solve 函数的方法(DecompTypes 类型)。
### 函数原型2
```cpp
Mat cv::getPerspectiveTransform
(
const Point2f src[],
const Point2f dst[],
int solveMethod = DECOMP_LU
)
```
### 函数参数2
* 参数src 源图像中四边形顶点的坐标。
* 参数dst 目标图像中对应四边形顶点的坐标。
* 参数solveMethod 传递给 cv::solve 函数的方法(DecompTypes 类型)。
### 示例代码
```cpp
#include