First download and setup the basics:
- Get MinGW
- Download Eclipse C/C++ IDE
Note: I have a tutorial on these two steps already so just head over HERE for more info.
- Next download/install OpenCV 2.2
- Now launch Eclipse and start a new project by going to:
- File->New->C++ Project (or File->New->C Project)
- Give your project a name in the "Project name" box
- Select the "Hello World" option under the "Project Type" section under the"Executable" folder. I recommend this over the "Empty Project" as it creates the c/c++ file for you instead of having to do it manually (it also creates a "src" folder and a"Debug" folder which helps keep things a little more organized)
- Make sure the "MinGW" Toolchain is selected in the "Toolchains" section
- Hit NEXT
- Fill in your Author and other file information, then hit NEXT
- In the next window select "Advanced settings...". This will bring you to the "Project Settings" which can always be accessed later by going to Project->Properties
- Under the "C/C++ Build" Section go to the "Settings" and select the "Tool Settings"Tab. Then select the "Includes" folder (on older versions of eclipse it is the "Directories" folder) in the GCC Compiler branch and add the opencv include directory to Include paths (-I): "C:\OpenCV2.2\include\". Of course, change C:\OpenCV2.2 to match the installed path that you used.
- Now, under the MinGW Linker select the "Libraries" folder and add the following to the Libraries (-l) section (note not all of these are necessarily needed for your project but these are all the libraries available in opencv version 2.2):
In most cases you will only need opencv_core220 and opencv_highgui220 to get started
NOTE: Versions 2.2 and later postfix the libraries names with a three digit number that corresponds to the version of OpenCV that you are linking to.
FINALLY, under the "Library search path (-L)" section add:
- Hit OK when done
- Hit Finish to create and start the Project
NOTE: The way this guide was written will require you to use a relative path to specify the header files you wish to include. OpenCV breaks up the library into two sections, "legacy libraries" and "new libraries".
If you wish to specify one of the new opencv libraries use the following format:
ADDITIONALLY, if you wish to include all of the primary opencv2 header files in a project you can use:
Note: opencv.hpp does not include every library in OpenCV2.2. It may be helpful for you to view the "opencv.hpp" library (located by default in: C:\OpenCV2.2\include\opencv2\opencv.hpp) to see what is included and how you can reference the new libraries in your code. To see the complete list of libraries available, go to "C:\OpenCV2.2\include\" and browse around the directory.
Legacy libraries can be defined by: #include "opencv\[library.hpp]
If you get an error, during compile time, pertaining to:__exchange_and_add
Then visit this page and follow the instructions under:
Building on Windows using MinGW 3.4.5
Hope this helps!