透视变换(Perspective Transformation)是将图片投影到一个新的视平面(Viewing Plane),也称作投影映射(Projective Mapping)。如下图所示

透视变换

透视变换的原理和公式推导见如下博客
【图像处理】透视变换 Perspective Transformation
【OpenCV】透视变换 Perspective Transformation(续)
opencv之仿射变换
图像几何变换之透视变换
图像变换——向前映射和向后映射

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.void perspectiveTransform(InputArray src, OutputArray dst, InputArray mtx)
Parameters:
src – Source two-channel or three-channel floating-point array. Each element is a 2D/3D vector to be transformed.
dst – Destination array of ***the same size and type as src*** .
mtx – 3x3 or 4x4 floating-point transformation matrix.
  • c++ 代码实现

void ImageTransform::perspective_form(Mat &srcimg, Mat &dstimg, Mat &offset)
{Point2f quad_src[4];Point2f quad_dst[4];quad_src[0] = Point2f(0.0*srcimg.cols, 0.0*srcimg.rows);quad_src[1] = Point2f(srcimg.cols - 1, 0.0*srcimg.rows);quad_src[2] = Point2f(0.0*srcimg.cols, srcimg.rows - 1);quad_src[3] = Point2f(srcimg.cols - 1, srcimg.rows - 1);quad_dst[0] = Point2f(0.1*srcimg.cols, 0.1*srcimg.rows);quad_dst[1] = Point2f(srcimg.cols - 1, 0.0*srcimg.rows);quad_dst[2] = Point2f(0.0*srcimg.cols, srcimg.rows - 1);quad_dst[3] = Point2f(0.9*srcimg.cols, srcimg.rows - 1);Mat persMat = getPerspectiveTransform(quad_src, quad_dst);vector<Point2f> points, points_tran;for (int row = 0; row < srcimg.rows; row++){for (int col = 0; col < srcimg.cols; col++){points.push_back(Point2f(col, row));}}perspectiveTransform(points, points_tran, persMat);int count = 0;for (int row = 0; row < srcimg.rows; row++){uchar *pixel = srcimg.ptr<uchar>(row);float *dxy = offset.ptr<float>(row);for (int col = 0; col < srcimg.cols; col++){int x = static_cast<int>(points_tran[count].x);int y = static_cast<int>(points_tran[count].y);uchar *new_pixel = dstimg.ptr<uchar>(y);new_pixel[3 * x] = pixel[3 * col]; //最近邻插值new_pixel[3 * x + 1] = pixel[3 * col + 1];new_pixel[3 * x + 2] = pixel[3 * col + 2];dxy[2 * col] = points_tran[count].y - row;dxy[2 * col + 1] = points_tran[count].x - col;count++;}}return;}

程序运行结果

透视变换(perspective transformation)相关推荐

  1. 【图像处理】透视变换 Perspective Transformation

    透视变换(Perspective Transformation)是将图片投影到一个新的视平面(Viewing Plane),也称作投影映射(Projective Mapping).通用的变换公式为: ...

  2. 【OpenCV】透视变换 Perspective Transformation(续)

    透视变换的原理和矩阵求解请参见前一篇<透视变换 Perspective Transformation>.在OpenCV中也实现了透视变换的公式求解和变换函数. 求解变换公式的函数: [cp ...

  3. 【OpenCV】透视变换 Perspective Transformation

    透视变换的原理和矩阵求解请参见前一篇<透视变换 Perspective Transformation>.在OpenCV中也实现了透视变换的公式求解和变换函数. 求解变换公式的函数: Mat ...

  4. 【CG】透视变换(Perspective Transformation)

    起源 透视与消失点 单点透视 - 1 个消失点 两点透视 - 2个消失点 三点透视 - 3个消失点 透视投影变换 透视变换矩阵 透视变换矩阵与 Homography.相机内参的关系 透视与车载环境的联 ...

  5. 【图像处理】透视变换 Perspective Transformation(含续加部分)

    本文博文地址:https://blog.csdn.net/xiaowei_cqu/article/details/26471527#commentsedit 续文博文地址:https://blog.c ...

  6. 【图像处理】透视变换 Perspective Transformation(小细节修正和推导流程补充)

    这部分的推导,首先是求解∆x3,∆y3,然后通过得到的方程组,求解可得a13,a23,然后通过∆x1,∆x2分别求得a21,a11,同样的通过∆y1,∆y2求得a22和a12,至此透视变换矩阵所有元素 ...

  7. 图像处理中的投影变换(Perspective Transformation)

    透视变换(Perspective Transformation)是将图片投影到一个新的视平面(Viewing Plane),也称作投影映射(Projective Mapping).通用的变换公式为: ...

  8. 透视变换(perspective transformation)和射影(投影)变换(projective transformation)

    透视变换(perspective transformation)和射影(投影)变换(projective transformation) 0几点说明 投影和变换的区别. 投影分为:平行投影或者正射投影 ...

  9. 透视投影变换-Perspective Transformation

    文章目录 1透视投影变换概述 2透视投影变换原理 3透视投影变换的实现 1透视投影变换概述 透视投影变换(Perspective Transformation)是对图像做视平面(Viewing Pla ...

最新文章

  1. 终于感觉掌握了一门重要的技术
  2. VOA AGRICULTURE REPORT - Two Efforts Seek to Increase Food Security in Africa
  3. MyBatis 缓存详解-开启二级缓存的方法
  4. [源码学习]--UGUI
  5. ajax背景、ajax对象、ajax状态、ajax与http、ajax请求数据接口、同步与异步、ajax请求XML数据、封装ajax函数、artTemplate简介、同源策略和跨域请求、JSONP
  6. 2019年3月计算机考试操作,2019年3月计算机二级C++操作练习题(一)
  7. 工厂 调用Unity Application Block 通过XML配置文件映射读取数据层方法
  8. eclipse抽取一段代码作为函数的方法(Extract Method)
  9. php 提取二维数组的key,PHP 获取二维数组中某个key的集合
  10. WINDOWS 2008的trustedinstallerexe占用过多CPU导致服务器性能下降的问题处理
  11. 圆柱体积怎么算立方公式_圆柱体体积计算公式?
  12. 小游戏开发设计之塔防类游戏
  13. 机器学习笔记——乳腺癌鸢尾花分类问题详解(没有直接调包)
  14. Flexsim Rack设置最底层Level不放货物
  15. 调焦后焦实现不同距离成像_照片要清晰、对焦必须深入理解!对焦模式、对焦区域模式等对焦知识...
  16. C++实现龙贝格求积分算法
  17. 饥荒控制台输入没用_饥荒联机版代码为什么没效 怎么用怎么输入
  18. web前端入门到实战:CSS mix-blend-mode滤色screen混合模式
  19. 新一年涨工资指南:AI薪资水平和就业前景分析(一定要看完!)
  20. 安卓编程常见错误记录

热门文章

  1. zoom 用法 flex zoom
  2. Linux下查看显卡型号
  3. 【二分图匹配】【CSTC2000】丘比特的烦恼
  4. 虚拟服务器存储扩容方法,虚拟化数据中心存储扩容方案
  5. 优盘启动盘恢复为普通优盘
  6. Attribute特性定义及应用
  7. 前端面试题——计算机网络 高频
  8. air仿QQ弹出提示窗口
  9. 裴礼文数学分析中的典型问题与方法练习 1.1.5 解答貌似有问题.
  10. 马蜂窝站队腾讯,在线旅游的格局已定?