11/20/2013

OpenCV Stitching example (Stitcher class, Panorama)

Image size of origin is 320*240. 






Processing time is 30.96 second took.

    The result of stitching

The result is pretty good. but, processing time is too much takes.

My computer spec is that.. (This is vmware system. The main system is mac book air 2013, i7 8bg)


The source code is very easy.
I think if we use stitching algorithm in realtime, we should be programing by GPU.

/////
#include < stdio.h >  
#include < opencv2\opencv.hpp >  
#include < opencv2\stitching\stitcher.hpp >

#ifdef _DEBUG  
#pragma comment(lib, "opencv_core246d.lib")   
#pragma comment(lib, "opencv_imgproc246d.lib")   //MAT processing  
#pragma comment(lib, "opencv_highgui246d.lib")  
#pragma comment(lib, "opencv_stitching246d.lib");

#else  
#pragma comment(lib, "opencv_core246.lib")  
#pragma comment(lib, "opencv_imgproc246.lib")  
#pragma comment(lib, "opencv_highgui246.lib")  
#pragma comment(lib, "opencv_stitching246.lib");
#endif  

using namespace cv;  
using namespace std;


void main()  
{
 vector< Mat > vImg;
 Mat rImg;

 vImg.push_back( imread("./stitching_img/S1.jpg") );
 vImg.push_back( imread("./stitching_img/S2.jpg") );
 vImg.push_back( imread("./stitching_img/S3.jpg") );
 vImg.push_back( imread("./stitching_img/S4.jpg") );
 vImg.push_back( imread("./stitching_img/S5.jpg") );
 vImg.push_back( imread("./stitching_img/S6.jpg") );
  

 Stitcher stitcher = Stitcher::createDefault();


 unsigned long AAtime=0, BBtime=0; //check processing time
 AAtime = getTickCount(); //check processing time

 Stitcher::Status status = stitcher.stitch(vImg, rImg);

 BBtime = getTickCount(); //check processing time 
 printf("%.2lf sec \n",  (BBtime - AAtime)/getTickFrequency() ); //check processing time

 if (Stitcher::OK == status) 
  imshow("Stitching Result",rImg);
  else
  printf("Stitching fail.");

 waitKey(0);

}  
/////

github
https://github.com/MareArts/Still-Image-Stitching-Test-Using-OpenCV

N image, realtime stitching.
source code:
http://study.marearts.com/2016/10/real-time-n-camera-stitching-class.html
how to work:
http://study.marearts.com/2015/02/real-time-stitching-multi-video-to-one.html

2 image stitching.
basic principal on vidoe(code and explanation):
http://study.marearts.com/2013/10/two-view-of-cam-to-one-screen-using.html
basic principal on image(code and explanation):
http://study.marearts.com/2011/08/two-image-mosaic-paranoma-based-on-sift.html