C语言中OpenCV怎样实现柱面投影(c语言,opencv,开发技术)

时间:2024-05-04 10:05:55 作者 : 石家庄SEO 分类 : 开发技术
  • TAG :

前言

在做全景拼接的时候,为了保持图片中的空间约束与视觉的一致性,需要进行柱面投影,否则离中心图像距离越远的图像拼接后变形越大。

柱面投影公式为

C语言中OpenCV怎样实现柱面投影

实现代码

针对彩色图像

intmain(){ cv::Matimage1=cv::imread("images/1.jpg",1); if(!image1.data) return0; imshow("image1",image1); MatimgOut=Mat(image1.rows,image1.cols,CV_8UC3); floatw=image1.cols; floath=image1.rows; floatf=(w/2)/atan(PI/8); for(inti=0;i<image1.rows;i++) { for(intj=0;j<image1.cols;j++) { floatx=j; floaty=i; floatx1=f*atan((x-w/2)/f)+f*atan(w/(2.0f*f)); floaty1=f*(y-h/2.0f)/sqrt((x-w/2.0f)*(x-w/2.0f)+f*f)+h/2.0f; intcol=(int)(x1+0.5f);//加0.5是为了四舍五入 introw=(int)(y1+0.5f);//加0.5是为了四舍五入 if(col<image1.cols&&row<image1.rows) { imgOut.at<Vec3b>(row,col)[0]=image1.at<Vec3b>(i,j)[0]; imgOut.at<Vec3b>(row,col)[1]=image1.at<Vec3b>(i,j)[1]; imgOut.at<Vec3b>(row,col)[2]=image1.at<Vec3b>(i,j)[2]; } } } imshow("imgOut",imgOut); waitKey(0); return0;}

实现效果

C语言中OpenCV怎样实现柱面投影

C语言中OpenCV怎样实现柱面投影

针对灰度图像

cv::Matimage1=cv::imread("E:\\zcb_work\\2113\\pic2\\k.jpg",0); if(!image1.data) return0; imshow("image1",image1); cv::Matimage2=cv::imread("E:\\zcb_work\\2113\\pic2\\j.jpg",0); if(!image2.data) return0; imshow("image2",image2); MatimgOut1=Mat(image1.rows,image1.cols,CV_8UC1); imgOut1.setTo(0); MatimgOut2=Mat(image2.rows,image2.cols,CV_8UC1); imgOut2.setTo(0); floatw=image1.cols; floath=image1.rows; floatf=(w/2)/atan(PI/8); for(inti=0;i<image1.rows;i++) { for(intj=0;j<image1.cols;j++) { floatx=j; floaty=i; floatx1=f*atan((x-w/2)/f)+f*atan(w/(2.0f*f)); floaty1=f*(y-h/2.0f)/sqrt((x-w/2.0f)*(x-w/2.0f)+f*f)+h/2.0f; intcol=(int)(x1+0.5f);//加0.5是为了四舍五入 introw=(int)(y1+0.5f);//加0.5是为了四舍五入 if(col<image1.cols&&row<image1.rows) { imgOut1.at<uchar>(row,col)=image1.at<uchar>(i,j); imgOut2.at<uchar>(row,col)=image2.at<uchar>(i,j); //imgOut.at<Vec3b>(row,col)[1]=image1.at<Vec3b>(i,j)[1]; //imgOut.at<Vec3b>(row,col)[2]=image1.at<Vec3b>(i,j)[2]; } } } imshow("imgOut1",imgOut1); imshow("imgOut2",imgOut2);

实现效果

原图

C语言中OpenCV怎样实现柱面投影

柱面投影

C语言中OpenCV怎样实现柱面投影

用surf算法,特征检测,

C语言中OpenCV怎样实现柱面投影

合成这样,呵呵呵,

C语言中OpenCV怎样实现柱面投影

 </div> <div class="zixun-tj-product adv-bottom"></div> </div> </div> <div class="prve-next-news">
本文:C语言中OpenCV怎样实现柱面投影的详细内容,希望对您有所帮助,信息来源于网络。
上一篇:Silverlight 4.0新增功能有哪些下一篇:

5 人围观 / 0 条评论 ↓快速评论↓

(必须)

(必须,保密)

阿狸1 阿狸2 阿狸3 阿狸4 阿狸5 阿狸6 阿狸7 阿狸8 阿狸9 阿狸10 阿狸11 阿狸12 阿狸13 阿狸14 阿狸15 阿狸16 阿狸17 阿狸18