Ai
1 Star 0 Fork 0

杨雪锋/opencv-python-5

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
c5-7.py 905 Bytes
一键复制 编辑 原始数据 按行查看 历史
杨雪锋 提交于 2023-04-14 21:48 +08:00 . update ch5
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''warpAffine实现图像的旋转'''
import cv2
import random
img = cv2.imread("lena.jpg")
# 输入(height,width,channel),取高度(rows)和宽度(cols)
h,w = img.shape[:2]
# 绕图片中心进行旋转
center = (w / 2, h / 2)
# 旋转方向取(-180,180)中的随机整数值,逆时针为负,顺时针为正
angle = random.randint(-180, 180)
# 将图像缩放为80%
scale = 0.8
# 获得旋转矩阵
M = cv2.getRotationMatrix2D(center, angle, scale)
rotated1 = cv2.warpAffine(img,M,(h, w),borderValue=(255, 255, 255))
# rotate函数旋转图像
rotated2 = cv2.rotate(img, cv2.ROTATE_180)
cv2.imshow('img',img)
cv2.imshow('rotated1',rotated1)
cv2.imshow('rotated2',rotated2)
cv2.waitKey(0)
cv2.destroyAllWindows()
# 为了输出图片
import sys
sys.path.append('..\\utils')
import utils
utils.show_img([img,rotated1,rotated2],"fig5-8")
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/hopeasy/opencv-python-5.git
git@gitee.com:hopeasy/opencv-python-5.git
hopeasy
opencv-python-5
opencv-python-5
master

搜索帮助