当前位置: 首页 > news >正文

旋转图片两种方法

这两种方法在旋转图像时,可能会产生一些不同的效果:

rotate_image_new()旋转后的图像完全包含旋转前的内容,并且填充边界尽可能小

rotate_image() 保持原始图像的大小,并根据填充选项决定是否填充边界为白色。如果 if_fill_white 参数为 True,则填充边界为白色;否则,边界将保持原始图像的值。这种方法可以更快速地旋转图像,但可能会导致旋转后的图像包含额外的空白区域或丢失部分图像信息。


def rotate_image_new(image, degree):'''旋转图片角度'''from math import *# dividing height and width by 2 to get the center of the imageheight, width = image.shape[:2]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(image, matRotation, (widthNew, heightNew), borderValue=(255, 255, 255))return imgRotationdef rotate_image( image, angle,if_fill_white = False):'''顺时针旋转'''# dividing height and width by 2 to get the center of the imageheight, width = image.shape[:2]# get the center coordinates of the image to create the 2D rotation matrixcenter = (width / 2, height / 2)# using cv2.getRotationMatrix2D() to get the rotation matrixrotate_matrix = cv2.getRotationMatrix2D(center=center, angle=angle, scale=1)# rotate the image using cv2.warpAffineif not if_fill_white:rotated_image = cv2.warpAffine(src=image, M=rotate_matrix, dsize=(width, height) )else:color = (255, 255) if len(image.shape)==2 else (255, 255,255)rotated_image = cv2.warpAffine(src=image, M=rotate_matrix, dsize=(width, height), borderValue=color)return rotated_image
http://www.lryc.cn/news/154962.html

相关文章:

  • 10 mysql tiny/small/medium/big int 的数据存储
  • UI自动化测试之Jenkins配置
  • 电视盒子什么品牌好?数码博主盘点目前性能最好的电视盒子
  • 对于枚举类型的输出
  • solidity开发环境配置,vscode搭配remix
  • chatGPT生成代码--go组合算法
  • 推荐6款普通人搞副业做自媒体AI工具
  • vs中git提交合并分支的步骤记录
  • PostgreSQL 备份恢复:pg_probackup
  • 博客程序系统其它功能扩充
  • MATLAB 2023安装方法之删除旧版本MATLAB,安装新版本MATLAB
  • 全国唯一一所初试考Java的学校!平均300分拿下
  • day35 | 860.柠檬水找零、406.根据身高重建队列、452. 用最少数量的箭引爆气球
  • ffmpeg批量转码
  • 时序预测 | MATLAB实现基于QPSO-BiLSTM、PSO-BiLSTM和BiLSTM时间序列预测
  • 【TypeScript学习】—基本类型(二)
  • uni-app点击复制指定内容(点击复制)
  • 无涯教程-Flutter - 简介
  • 【STM32】学习笔记-时间戳RTC
  • 绿色能源迎来跨越式增长新时代
  • 【算法】函数渐近的界基础知识及定理
  • stable diffusion实践操作-writing
  • idea查找maven所有依赖
  • 【业务功能篇97】微服务-springcloud-springboot-电商购物车模块-获取当前登录用户的购物车信息
  • Shell常用的几个正则表达式:[:alnum:], [:alpha:], [:upper:], [:lower:], [:digit:] 认知
  • 简单的爬虫代码 爬(豆瓣电影)
  • 微服务之架构演变
  • 面试问题记录一 --- C++(Qt方向)
  • 使用词袋模型(BoW)测试提取图像的特征点和聚类中心
  • 利用vba处理Excel表格数据实现键值转化,适用于将编码转化成对应的文本