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

OpenCV图像处理——几何变换

目录

  • 图像缩放
  • 图像平移
  • 图像旋转
  • 图像的仿射变换
  • 透射变换
  • 图像金字塔

图像缩放

cv.resize(src,dsize,fx=0,fy=0,interpolation=cv2.INTER_LINEAR)

在这里插入图片描述

import numpy as np
import cv2 as cv
import matplotlib.pyplot as pltkids=cv.imread('./汪学长的随堂资料/4/图像操作/dog.jpg')
plt.imshow(kids[:,:,::-1])

在这里插入图片描述

# 绝对尺寸
rows,cols=kids.shape[:2]
res=cv.resize(kids,(2*cols,2*rows))
plt.imshow(res[:,:,::-1])

在这里插入图片描述

# 相对尺寸
res1=cv.resize(kids,None,fx=0.5,fy=0.5)
plt.imshow(res1[:,:,::-1])

在这里插入图片描述

图像平移

cv.warpAffine(img,M,dsize)

在这里插入图片描述
在这里插入图片描述

M=np.float32([[1,0,100],[0,1,50]])
res2=cv.warpAffine(kids,M,(cols,rows))
plt.imshow(res2[:,:,::-1])

在这里插入图片描述

图像旋转

cv.getRotationMatrix2D(center,angle,scale)

在这里插入图片描述

M=cv.getRotationMatrix2D((cols/2,rows/2),45,1)
res3=cv.warpAffine(kids,M,(cols,rows))
plt.imshow(res3[:,:,::-1])

在这里插入图片描述

图像的仿射变换

点线关系的仿射结果在原图像是一样的,但是线长度,线与线的角度会发生变化
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

# 原始位置
pts1=np.float32([[50,50],[200,50],[50,200]])
# 仿射后的位置
pts2=np.float32([[100,100],[200,50],[100,250]])
M=cv.getAffineTransform(pts1,pts2)
res4=cv.warpAffine(kids,M,(cols,rows))
plt.imshow(res4[:,:,::-1])

在这里插入图片描述

透射变换

视角的变换
在这里插入图片描述

在这里插入图片描述

pst1=np.float32([[56,65],[368,52],[28,387],[389,390]])
pst2=np.float32([[100,145],[300,100],[80,290],[310,300]])
T=cv.getPerspectiveTransform(pst1,pst2)
res5=cv.warpPerspective(kids,T,(cols,rows))
plt.imshow(res5[:,:,::-1])

在这里插入图片描述

图像金字塔

在这里插入图片描述

imgup=cv.pyrUp(kids)
plt.imshow(imgup[:,:,::-1])

在这里插入图片描述

imgdown=cv.pyrDown(kids)
plt.imshow(imgdown[:,:,::-1])

在这里插入图片描述

http://www.lryc.cn/news/122511.html

相关文章:

  • Apache JMeter:完全指南
  • js obj 生成java 实体 entity
  • 【第二阶段】kotlin语言的匿名函数与具名函数
  • P1123 取数游戏
  • JavaScript高级:原型与原型链继承方式
  • 使用vue-grid-layout时 You may need an appropriate loader to handle this file type.
  • C# 2048小游戏核心算法
  • 设计模式(5)代理模式
  • Django配置(部署环境较乱,暂时启用)
  • 【设计模式】桥接模式
  • ol问题总结二
  • 批量打印-----jsPDF将图片转为pdf,并合并pdf
  • 【Git】版本控制器详解之git的概念和基本使用
  • C语言 棱形图案
  • 在idea使用GitHub账号、Copilot异常
  • 面试热题(反转字符串中的单词)
  • Stable Diffusion WebUI 从零基础到入门
  • 【uniapp】一文读懂app端安装包升级
  • 【算法题】2518. 好分区的数目
  • 编写守护进程
  • stable-diffusion-webui启动No Python at ‘C:\xxx\xxx\python.exe‘
  • 面试热题(合并两个有序列表)
  • QT生成Word PDF文档
  • 阿里云服务器搭建WordPress建站教程基于Windows系统
  • 动态链接(8/11)
  • Python 之 Http 获取网页的 html 数据,并去掉 html 格式等相关信息
  • 干不完根本干不完,我也不想加班,快来围观时间管理大师
  • 常见设计模式
  • Android之版本号、版本别名、API等级对应关系(全)(一百六十二)
  • Redis的简介,安装(Linux、Windows),配置文件的修改---详细介绍