1 #include"opencv2/highgui/highgui.hpp" 2 #include"opencv2/imgproc/imgproc.hpp" 3 #include<iostream> 4 #include<time.h> 5 6 int main() 7 { 8 Mat img = imread("frame1.jpg", 0);//左图像 9 Mat img1 = imread("frame2.jpg", 0);//右图像 10 imshow("源图像-左", img); 11 imshow("源图像-右", img1); 12 double t = (double)getTickCount(); 13 //柱形投影 14 double t3 = (double)getTickCount(); 15 img = cylinder(img,1000); 16 img1 = cylinder(img1, 1000); 17 t3 = ((double)getTickCount() - t3) / getTickFrequency(); 18 //匹配 19 double t1 = (double)getTickCount(); 20 Point2i a = getOffset(img, img1); 21 t1 = ((double)getTickCount() - t1) / getTickFrequency(); 22 //拼接 23 double t2 = (double)getTickCount(); 24 Mat stitch = linearStitch(img, img1, a); 25 t2 = ((double)getTickCount() - t2) / getTickFrequency(); 26 t = ((double)getTickCount() - t) / getTickFrequency(); 27 28 cout << "各阶段耗时:"<< endl; 29 cout << "柱面投影:" << t3 << ‘\n‘ << "模板匹配:" << t1 << ‘\n‘ << "渐入渐出拼接:" << t2 << endl; 30 cout << "总时间:" << t << endl; 31 32 imshow("柱面校正-左图像", img); 33 imshow("柱面校正-右图像", img1); 34 imshow("拼接结果", stitch); 35 imwrite("rectify.jpg", img); 36 imwrite("rectify1.jpg", img1); 37 imwrite("stitch.jpg", stitch); 38 waitKey(0); 39 return 0; 40 }
原文:https://www.cnblogs.com/smsm/p/14619409.html