How to Setup OpenCV for code :: block in Linux and Windows?

There are a lot of question asking how to setup the code::block for working with the OpenCV library.
And this is the tutorial...
Keep reading folks..
:)

Linux and Windows First Steps
1. Download the code :: block binary. (http://www.codeblocks.org/downloads/binaries)
2. Install the downloaded binary file.
3. After you have successfully install the code :: block, you will have a working window like this one.



4. Then, download the OpenCV library. (Win: http://sourceforge.net/projects/opencvlibrary/files/opencv-win/2.3.1/ , Linux : http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.3.1/
5. After you have downloaded the OpenCV library, read the wiki how to install it on your machine. (http://opencv.willowgarage.com/wiki/InstallGuide)

Now, that you have already installed the code :: block and the OpenCV library, then you have to setup the OpenCV in the code :: block so we can use the OpenCV library for our programming activity later.

A. Windows Next Steps (Skip to section B. if you use Linux)
6. Before you create a new project, let set the OpenCV library first. Okay, go to the Compiler and Debugger option (Settings -> Compiler and Debugger...)

7. A new dialog window appears, select the linker setting tab. Then click the "add" button, browse the OpenCV library by clicking "..." button, select all the OpenCV library in your OpenCV installation folder (in my case it's C:\Users\hxr99\Downloads\opencv\build\x86\mingw\bin\*). Click Open then OK to apply the OpenCV library in your code :: block.
8. Done with the linker setting, now go to the Search Directories tab. Focus on the Compiler tab first, then click the "Add" button, browse the include library with the "..." button, then select the opencv and opencv2 folder in your OpenCV installation folder to add them to the code :: block (in my case it's C:\Users\hxr99\Downloads\opencv\build\include, C:\Users\hxr99\Downloads\opencv\build\include\opencv, and C:\Users\hxr99\Downloads\opencv\build\include\opencv2).

9. Then, focus on the linker tab next to the compiler tab, then click the "Add" button and locate the bin and lib folder in your OpenCV installation folder (in my case is C:\Users\hxr99\Downloads\opencv\build\x86\mingw\lib and C:\Users\hxr99\Downloads\opencv\build\x86\mingw\bin).

10. After you have finished all the setting, apply the setting with the "OK" button.

B. Linux Next Steps
6. First, locate the OpenCV installation folder by typing this command in your terminal:
pkg-config --libs --cflags opencv
then your command will return the installation folder of the OpenCV.
(Example: -L/usr/local/lib -I/usr/local/include/opencv)

7. After you already locate the opencv installation folder, just follow the steps in the A section above, change the windows folder with the current linux folder showed by the pkg-config command.

Okay, now you have already done with the OpenCV setting in the code :: block, in my next post, I will give you a few samples in OpenCV tutorials. So, what are you waiting for, start programming and keep reading my post.

Btw, thank you for visiting my blog.. :)

1 comment:

  1. Thank you! Now my easy opencv project is compiled successfully without errors like "undefined reference to `cv::"!

    ReplyDelete