1. 基本原理

透视变换(Perspective Transformation)的本质是将图像投影到一个新的视平面,其通用变换公式为:

(u,v)为原始图像像素坐标,(x=x’/w’,y=y’/w’)为变换之后的图像像素坐标。透视变换矩阵图解如下:

仿射变换(Affine Transformation)可以理解为透视变换的特殊形式。透视变换的数学表达式为:

所以,给定透视变换对应的四对像素点坐标,即可求得透视变换矩阵;反之,给定透视变换矩阵,即可对图像或像素点坐标完成透视变换,如下图所示:

2. OpenCV透视变换函数

Mat getPerspectiveTransform(const Point2f* src, const Point2f* dst)
// Calculate a perspective transform from four pairs of the corresponding points.
// src – Coordinates of quadrangle vertices in the source image.
// dst – Coordinates of the corresponding quadrangle vertices in the destination image.void warpPerspective(InputArray src, OutputArray dst, InputArray M, Size dsize, int flags=INTER_LINEAR, int borderMode=BORDER_CONSTANT, const Scalar& borderValue=Scalar())
// Apply a perspective transform to an image.
// src – Source image.
// dst – Destination image that has the size dsize and the same type as src.
// M – 3*3 transformation matrix.
// dsize – Size of the destination image.
// flags – Combination of interpolation methods and the optional flag WARP_INVERSE_MAP that means that M is the inverse transformation (dstsrc).
// borderMode – Pixel extrapolation method. When borderMode=BORDER_TRANSPARENT, it means that the pixels in the destination image that corresponds to the “outliers” in the source image are not modified by the function.
// borderValue – Value used in case of a constant border. By default, it is 0.

3. 程序

#include <iostream>#include "highgui.h"
#include "opencv2/imgproc/imgproc.hpp"int main()
{// get original image.cv::Mat originalImage = cv::imread("road.png");// perspective image.cv::Mat perspectiveImage;// perspective transformcv::Point2f objectivePoints[4], imagePoints[4];// original image points.imagePoints[0].x = 10.0; imagePoints[0].y = 457.0;imagePoints[1].x = 395.0; imagePoints[1].y = 291.0;imagePoints[2].x = 624.0; imagePoints[2].y = 291.0;imagePoints[3].x = 1000.0; imagePoints[3].y = 457.0;// objective points of perspective image.// move up the perspective image : objectivePoints.y - value .// move left the perspective image : objectivePoints.x - value.double moveValueX = 0.0;double moveValueY = 0.0;objectivePoints[0].x = 46.0 + moveValueX; objectivePoints[0].y = 920.0 + moveValueY;objectivePoints[1].x = 46.0 + moveValueX; objectivePoints[1].y = 100.0 + moveValueY;objectivePoints[2].x = 600.0 + moveValueX; objectivePoints[2].y = 100.0 + moveValueY;objectivePoints[3].x = 600.0 + moveValueX; objectivePoints[3].y = 920.0 + moveValueY;cv::Mat transform = cv::getPerspectiveTransform(objectivePoints, imagePoints);// perspective.cv::warpPerspective(originalImage,perspectiveImage,transform,cv::Size(originalImage.rows, originalImage.cols),cv::INTER_LINEAR | cv::WARP_INVERSE_MAP);// cv::imshow("perspective image", perspectiveImage);// cvWaitKey(0);cv::imwrite("perspectiveImage.png", perspectiveImage);return 0;
}

原始图像及其透视变换结果:

转载于:https://www.cnblogs.com/liekkas0626/p/5262942.html

图像几何变换之透视变换相关推荐

  1. opencv android 透视,OpenCV图像几何变换之透视变换

    本文实例为大家分享了Android九宫格图片展示的具体代码,供大家参考,具体内容如下 1. 基本原理 透视变换(Perspective Transformation)的本质是将图像投影到一个新的视平面 ...

  2. [Python图像处理] 十二.图像几何变换之图像仿射变换、图像透视变换和图像校正

    该系列文章是讲解Python OpenCV图像处理知识,前期主要讲解图像入门.OpenCV基础用法,中期讲解图像处理的各种算法,包括图像锐化算子.图像增强技术.图像分割等,后期结合深度学习研究图像识别 ...

  3. Python 计算机视觉(五)—— OpenCV 进行图像几何变换

    几何变换不改变图像的像素值,只是实现图像像素点的重新安排:恰当的进行图像的几何变换,可以减小甚至避免由于角度等一些因素造成的图像失真问题,有利于我们在识别图像时将注意力集中到图像的有效信息中而不至于被 ...

  4. [Python图像处理] 三十六.OpenCV图像几何变换万字详解(平移缩放旋转、镜像仿射透视)

    该系列文章是讲解Python OpenCV图像处理知识,前期主要讲解图像入门.OpenCV基础用法,中期讲解图像处理的各种算法,包括图像锐化算子.图像增强技术.图像分割等,后期结合深度学习研究图像识别 ...

  5. [练气期]计算机视觉之从矩阵本质修炼图像几何变换秘籍

    [练气期]计算机视觉之从矩阵本质修炼图像几何变换秘籍 练气期,我们需要掌握哪些图像处理知识? 掌握OpenCV和图像处理的基础知识,并进行实践操作,具体包含: 为什么选择OpenCV,OpenCV是什 ...

  6. [Python从零到壹] 三十九.图像处理基础篇之图像几何变换(镜像仿射透视)

    欢迎大家来到"Python从零到壹",在这里我将分享约200篇Python系列文章,带大家一起去学习和玩耍,看看Python这个有趣的世界.所有文章都将结合案例.代码和作者的经验讲 ...

  7. No2. 图像几何变换

    基于OpenCV的图像编程基础 主要内容 一.图像平移 1. 平移,图像大小不变 2. 平移,图像大小改变 二.图像旋转 三.图像缩放 四.用户UI交互设计 五.图像的透视畸变矫正 六.结果分析 1. ...

  8. 图像几何变换知识总结

    图像几何变换知识总结 图像变换知识总结 1.相似变换(Similarity transformations) 2.仿射变换(Affine transformations) 3.单应性变换(Homoge ...

  9. Python图像处理丨带你掌握图像几何变换

    摘要:本篇文章主要讲解图像仿射变换和图像透视变换,通过Python调用OpenCV函数实. 本文分享自华为云社区<[Python图像处理] 十二.图像几何变换之图像仿射变换.图像透视变换和图像校 ...

最新文章

  1. php读取xml的值,PHP读取XML 值
  2. Apache Cassandra和低延迟应用程序
  3. Datatables + Bootstrap
  4. https及核心SSL
  5. Tendermint推出2000万美元风投基金,促进Cosmos发展
  6. 使用Eclipse调试Android程序时无法安装控制台报错INSTALL_FAILED_UPDATE_INCOMPATIBLE
  7. matlab保存超分辨率图
  8. 怎么评判网络舆情分析系统好不好的指标标准详解
  9. 易观分析联合中小银行联盟发布海南数字经济指数,敬请期待!
  10. 开发工具之 Snipaste(超级截图工具)
  11. 《财经》杂志:盛大新浪梦纪实(完全版)
  12. VCPKG 特性 - Overlay triplets
  13. 中国前十软件公司招聘官网聚合
  14. 第四章 Pandas统计分析基础
  15. 蓝凌LBPM平台,大公司流程数字化升级必选
  16. signature=f2fd61184b3328e471644f6fd3617f29,IPSEC-×××-CA
  17. Share实例:用python将ppt转为pdf
  18. 手把手教你搭建Traccar:开源免费的GPS定位追踪系统【社工】
  19. python—微信好友头像性别统计个性签名统计
  20. Unity初级教程贪吃蛇实现(Snake)带工程源码

热门文章

  1. opensuse11.4-fcitx输入法安装
  2. rails3 cookie setting
  3. Android广播机制
  4. Hyper-V虚拟机win7网络红叉,无法上网解决方法
  5. BPM实例分享:如何设置表单字体样式
  6. 第一阶段站立会议08
  7. 201521123079 《Java程序设计》第1周学习总结
  8. xpath技术解析xml以及案例模拟用户登录效果
  9. Asp.Net Web API 2第一课——入门
  10. 电厂MIS,SIS简介