【opencv】鱼眼图像畸变校正

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

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


原图


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

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


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

透视变换


透视变换代码 opencv2.4.9+vs2012

[cpp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. int main(int argc,char** argv)  
  2. {  
  3.     CvPoint2D32f pts_src[4], pts_dst[4];  
  4.     CvMat *warp_matrix;  
  5.     IplImage *src, *dst;  
  6.     int offset_x, offset_y;  
  7.   
  8.     src = cvLoadImage("correct_Img_1.jpg",1);  
  9.     dst = cvCreateImage( cvGetSize(src), src->depth, src->nChannels);  
  10.       
  11.     //映射关系 (310,281)->(300,200)      (193,14)->(300,50)           (928,14)->(800,50)       (744,281)->(800,200)  
  12.     offset_x = 100;//为正,横向拉伸,为负,横向压缩  
  13.     offset_y = 0;//为正,纵向拉伸,为负,纵向压缩  
  14.   
  15.     pts_src[0].x = 310;  
  16.     pts_src[0].y = 281;  
  17.     pts_src[1].x = 193;  
  18.     pts_src[1].y = 14;  
  19.     pts_src[2].x = 928;  
  20.     pts_src[2].y = 14;  
  21.     pts_src[3].x = 744;  
  22.     pts_src[3].y = 281;  
  23.   
  24.     pts_dst[0].x = 300-offset_x;  
  25.     pts_dst[0].y = 200+offset_y;  
  26.     pts_dst[1].x = 300-offset_x;  
  27.     pts_dst[1].y = 50-offset_y;  
  28.     pts_dst[2].x = 800+offset_x;  
  29.     pts_dst[2].y = 50-offset_y;  
  30.     pts_dst[3].x = 800+offset_x;  
  31.     pts_dst[3].y = 200+offset_y;  
  32.   
  33.     warp_matrix = cvCreateMat(3,3,CV_32FC1);  
  34.   
  35.     //计算变换矩阵  
  36.     cvGetPerspectiveTransform( pts_src, pts_dst ,warp_matrix);  
  37.     //透视变换  
  38.     cvWarpPerspective( src, dst ,warp_matrix);  
  39.   
  40.     cvNamedWindow("dst",1);  
  41.     cvShowImage("dst",dst);  
  42.     cvSaveImage("out.jpg",dst);  
  43.   
  44.     cvWaitKey(0);  
  45.   
  46.     cvReleaseImage(&dst);  
  47.     cvDestroyWindow("dst");  
  48.   
  49.     return 0;  
  50. }  
  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值