OpenCV 2.3.1 with CodeBlocks on Ubuntu 12.04

For Installing OpenCV 2.3.1 on ubuntu 12.04 please refer to previous post
http://opencvlover.blogspot.in/2012/05/install-opencv-231-on-ubuntu-1204.html

Once the installation is done, install codeblocks as mentioned in previous post http://opencvlover.blogspot.in/2011/07/installing-opencv-with-codeblocks-ide.html

Create a new console application as mentioned in above post and go to Build Options.
Make sure that GNU GCC compiler is selected in compiler drop down option.
Go to Linker Settings tab and Link libraries which are located at /usr/local/lib/ and looks like 'libopncv_*.so'
An example is shown in image below


Now go to Search directories and under Compiler tab add following location
/usr/local/include/opencv2
Here is a screenshot


Now we are ready to run OpenCV 2.3.1 on Code Blocks running on Ubuntu 12.04.
Here is a sample code to test the installtion






9 comments:

  1. Hi.. I am getting following errors...
    /home/cpp/img/main.o||In function `main':|
    main.cpp|| undefined reference to `cvNamedWindow'|
    main.cpp|| undefined reference to `cvWaitKey'|
    main.cpp|| undefined reference to `cvDestroyWindow'|
    ||=== Build finished: 3 errors, 0 warnings ===|

    Please tell me what should i do?????

    ReplyDelete
    Replies
    1. Please check your linker setting as mentioned in the post. Which opencv version are you using?

      Delete
    2. I have checked linker settings.. Still its not working..
      I am using OpenCV Version 2.1.0-7...

      Delete
    3. Method mentioned in above blogpost works for opencv 2.3 and higher versions. I would suggest you using opencv 2.3.1 or higher versions as they are latest.
      For opencv 2.1 I guess you will have to soecify few more setting such as include directory etc.

      Delete
  2. Hi... i am new to ubuntu and opencv...
    I followed the above mentioned steps..
    but i am getting following error....

    -------------- Build: Debug in p2 ---------------

    Linking console executable: bin/Debug/p2
    /usr/bin/ld: cannot find -lcv
    /usr/bin/ld: cannot find -lhigui
    /usr/bin/ld: cannot find -lcvaux
    /usr/bin/ld: cannot find -lcv
    /usr/bin/ld: cannot find -lcvaux
    /usr/bin/ld: cannot find -lhigui
    collect2: ld returned 1 exit status
    Process terminated with status 1 (0 minutes, 0 seconds)
    6 errors, 0 warnings

    can anybody tell what is the problem????

    ReplyDelete
    Replies
    1. which opencv version are you using?

      Delete
    2. Hi I am also getting the same error...

      /usr/bin/ld: cannot find -lcv
      /usr/bin/ld: cannot find -lcvaux
      /usr/bin/ld: cannot find -lhigui
      collect2: ld returned 1 exit status

      I am using openCV 2.4.9

      Delete
  3. Hi..
    I am trying to capture image using webcam. When i executed the code its giving me capture as null.
    What could be the problem??
    Please help me.
    Following is the code.

    #include
    #include

    int main( int argc, char** argv )
    {
    cvNamedWindow( "Example", CV_WINDOW_AUTOSIZE );

    CvCapture* capture = cvCaptureFromCAM(0) ;
    IplImage* frame;

    while(1)
    {
    frame = cvQueryFrame( capture );

    if( 1 ) // !frame
    break;
    cvShowImage( "Example", frame );

    char c = cvWaitKey(33);
    if( c == 27 )
    break;

    cvSaveImage("webcam_frame.png",frame);
    }
    cvReleaseCapture( &capture );
    cvWaitKey(0);
    cvDestroyWindow( "Example" );
    }

    ReplyDelete