python opencv旋转图像(保持图像不被裁减)
作者:yjl9122 时间:2022-02-09 13:56:32
本文实例为大家分享了python opencv旋转图像的具体代码,保持图像不被裁减,供大家参考,具体内容如下
# -*- coding:gb2312 -*-
import cv2
from math import *
import numpy as np
img = cv2.imread("3-2.jpg")
height,width=img.shape[:2]
degree=45
#旋转后的尺寸
heightNew=int(width*fabs(sin(radians(degree)))+height*fabs(cos(radians(degree))))
widthNew=int(height*fabs(sin(radians(degree)))+width*fabs(cos(radians(degree))))
matRotation=cv2.getRotationMatrix2D((width/2,height/2),degree,1)
matRotation[0,2] +=(widthNew-width)/2 #重点在这步,目前不懂为什么加这步
matRotation[1,2] +=(heightNew-height)/2 #重点在这步
imgRotation=cv2.warpAffine(img,matRotation,(widthNew,heightNew),borderValue=(255,255,255))
cv2.imshow("img",img)
cv2.imshow("imgRotation",imgRotation)
cv2.waitKey(0)
效果图:
来源:https://blog.csdn.net/yjl9122/article/details/70833330
标签:python,opencv,旋转图像
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
PHP正则表达式替换<pre>标签外的内容
2023-05-22 10:47:12
利用python实现命令行有道词典的方法示例
2021-03-24 06:32:16
![](https://img.aspxhome.com/file/2023/5/68975_0s.png)
Pytorch模型微调fine-tune详解
2021-06-17 07:29:00
![](https://img.aspxhome.com/file/2023/0/83970_0s.png)
Python实现多并发访问网站功能示例
2022-12-16 11:42:47
python实现简单神经网络算法
2021-03-22 07:03:16
![](https://img.aspxhome.com/file/2023/9/97549_0s.jpg)
Python实现截图生成符合markdown的链接
2021-07-09 10:18:22
![](https://img.aspxhome.com/file/2023/9/67299_0s.png)
python删除特定文件的方法
2023-07-13 23:29:36
python实现手机销售管理系统
2023-01-16 00:02:04
![](https://img.aspxhome.com/file/2023/3/81713_0s.jpg)
Flash连接服务器
2008-06-15 07:19:00
Linux下通过python获取本机ip方法示例
2023-02-18 05:56:15
![](https://img.aspxhome.com/file/2023/0/120560_0s.png)
使用python如何提取JSON数据指定内容
2022-08-06 23:48:41
JavaScript解释型模版
2009-10-19 23:12:00
django 消息框架 message使用详解
2021-06-21 17:22:29
谈谈CSS样式表的命名规范
2007-10-08 12:41:00
Python装饰器与线程结合提高接口访问效率方法
2021-07-16 11:28:32
Javascript 中 String.replace( ) 的妙用
2008-08-05 18:08:00
Golang中switch语句和select语句的用法教程
2023-09-02 09:09:06
Jupyter Notebook的连接密码 token查询方式
2023-10-21 23:51:47
![](https://img.aspxhome.com/file/2023/9/101339_0s.jpg)
设计师的底线
2009-05-06 12:51:00
Python OpenCV Hough直线检测算法的原理实现
2021-01-29 10:10:00
![](https://img.aspxhome.com/file/2023/9/121119_0s.png)