透视变换实现代码(全)
来源:互联网 发布:如何升级mac os系统 编辑:程序博客网 时间:2024/05/19 06:34
好久没写博客了,因为白天要去实习,晚上看论文实在抽不出时间,由于项目需要,研究了透视变换,在网上找了一圈不是缺腿就是少胳膊的,后来对缺省的代码进行补充使其可以调通,现贴出来供大家学习使用,代码如下:
#include<iostream>#include<opencv2/highgui/highgui.hpp>#include<opencv2/imgproc/imgproc.hpp>using namespace cv;using namespace std;int main( ) { Mat img=imread("1.jpg"); 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("1_trans.jpg",img_trans); namedWindow("原图");imshow("原图", img);namedWindow("透视变换图");imshow("透视变换图", img_trans);waitKey(0); return 0; }原图:
透视变换之后的效果图:
阅读全文
0 0
- 透视变换实现代码(全)
- 逆透视变换详解 及 代码实现(一)
- 逆透视变换详解 及 代码实现(二)
- 逆透视变换详解 及 代码实现
- 图像的透视变换(opencv2实现)
- matlab中的透视变换代码
- GLSL 透视变换(着色器实现C语言)
- 透视变换(Perspective Transformation)
- ps进行透视变换(扭曲变换)
- 透视、仿射变换的代码
- opencv 实现任意角度的透视变换
- 透视变换
- 透视变换
- 透视变换
- 透视变换
- 透视变换
- 【OpenCV】透视变换 Perspective Transformation(续)
- OpenCV入门(十七)-- 透视变换
- 函数
- Shiro入门学习二
- 大数据-时下已经大火的技术
- [NOIP模拟][规律探究]弹球
- 判断字符串是否是回文
- 透视变换实现代码(全)
- linux每天一命令: chmod 修改档案权限
- 数据结构 折半查找法(算法思想和源代码)
- [NOIP模拟][匈牙利算法][费用流]放盒子
- CentOS7 yum源 快速转 阿里云
- 电脑怎么进入BIOS界面
- ImageNet Classification with Deep Convolutional Neural Networks
- (M)Backtracking:40. Combination Sum II
- NOIP模拟:Box(费用流)