python opencv对图像进行旋转且不裁剪图片的实现方法
作者:hui3909 时间:2023-03-12 02:40:09
最近在做深度学习时需要用到图像处理相关的操作,在度娘上找到的图片旋转方法千篇一律,旋转完成的图片都不是原始大小,很苦恼,于是google到歪果仁的网站扒拉了一个方法,亲测好用,再次嫌弃天下文章一大抄的现象,虽然我也是抄歪果仁的。
废话不多说了,直接贴代码了。
def rotate_bound(image, angle):
# grab the dimensions of the image and then determine the
# center
(h, w) = image.shape[:2]
(cX, cY) = (w // 2, h // 2)
# grab the rotation matrix (applying the negative of the
# angle to rotate clockwise), then grab the sine and cosine
# (i.e., the rotation components of the matrix)
M = cv2.getRotationMatrix2D((cX, cY), -angle, 1.0)
cos = np.abs(M[0, 0])
sin = np.abs(M[0, 1])
# compute the new bounding dimensions of the image
nW = int((h * sin) + (w * cos))
nH = int((h * cos) + (w * sin))
# adjust the rotation matrix to take into account translation
M[0, 2] += (nW / 2) - cX
M[1, 2] += (nH / 2) - cY
# perform the actual rotation and return the image
return cv2.warpAffine(image, M, (nW, nH))
其他的不用多说了吧,第一个参数穿opencv读取的图像,第二个参数传入需要旋转的角度,enjoy!
来源:https://blog.csdn.net/hui3909/article/details/78854387
标签:python,opencv,旋转,不裁剪,图片
0
投稿
猜你喜欢
php注册系统和使用Xajax即时验证用户名是否被占用
2023-09-12 05:27:55
详解bootstrap导航栏.nav与.navbar区别
2023-08-15 19:18:42
谈中国站长站的文章干扰码实现方法
2007-10-13 11:13:00
表格梳理解析python内置时间模块看完就懂
2023-10-21 08:10:27
设计提升满意度
2010-05-16 15:00:00
在ASP中使用SQL语句之8:随机数的用法
2007-08-11 13:15:00
利用ThinkPHP内置的ThinkAjax实现异步传输技术的实现方法
2023-09-11 15:11:50
兼容所有浏览器的设为首页与显示小策略
2009-01-12 18:50:00
go实现文件的创建、删除与读取示例代码
2023-06-17 05:10:50
利用SQL语句对不同数据库进行高效果分页
2008-11-28 14:44:00
Python高级编程之继承问题详解(super与mro)
2023-08-08 18:58:47
PHP 页面跳转到另一个页面的多种方法方法总结
2023-06-14 21:05:49
Python 批量下载阴阳师网站壁纸
2023-12-28 15:01:42
IOS苹果AppStore内购付款的服务器端php验证方法(使用thinkphp)
2023-06-14 13:05:56
Mysql的最大连接数怎样用java程序测试
2009-01-14 12:05:00
以SQLite和PySqlite为例来学习Python DB API
2023-07-13 02:19:14
微信小程序页面缩放式侧滑效果的实现代码
2023-09-02 05:21:45
如何处理Oracle中较大的文本数据?
2009-11-11 20:06:00
为FCKeditor2.6添加行距功能(最新修改)
2008-08-18 21:09:00
Dreamweaver虚拟在线试衣室
2009-07-05 18:54:00