python opencv对图像进行旋转且不裁剪图片的方法
来源:互联网 发布:win7电脑优化 编辑:程序博客网 时间:2024/06/06 11:37
最近在做深度学习时需要用到图像处理相关的操作,在度娘上找到的图片旋转方法千篇一律,旋转完成的图片都不是原始大小,很苦恼,于是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!
阅读全文
0 0
- python opencv对图像进行旋转且不裁剪图片的方法
- android 对图片进行裁剪的方法
- opencv实现图片的裁剪以及旋转
- python-opencv旋转图像,保持图像不被裁减
- [python + opencv] 图像的旋转和分块
- [Swift3] 对图片进行裁剪
- Python-OpenCv之图像基本处理-平移,缩放,旋转,翻转,裁剪及仿射变换
- 利用OpenCV对图像旋转
- 图像的旋转 OpenCV
- OpenCV图像的旋转
- Emgu&openCV二值化图像,对不为零的区域进行检测
- 对上传的图片进行裁剪处理后保存
- 关于用VC对图像进行裁剪
- 利用matlab对rgb图像进行裁剪
- opencv对图像的旋转操作以及尺寸改变
- 【图像处理】基于OpenCV底层实现的图片旋转
- 利用插值的方法对图像进行缩放的MATLAB和OpenCV源码!
- opencv对图像进行标定
- Tensorflow1.4安装gpu教程
- 编写游戏变速器的原理
- VTK图像基本操作-图像信息的访问与修改
- 七、Netflix Eureka && 搭建服务注册中心
- VS中使用Github全图解
- python opencv对图像进行旋转且不裁剪图片的方法
- typeScipt学习笔记(一)
- ARP攻击
- 浅谈Web网站架构演变过程
- 看得“深”、看得“清” —— 深度学习在图像超清化的应用
- android四种点击事件触发写法
- office打开满--几分钟一直在转圈
- 蓝桥杯 历届试题 数字游戏 部分超时
- Nginx 基本入门