首页 > 学院 > 开发设计 > 正文

【opencv】鱼眼图像畸变校正——透视变换

2019-11-06 09:41:25
字体:
来源:转载
供稿:网友

http://blog.csdn.net/QQ_15947787/article/details/50786782

http://blog.csdn.net/qq61394323/article/details/37812561

http://blog.csdn.net/qq_15947787/article/details/51441128

原图

球面透视投影(以空间左手坐标系,x轴为水平,y为竖直,z为光轴,投影面法线与xoz面夹角55度)

经过球面透视投影后,会存在两个灭点,此时,需要消去由于球面透视投影面存在角度引入的灭点。在这里采用opencv的仿射变换。

选取两条直线上的四个点,这两条直线相交与要消除的灭点。给出四个点校正后的位置。求变换矩阵。

透视变换

透视变换代码 opencv2.4.9+vs2012

[cpp] view plain copy 在CODE上查看代码片int main(int argc,char** argv)  {      CvPoint2D32f pts_src[4], pts_dst[4];      CvMat *warp_matrix;      iplImage *src, *dst;      int offset_x, offset_y;        src = cvLoadImage("correct_Img_1.jpg",1);      dst = cvCreateImage( cvGetSize(src), src->depth, src->nChannels);            //映射关系 (310,281)->(300,200)      (193,14)->(300,50)           (928,14)->(800,50)       (744,281)->(800,200)      offset_x = 100;//为正,横向拉伸,为负,横向压缩      offset_y = 0;//为正,纵向拉伸,为负,纵向压缩        pts_src[0].x = 310;      pts_src[0].y = 281;      pts_src[1].x = 193;      pts_src[1].y = 14;      pts_src[2].x = 928;      pts_src[2].y = 14;      pts_src[3].x = 744;      pts_src[3].y = 281;        pts_dst[0].x = 300-offset_x;      pts_dst[0].y = 200+offset_y;      pts_dst[1].x = 300-offset_x;      pts_dst[1].y = 50-offset_y;      pts_dst[2].x = 800+offset_x;      pts_dst[2].y = 50-offset_y;      pts_dst[3].x = 800+offset_x;      pts_dst[3].y = 200+offset_y;        warp_matrix = cvCreateMat(3,3,CV_32FC1);        //计算变换矩阵      cvGetPerspectiveTransform( pts_src, pts_dst ,warp_matrix);      //透视变换      cvWarpPerspective( src, dst ,warp_matrix);        cvNamedWindow("dst",1);      cvShowImage("dst",dst);      cvSaveImage("out.jpg",dst);        cvWaitKey(0);        cvReleaseImage(&dst);      cvDestroyWindow("dst");        return 0;  }  
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表