How to set up ROS with opencv2 nonfree package

We are talking about ROS environment in Ubuntu 14.04 LTS.

Since opencv 2.x, ROS does not include the OpenCV libraries as native, but as a third party package. This impacts on ROS usage in many ways, one of them being the tricky aspect of /nonfree (and /viz) packages.

What the heck is the /nonfree package? It is a compilation of very interesting and powerful feature detectors for computer vision, mainly SIFT and SURF.

When I installed ROS, somehow, i missed the /nonfree package. How to tell? Go to /usr/include/opencv2 and inspect the directory. If /nonfree (or /viz) dir is missing, than you may want to install them as well.

Unfortunately, those packages are not stored as binaries on the principal ROS reporitory. Indeed, you can find them on github here: Fortunately, as someone as pointed out on StackOverflow, there’s a PPA (Personal Package Archive) you can use. So, run the following:

sudo add-apt-repository --yes ppa:xqms/opencv-nonfree
sudo apt-get update
sudo apt-get install libopencv-nonfree-dev

I have tested it and in few minutes the /nonfree package will be availabe to you.

You may want to test it for the /viz package as well and perhaps let me know? Also, this is probably not the only method and is not an exhaustive discussion on the matter. If you’d like to contribute, drop a line below.


edit: Some more thoughts

Core functions of OpenCV are affected by the presence of the /nonfree package. For instance, have a look to the src of stitcher.cpp, you’ll notice that is a feature-based stitching creator that uses ORB feature finder for default, but uses SURF if the /nonfree package is installed. Downfalls are also in matcher.cpp (and I guess elsewhere as well, but I did not read all the src code).