Friday, September 2, 2016

Image Stitching with OpenCV 3.1.0

With OpenCV, stitching images to make a panorama is very easy. I will go over how to create a beautiful panorama image using OpenCV 3.1.0. Because there is a bug in OpenCV 3.1.0 Stitcher class when OpenCL is enabled, we will need to turn it off when building.

To build OpenCV 3.1.0 from source files, download it first from here or run$ wget https://github.com/Itseez/opencv/archive/3.1.0.zip

After some time, the build should end successfully. Let's test stitch function out. It turns out that there is an example code in the source:$ vim ../samples/cpp/stitching.cpp$ vim ../samples/cpp/stitching_detailed.cpp

Actually, we just built this example file, and its executable is located in build/bin directory$ cd bin/$ ls cpp-example-stitching*

You may want to download the files from here. If successful, the resultant panorama image files should have been produced$ eog result.jpg

For Mac OS X, run$ open -a Preview result.jpg

You may also want to run other OpenCV test and example files in the bin folder. To run tests, you will need to copy OpenCV extra data and set OPENCV_TEST_DATA_PATH variable:$ git clone git://github.com/Itseez/opencv_extra.git$ export OPENCV_TEST_DATA_PATH=`pwd`/opencv_extra/testdata

Now, you can run test files:./opencv_test_stitching

Finally, to install it on the system, one needs to run$ sudo make install