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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。