Click here to read about installation in windows
This tutorial is meant for the Linux users who wants too configure OpenCV in Codeblocks platform. I assume that you have already installed codeblocks from the Software Centre or by extracting and making using the Makefile. You can download Code Blocks from the following link.
After properly setting up Visual Studio in your computer, The next step is to download OpenCV from the sourceforge site. Its always recommended to download the latest stable release. The beta versions may be under development and so you may download those versions only under your risk.
Now follow the link given below to download openCV for Windows.Download OpenCV
After having downloaded the tarball file(tar.gz file), untar it. I am making an assumption that the OpenCV tarball name is opencv-2.4.6.tar.gz, and that my tarball is in the Desktop.In order to untar the file open terminal and navigate to the Desktop and use the tar command
The extraction will take quite a while to complete. Once completed, you may go to the installation directory and make sure that it looks something like this. For that type ls in the terminal. You must see something like this.
Before making opencv, we have to ensure that all the necessary libraries and softwares have been installed. For that run the following command in the terminal.
remove any library or software which is creating problem in the above step.Now recheck whether you are in the Opencv-2.4.6 folder.Now we have to create a folder named “release”.
Now build the OpenCV using the following command.
Now make and install OpenCV using the following commands.
This step will take quite a long time to complete. Its better to ensure that you keep your laptop plugged while making OpenCV.
Now we have to add the library path of OpenCV to linux. Inorder to do that follow these commands:
Add the following line to the file, save and close it.
Now run the following command to complete the installation.
Inorder to check whether the opencv has been properly installed, you can type in the following in the terminal:
You must get an output looking sompething like this:
Once you have ensured that the OpenCV has been properly installed in your system, the next step is to integrate it into an IDE. In this tutorial I am using Code Blocks but it also works for any other IDE. I prefer IDE because the auto complete option makes coding simplified.
Now open CodeBlocks. I am using CodeBlocks 12.11.
Now go to settings –>compiler
Under the compiler settings tab select the other options tab and copy the following command into the pane.Make sure that you are not using the apostrophe but the symbol just next to the number 1 on your keyboard.
`pkg-config opencv –cflags`
Now open the Linker Settings Tab and copy the following command int the other linker options pane:
`pkg-config opencv –libs`
Now open the search directories tab and add the following locations :
Click OK to save the settings.
The last step is to enable autocomplete feature of CodeBlocks. Auto complete is a helpful feature of Code Blocks, as we dont have to remember the numerous functions and its parameters when coding in OpenCV.
Now Inorder to enable auto complete open the editor options from the settings menu. and make the selections as shown below:
Test your installation
Now Inorder to test whether the installation was proper, you may copy the following code to your project either in Visual Studio in the case of windows or CodeBlocks in the case of Linux. Build and run the code.