Thursday, May 23, 2013

OpenCV setup for Mac

Homebrew makes setup easy.

This is for OSX 10.7+:
1) Install the latest XCode and its command line tools (must install separately).
2) Install homebrew
$ ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
$ brew doctor
- make any fixes the doctor recommends
$ brew tap hombrew/science
- this gives you access to a group of science-related brew formulas
$ brew install opencv
- will probably install the latest mac-compatible OpenCV; as of this writing, the OpenCV version was 2.4.5

In XCode, if you set the correct Additional Library and Header paths in Build Settings, but still get linker errors when you try to compile OpenCV C++ code, in Build Settings edit the Standard C++ library to choose libstdc++ (GNU C++ standard library) instead.

Thursday, May 9, 2013

Automatic panorama

Coded in OpenCV 2.4.2 and C++. I initially tried to use OpenCV's Python wrapper, but the documentation was quite bad. So it was C++ instead, which was pretty fun. Like, in Python I'd just think of sticking an ArgumentParser for command line arguments, but in C++ it felt natural to write a recursive option parser. I decided not to use Matlab because (1) I don't have it on my laptop, (2) I wanted something I could play with later, or use easily.

The human eye naturally recognizes the relationship of points in two photographs. First I did manual landmarking (user clicks pairs of interesting points on the two images he/ she wants to stitch). To mosaic more than one image, do manual consecutive mapping for better results (the order that you put images together is important).

Automating manual clicking

Then with feature detector and extractors, I obtained descriptors of landmarks, and matched them. This was all done with the OpenCV library. However, it's findHomography function, where it finds the projective transformation from image 1's coordinate system to the other, was not very good. For non-planar surfaces, they would fail immediately.

So instead of using that, I implemented my own outlier/ inlier algorithms. It was really quite easy, but with some inaccuracies. It was also slower.