OpenCV-Python是旨在解决计算机视觉问题的Python绑定库。cv2.rotate()
方法用于将2D数组旋转90度的倍数。函数cv::rotate以三种不同的方式旋转数组。
用法: cv2.cv.rotate( src, rotateCode[, dst] )
参数:
src:它是要更改其色彩空间的图像。
rotateCode:它是一个枚举,用于指定如何旋转数组。
dst:它是与src图像大小和深度相同的输出图像。它是一个可选参数。
返回值:它返回一个图像。
用于以下所有示例的图像:
范例1:顺时针旋转90度
# Python program to explain cv2.rotate() method
# importing cv2
import cv2
# path
path = r'C:\Users\user\Desktop\geeks14.png'
# Reading an image in default mode
src = cv2.imread(path)
# Window name in which image is displayed
window_name = 'Image'
# Using cv2.rotate() method
# Using cv2.ROTATE_90_CLOCKWISE rotate
# by 90 degrees clockwise
image = cv2.rotate(src, cv2.cv2.ROTATE_90_CLOCKWISE)
# Displaying the image
cv2.imshow(window_name, image)
cv2.waitKey(0)
输出:
范例2:顺时针旋转180度
# Python program to explain cv2.rotate() method
# importing cv2
import cv2
# path
path = r'C:\Users\user\Desktop\geeks14.png'
# Reading an image in default mode
src = cv2.imread(path)
# Window name in which image is displayed
window_name = 'Image'
# Using cv2.rotate() method
# Using cv2.ROTATE_180 rotate by
# 180 degrees clockwise
image = cv2.rotate(src, cv2.ROTATE_180)
# Displaying the image
cv2.imshow(window_name, image)
cv2.waitKey(0)
输出:
范例3:顺时针旋转270度
# Python program to explain cv2.rotate() method
# importing cv2
import cv2
# path
path = r'C:\Users\user\Desktop\geeks14.png'
# Reading an image in default mode
src = cv2.imread(path)
# Window name in which image is displayed
window_name = 'Image'
# Using cv2.rotate() method
# Using cv2.ROTATE_90_COUNTERCLOCKWISE
# rotate by 270 degrees clockwise
image = cv2.rotate(src, cv2.ROTATE_90_COUNTERCLOCKWISE)
# Displaying the image
cv2.imshow(window_name, image)
cv2.waitKey(0)
输出:
相关用法
- Python OpenCV cv2.imread()用法及代码示例
- Python OpenCV cv2.imshow()用法及代码示例
- Python OpenCV cv2.imwrite()用法及代码示例
- Python OpenCV cv2.line()用法及代码示例
- Python OpenCV cv2.rectangle()用法及代码示例
- Python OpenCV cv2.circle()用法及代码示例
- Python OpenCV cv2.putText()用法及代码示例
- Python OpenCV cv2.ellipse()用法及代码示例
- Python OpenCV cv2.cvtColor()用法及代码示例
- Python OpenCV cv2.copyMakeBorder()用法及代码示例
- Python OpenCV cv2.arrowedLine()用法及代码示例
- Python OpenCV cv2.blur()用法及代码示例
- Python OpenCV cv2.erode()用法及代码示例
注:本文由纯净天空筛选整理自divyamohan123大神的英文原创作品 Python OpenCV – cv2.rotate() method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。