Python OpenCV cv2.rotate()用法及代码示例

您所在的位置:网站首页 PythonCV2 Python OpenCV cv2.rotate()用法及代码示例

Python OpenCV cv2.rotate()用法及代码示例

2023-07-04 03:49| 来源: 网络整理| 查看: 265

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)

输出:



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3