Installing OpenCV with CodeBlocks IDE on Ubuntu





EDIT: It was reported by some users that this method no longer works. I will post updated version for installation process shortly.


While using OpenCV on Linux I prefer using IDE as you can easily manage code and files when you are working on significantly bigger project. Following are the steps to configure CodeBlocks IDE on Ubuntu for OpenCV. I will be using opencv2.2 and CodeBlocks 10.5 in this post.

For OpenCV 2.3.1 with CodeBlocks on Ubuntu, refer to recent post
http://opencvlover.blogspot.in/2012/06/opencv-231-with-codeblocks-on-ubuntu.html

Installing CodeBlocks IDE and OpenCV

You can install both CodeBlocks and OpenCV using Synaptic package manager in ubuntu or just type following command in terminal

  • for CodeBlocks:
  • sudo apt-get install codeblocks
    
  • for Opencv:
  •  
    sudo apt-get install libcv1 libcvaux1 libcvaux-dev libcv-dev libhighgui1 libhighgui-dev opencv-doc
    
For OpenCV 2.3.1 Installation please refer to recent post
http://opencvlover.blogspot.in/2012/05/install-opencv-231-on-ubuntu-1204.html

Create CodeBlocks c++ project

Create codeblocks project from File > New > Project. A new project dialog will be opened. In project type select Console Application. Select Next. Now it will prompt you to name your project and select location for project files. Make sure to use GNU GCC compiler when prompted. Now your project creation in complete and you should see the codeblocks window as shown in below pic.



Cofiguring CodeBlocks for OpenCV

Now in menu bar go to Project > Build options. Under Linker tab, add "-lm -lcv -lhighgui -lcvaux"(without quotes) parameters in Other linker options. It should look like following pic.





Now, under Search Directories tab, put the location of your opencv include folder. If you have installed opencv using synaptic package manager or apt-get then most probably it should be /usr/include/opencv/. If codeblocks asks for keeping this directory as a relative path then hit Yes.
It should look like following pic.


Now we are done with the setup. We will check our setup now.
Just build and run the following code. It will create a window named Hello and window will disappear upon hitting ESC.

Code:

#include <iostream>
#include <cv.h>
#include <highgui.h>
using namespace std;

int main()
{
    cvNamedWindow("Hello", 1);
    cvWaitKey(0);
    cvDestroyWindow("Hello");
    return 0;
}




19 comments:

  1. which library shall i use for making image processing program?

    ReplyDelete
  2. why I can't build that code. error said cannot find -lvc -lhighgui.. need help. thanks :)

    ReplyDelete
  3. Replies
    1. do it from here worked for me
      http://www.technical-recipes.com/2014/using-opencv-in-codeblocks-in-linux/

      Delete