opencv android 透视,OpenCV图像几何变换之透视变换
本文实例为大家分享了Android九宫格图片展示的具体代码,供大家参考,具体内容如下
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 (dstsrc).
// 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
#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 transform
cv::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;
}
原始图像及其透视变换结果:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
opencv android 透视,OpenCV图像几何变换之透视变换相关推荐
- opencv android 透视,Opencv for Android 之透视变换
/** * 透视变换 * @param in 原图像 * @param point 定位到的四个点 * @return */ private Mat getWarpPersPective(Mat in ...
- 图像几何变换之透视变换
1. 基本原理 透视变换(Perspective Transformation)的本质是将图像投影到一个新的视平面,其通用变换公式为: (u,v)为原始图像像素坐标,(x=x'/w',y=y'/w') ...
- opencv android 羽化,opencv 边缘羽化,边缘过渡
原地址:http://blog.csdn.net/sogarme/article/details/12942971 当把前景和背景分开时,黑色代表背景,白色代表前景,如下图1-记作img1 为了平滑过 ...
- opencv android jni,OpenCV - AndroidStudio的JNI工程及引用OpenCV
一把利刃,用不好,会伤到你遍体鳞伤.用得好,便为你披荆斩棘,所向披靡.好与不好之间,便是历练. 几经波折,终于跌跌撞撞,集成了OpenCV,并实现了灰度图片,自此一扇新的大门已经打开. 至此我手中已经 ...
- [Python图像处理] 三十六.OpenCV图像几何变换万字详解(平移缩放旋转、镜像仿射透视)
该系列文章是讲解Python OpenCV图像处理知识,前期主要讲解图像入门.OpenCV基础用法,中期讲解图像处理的各种算法,包括图像锐化算子.图像增强技术.图像分割等,后期结合深度学习研究图像识别 ...
- OpenCV图像几何变换专题(缩放、翻转、仿射变换及透视)【python-Open_CV系列(五)】
OpenCV图像几何变换专题(缩放.翻转.仿射变换及透视)(python为工具) [Open_CV系列(五)] 文章目录 准备图片 1. 缩放 cv2.resize()方法 2. 翻转 cv2.fli ...
- youcans 的 OpenCV 学习课—5.图像的几何变换
youcans 的 OpenCV 学习课-5.图像的几何变换 本系列面向 Python 小白,从零开始实战解说 OpenCV 项目实战. 几何变换是指对图像的位置.大小.形状.投影进行变换,是将图像从 ...
- Python 计算机视觉(五)—— OpenCV 进行图像几何变换
几何变换不改变图像的像素值,只是实现图像像素点的重新安排:恰当的进行图像的几何变换,可以减小甚至避免由于角度等一些因素造成的图像失真问题,有利于我们在识别图像时将注意力集中到图像的有效信息中而不至于被 ...
- OpenCV中的图像处理 —— 改变颜色空间+图像几何变换
OpenCV中的图像处理 -- 改变颜色空间+图像几何变换 这一部分主要介绍OpenCV图像处理中的改变颜色空间和图像的几何变换,颜色空间的改变应用非常广泛,在处理图像的实际问题中,经常需要要图像变换 ...
最新文章
- Nginx 之父被拘留,时隔15年后,前老板提起了版权侵权诉讼!
- nanomsg(ZeroMQ with C)
- linux 获取CPU NUMA内存节点信息
- visual studio 2005没有chart空间_彭啸专访:2005年的国少跳级生 天赋+汗水造就成功...
- C# 子类实例化基类 基类使用不了子类的方法_C#学习笔记11--接口/泛型
- [SOJ] DAG?
- 读人人都是产品经理__2
- C/C++基础语法复习(一):C++与C语言的区别,主要有这些!
- 系统协调服务器,协调网络系统 Collaboration network system
- linux下完全删除mysql
- CodeForces - 748C Santa Claus and Robot
- vim配置运行python3快捷键_Linux VIM8 Python3 编辑器配置文件
- Windows10 创建Django项目
- Adobe Illustrator 中的路径查找器
- 软件:10款免费无广告的看图软件,总有一款适合你
- 51 单片机晶振电路原理
- mysql数据库的安装和使用方法_Mysql数据库的安装和使用
- 汇编bne的问题 汇编中的标号1: 以及bne 1b解释
- 不能整除7的整数C语言,求1-1000中能被3整除,且不能被7整除,且至少有一位数是5的整数...
- ThingsBoard 规则引擎-邮件通知