getPerspectiveTransform函数
来源:互联网 发布:mac速度慢怎么办 编辑:程序博客网 时间:2024/05/18 01:31
getPerspectiveTransform函数
函数作用:
根据输入和输出点获得图像透视变换的矩阵
函数的调用形式:
C++: Mat getPerspectiveTransform(InputArray src, InputArray dst)
InputArray src, InputArray dst:分别为变换的输入和输出点
分别四个点
透视变换后的图像不是平行的,
函数的运用:
解变换公式的函数:
- Mat getPerspectiveTransform(const Point2f src[], const Point2f dst[])
- void perspectiveTransform(InputArray src, OutputArray dst, InputArray m)
- int main( )
- {
- Mat img=imread("boy.png");
- int img_height = img.rows;
- int img_width = img.cols;
- vector<Point2f> corners(4);
- corners[0] = Point2f(0,0);
- corners[1] = Point2f(img_width-1,0);
- corners[2] = Point2f(0,img_height-1);
- corners[3] = Point2f(img_width-1,img_height-1);
- vector<Point2f> corners_trans(4);
- corners_trans[0] = Point2f(150,250);
- corners_trans[1] = Point2f(771,0);
- corners_trans[2] = Point2f(0,img_height-1);
- corners_trans[3] = Point2f(650,img_height-1);
- Mat transform = getPerspectiveTransform(corners,corners_trans);
- cout<<transform<<endl;
- vector<Point2f> ponits, points_trans;
- for(int i=0;i<img_height;i++){
- for(int j=0;j<img_width;j++){
- ponits.push_back(Point2f(j,i));
- }
- }
- perspectiveTransform( ponits, points_trans, transform);
- Mat img_trans = Mat::zeros(img_height,img_width,CV_8UC3);
- int count = 0;
- for(int i=0;i<img_height;i++){
- uchar* p = img.ptr<uchar>(i);
- for(int j=0;j<img_width;j++){
- int y = points_trans[count].y;
- int x = points_trans[count].x;
- uchar* t = img_trans.ptr<uchar>(y);
- t[x*3] = p[j*3];
- t[x*3+1] = p[j*3+1];
- t[x*3+2] = p[j*3+2];
- count++;
- }
- }
- imwrite("boy_trans.png",img_trans);
- return 0;
- }
得到变换之后的图片:
0 1
- getPerspectiveTransform函数
- 透视变换warpPerspective和GetPerspectiveTransform函数
- opencv 调用 getPerspectiveTransform 函数报错
- [OpenCv]使用getPerspectiveTransform()函数实现Perspective Effect(透视效果)
- opencv透视变换GetPerspectiveTransform的总结
- 透视变换矩阵(单应矩阵)计算:findHomography 与 getPerspectiveTransform
- 单应矩阵计算 findHomography和getPerspectiveTransform区别
- 【OpenCV3】透视变换——cv::getPerspectiveTransform()与cv::warpPerspective()详解
- 函数
- 函数
- 函数
- 函数
- 函数
- 函数
- 函数
- 函数
- 函数
- 函数
- 【Git分布式版本控制系统】远程仓库Github
- 字典树(Trie树、单词查找树、前缀树)
- 微服务-(1)
- Report (enovia) 开发实践档案——PP Cost Book Report
- Swift学习笔记系列——(24)访问控制
- getPerspectiveTransform函数
- windows下使用libsvm3.2
- 面试中经常让写的关于链表的代码
- Java中的移位运算符
- Opencv的Size类-尺寸类
- [CQOI2013]新数独
- OFM OBIEE Security
- 小议:SharePoint 2013配置Office Web Application时,无法打开文件的解决方案
- Android Activity全屏