cv.warpaffine(img,m,dsize)
时间: 2024-05-14 07:12:24 浏览: 14
The function cv.warpAffine() in OpenCV is used to apply an affine transformation to an image.
Parameters:
- img: input image
- m: 2x3 transformation matrix
- dsize: size of the output image
The transformation matrix m is defined by 6 parameters:
- a: scaling factor in the x-direction
- b: rotation factor in the x-direction
- c: translation in the x-direction
- d: rotation factor in the y-direction
- e: scaling factor in the y-direction
- f: translation in the y-direction
The function returns the transformed image.
Example usage:
```
import cv2 as cv
import numpy as np
img = cv.imread('image.jpg')
rows, cols = img.shape[:2]
# define transformation matrix
theta = 30
scale = 1.5
M = np.float32([[scale*np.cos(theta), scale*np.sin(theta), 0], [-scale*np.sin(theta), scale*np.cos(theta), 0]])
# apply affine transformation
dst = cv.warpAffine(img, M, (cols, rows))
# display original and transformed images
cv.imshow('Original', img)
cv.imshow('Transformed', dst)
cv.waitKey(0)
cv.destroyAllWindows()
```
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)