dst_points应该怎样设置
时间: 2023-07-26 13:39:28 浏览: 46
`dst_points` 是目标图像上的四个顶点,在透视变换中用于指定源图像的四个顶点在目标图像上的对应位置。通常情况下,我们需要手动指定这些顶点的坐标,以保证变换后的图像符合我们的要求。
如果要将整张图做透视变换,可以将 `dst_points` 的四个顶点设置为目标图像的四个角点,即左上角、左下角、右下角、右上角。代码如下:
```python
import cv2
import numpy as np
# 定义源图像的四个顶点和目标图像的四个顶点
src_points = np.float32([[0, 0], [0, img.shape[0]], [img.shape[1], img.shape[0]], [img.shape[1], 0]])
dst_points = np.float32([[0, 0], [0, img.shape[0]], [img.shape[1], img.shape[0]], [img.shape[1], 0]])
# 计算透视变换矩阵
M = cv2.getPerspectiveTransform(src_points, dst_points)
# 对源图像进行透视变换
dst_img = cv2.warpPerspective(img, M, (img.shape[1], img.shape[0]))
# 显示结果图像
cv2.imshow('Input', img)
cv2.imshow('Output', dst_img)
cv2.waitKey(0)
cv2.destroyAllWindows()
```
在上述代码中,我们将 `src_points` 的四个顶点设置为源图像的四个角点,将 `dst_points` 的四个顶点也设置为目标图像的四个角点,这样就实现了对整张图做透视变换。其中 `img.shape` 可以获取源图像的尺寸,以便将目标图像设置为相同的大小。