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 plt

kids=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])

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

醋酸洋红就是我

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值