Friday, July 23, 2010

How to set up OpenCV version 2.2

If you have been using OpenCV all the time by getting the code straight out of the SVN, you may or may not know that it has reach version 2.2 recently. There has been some big changes to version 2.2 and most of your code is likely won't be able to compile. But, fret not, as I'm going to show you how to get back up again.

First of all, if you used to be doing this:
#include <cv.h>
#include <highgui.h>

just change it to:
#include <opencv2/opencv.hpp>


Secondly, if you used to link against:
cv.lib cxcore.lib highgui.lib
or
cv{version}.lib cxcore{version}.lib or highgui{version}.lib


just change it to:
opencv_calib3d220.lib opencv_contrib220.lib opencv_core220.lib opencv_features2d220.lib opencv_ffmpeg220.lib opencv_flann220.lib opencv_gpu220.lib opencv_haartraining_engine.lib opencv_highgui220.lib opencv_imgproc220.lib opencv_legacy220.lib opencv_ml220.lib opencv_objdetect220.lib opencv_video220.lib
(Some of these libs may not be needed if you did not use the features, but I don't think you will get any linking errors if you put it anyway.)


NOTE: as of the latest in the svn, the version is 2.2. Hence the "220" in "opencv_calib3d220.lib". If the version number changes, you may have the update the number accordingly.


Thirdly, in your "Projects and Solutions" "VC++ Directories" Options diaglog box, add this for "Include files":
{Path to your OpenCV SVN root folder}\include
{Path to your OpenCV SVN root folder}\modules\calib3d\include
{Path to your OpenCV SVN root folder}\modules\contrib\include
{Path to your OpenCV SVN root folder}\modules\core\include
{Path to your OpenCV SVN root folder}\modules\features2d\include
{Path to your OpenCV SVN root folder}\modules\ffmpeg
{Path to your OpenCV SVN root folder}\modules\flann\include
{Path to your OpenCV SVN root folder}\modules\gpu\include
{Path to your OpenCV SVN root folder}\modules\haartraining
{Path to your OpenCV SVN root folder}\modules\highgui\include
{Path to your OpenCV SVN root folder}\modules\imgproc\include
{Path to your OpenCV SVN root folder}\modules\legacy\include
{Path to your OpenCV SVN root folder}\modules\ml\include
{Path to your OpenCV SVN root folder}\modules\objdetect\include
{Path to your OpenCV SVN root folder}\modules\python
{Path to your OpenCV SVN root folder}\modules\traincascade
{Path to your OpenCV SVN root folder}\modules\video\include


Thirdly, in your "Projects and Solutions" "VC++ Directories" Options diaglog box, add this for "Library files":
{Path to your OpenCV SVN root folder}\{The name of the folder you created when building with CMake}\lib\{Release or Debug}

That's all that is to it. Good luck!