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



33 comments:

  1. Saludos muy bueno el artículo. Faltaría la imagen 4.

    ReplyDelete
  2. Anonymous2/2/14 20:22

    great blog mare! thank for your sharing

    ReplyDelete
  3. Thank you very much~!! ^^

    ReplyDelete
  4. The code work well when I stitched using only two of your images, but gave the following errors when used more than 2 image.

    First-chance exception at 0x5baa677a in TEST_CV.exe: 0xC0000005: Access violation reading location 0x00000004.

    First-chance exception at 0x756d9617 in TEST_CV.exe: Microsoft C++ exception: tbb::captured_exception at memory location 0x0012eaf4..

    Unhandled exception at 0x756d9617 in TEST_CV.exe: Microsoft C++ exception: tbb::captured_exception at memory location 0x0012eaf4..

    Please help me in fixing that.

    ReplyDelete
  5. Can you send me the image files? I will test on my computer. Thank you.
    My email is feelmare@gmail.com

    ReplyDelete
  6. Badrullami17/3/14 07:31

    It's great code.... but I have problem with image that captured with fisheye lens.. how to stitch that images? any suggestions?

    ReplyDelete
  7. In my opinion, case of fisheye lens, you should do undistortion processing first.
    refer to this page -> http://www.kscottz.com/fish-eye-lens-dewarping-and-panorama-stiching/

    ReplyDelete
  8. This comment has been removed by the author.

    ReplyDelete
  9. it is great code ,,,, but can you help me how can i stitching video files together ???
    thanks

    ReplyDelete
  10. Real-time video stitching is little bit different with image.
    Big problem is proccesing time is late.
    In order to implementation, Structure must be sperate of online and offline calculation part.

    Please refer to the source code "stitching_detailed.cpp" of Opencv samples

    I made real-time stitching program but I am difficult to share the code.
    Because the source code is owned by my company.

    refer to this video.
    http://www.youtube.com/watch?v=Zkrn-rooj0M
    http://www.youtube.com/watch?v=jP1Y8nd0mQc

    Thank you.

    ReplyDelete
  11. This comment has been removed by the author.

    ReplyDelete
  12. I have used the same code and it is running fine sometimes. But if I run it continuously more than two times, it is crashing.. giving the following error.
    Access violation reading location 0x0000000000000008. and it the cursor is pointing to
    pChore->m_pFunction(pChore); in Chores.cpp file.

    When I ran using 640x480 size images, the application is generating panorama for 2 images and crashing some times for the same set of images. Moreover it is not able to run for more than 2 images.

    Can you please let me know why it is happening like this?

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
    2. hi , i faced same problem .... but when i using small images (320*240) for example , it will be correctly done .

      Delete
  13. it is very informative but is it possible to have this details using python language : my email: mandeepola@ymail.com

    ReplyDelete
  14. This comment has been removed by the author.

    ReplyDelete
  15. Anonymous14/3/16 00:51

    Hi, I have some problems when using the stitcher, maybe you can help me. I guess I'll remit to you personally by mail with the image. Thank you in advance.

    ReplyDelete
    Replies
    1. I test your image
      and upload code to github
      https://github.com/MareArts/Still-Image-Stitching-Test-Using-OpenCV

      Check output.jpg file
      and code

      Thank you.

      Delete
    2. Anonymous15/3/16 00:36

      Thank you for your quick reply. It's strange your code is similar to mine and mine is not working properly. I´m using VS2013 as well, but OpenCV 3.1.0 x64 without Gpu, while you are using OpenCV 2.4.9 with Gpu. Do you know if the reason of my artifacts has to to with any of these three differences?

      Delete
    3. I think default option is different.

      Delete
    4. Anonymous15/3/16 04:18

      Default option looks similar (GraphCutSeamFinder(CostColor), BlocksGainCompensator and MultibandBlender after registration). Could it be due to any change in any of these blocks (probably multiband blender), that is messing up everything in the new version of OpenCV?

      Delete
  16. Anonymous15/4/16 15:17

    Hi, There was a run-time error on my PC. It says, "Unhandled exception at 0x00871BDA (opencv_imgproc2412d.dll) in T3.exe: 0xC000001D: Illegal Instruction." I use VS2012 and opencv2.4.12. Could you please help me?

    ReplyDelete
    Replies
    1. I don't know about this error.
      Please check build option 32bit, 64bit.
      lib build condition. gpu include?
      function usage different in another opencv version?

      Delete
    2. you can try in release type, it will be fine!

      Delete
  17. Anonymous29/4/16 00:10

    i pasted this code in geany editor. compilation error ocured/home/aftab/Pictures/Screenshot from 2016-04-29 00:03:43.png

    ReplyDelete
  18. Hi Mare, thanks for the code. I used your exact code on my machine and fed the same set of input images, but my resulting image wasn't complete like yours. It looks like it did some stitching but not completely. Any ideas what may be wrong? Thanks!

    ReplyDelete
  19. Your code has 6 input images.
    But there are only 5 pictures.
    I tried running the program using your code.
    Pictures 5 and 6 do not appear in the execution window.

    And the input image was replaced with another image. But stitching failed.

    ReplyDelete
    Replies
    1. It is example of Stitcher in OpenCV library.
      It is very simple code, if you input overlap images.
      If a common feature can not be found in the image, stitching may fail.

      Delete
  20. This comment has been removed by the author.

    ReplyDelete
  21. Hi you know any example of stitching but with the opossite perspective.
    Something like this:

    http://www.diga.me.uk/360degreeCamera.html

    My intention to carry out an inspection of labels in metal cans.

    Thanks in advance

    ReplyDelete
  22. Anonymous6/3/17 19:08

    Dear Mare! you're really doing nice job. Please let me know about your platform specification while executing your code for stitching images.
    Hope to hearing from you soon.

    Thanks,
    Abdul Wahab

    ReplyDelete
    Replies
    1. I am using window os, and visuals studio.
      this code is standard code, so opencv version, platform(32/64), cuda version.. is not specification.
      Thank you.

      Delete