getRotationMatrix2D
时间: 2024-05-03 17:21:34 浏览: 13
getRotationMatrix2D is a function in OpenCV which computes a 2D rotation matrix. This function takes three arguments:
1. center: The center of the rotation in the form of a tuple (x,y).
2. angle: The angle of rotation in degrees.
3. scale: The scale factor for the rotation.
The output of this function is a 2x3 matrix which can be used with the warpAffine function in OpenCV to rotate an image.
Here's an example of how to use getRotationMatrix2D:
```
import cv2
img = cv2.imread('image.jpg')
rows, cols = img.shape[:2]
# Define the center of rotation
center = (cols / 2, rows / 2)
# Define the angle of rotation
angle = 45
# Define the scale factor
scale = 1
# Compute the rotation matrix
M = cv2.getRotationMatrix2D(center, angle, scale)
# Apply the rotation to the image
rotated_img = cv2.warpAffine(img, M, (cols, rows))
# Display the rotated image
cv2.imshow('Rotated Image', rotated_img)
cv2.waitKey(0)
cv2.destroyAllWindows()
```
相关推荐
![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)
![](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)