Python Opencv实践 - 图像透射变换

复制代码
import cv2 as cv
import numpy as np
import matplotlib.pyplot as plt


img = cv.imread("../SampleImages/pomeranian.png", cv.IMREAD_COLOR)
rows,cols = img.shape[:2]
print(rows,cols)

#opencv中的透射变换,需要一个3x3透射变换矩阵
#这个矩阵可以通过cv.getPerspectiveTransform(src,dst)获得
#src是原图中的4个点的坐标,dst是目标图像中的4个点的坐标(任意三个点不共线)
#参考资料:https://blog.csdn.net/qq_50394133/article/details/123832496
srcPts = np.float32([[56,65],[368,52],[28,387],[389,390]])
dstPts = np.float32([[100,145],[300,100],[80,290],[310,300]])
M_perspective = cv.getPerspectiveTransform(srcPts,dstPts)


#图像透射变换
#cv.warpPerspective(src,M,dsize,dst,flags,borderMode,borderValue)
img_perspective = cv.warpPerspective(img,M_perspective,(cols,rows))

#显示图像
fig,axes = plt.subplots(nrows=1, ncols=2, figsize=(12,12), dpi=100)
axes[0].imshow(img[:,:,::-1])
axes[0].set_title("Original")
axes[1].imshow(img_perspective[:,:,::-1])
axes[1].set_title("Perspective Transform")
相关推荐
神仙别闹6 分钟前
基于 C++实现(控制台)车辆信息管理系统
开发语言·c++
智塑未来8 分钟前
常用的在线ping测试工具有哪些
服务器·开发语言·php
卷无止境24 分钟前
FastAPI 的可观测性进化,从打日志到看清整个系统的呼吸
后端·python·fastapi
Freak嵌入式32 分钟前
MicroPython+Pico 接收空闲中断和发送空闲中断全实战
java·开发语言·stm32·单片机·嵌入式硬件
Zentceh32 分钟前
全彩夜视 vs 黑白夜视:信息密度、AI识别准确率对比
人工智能·科技·计算机视觉·车载系统·无人机·量子计算·视频
重生之小比特33 分钟前
【初阶C++】string
开发语言·c++
卷无止境41 分钟前
FastAPI 的 CI/CD 之路,从代码提交到线上运行
后端·python·fastapi
2601_9623824343 分钟前
系统学习Python——单元测试unittest:执行测试用例(unit test python)
python·测试用例·测试框架·unittest·测试集合
小玮看世界1 小时前
[Python]动态规划三步走:从爬楼梯到打家劫舍,再到最大子数组和
开发语言·python·动态规划
AI视觉网奇1 小时前
3d子部件高亮选中
开发语言·javascript·3d