python opencv旋转,Python OpenCV cv2.rotate()用法及代码示例

OpenCV-Python是旨在解决计算机视觉问题的Python绑定库。cv2.rotate()方法用于将2D数组旋转90度的倍数。函数cv::rotate以三种不同的方式旋转数组。

用法: cv2.cv.rotate( src, rotateCode[, dst] )

参数:

src:它是要更改其色彩空间的图像。

rotateCode:它是一个枚举,用于指定如何旋转数组。

dst:它是与src图像大小和深度相同的输出图像。它是一个可选参数。

返回值:它返回一个图像。

用于以下所有示例的图像:

13148a4c0d44215a94fd2e08fdd8ae80.png

范例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)

输出:

0a87a7e300651f295ea741c8c85bfea9.png

范例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)

输出:

9dd53d08ced5042a0685426ed07d4819.png

范例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)

输出:

7d749eb3650e1d64551818eeabea3a37.png

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值