Ninetynine is a creative design & coding agency

Setting up OpenCV 2.3 and Netbeans 7.0 on Ubuntu Oneiric 11.10

with 4 comments


I don’t like Eclipse. There, I said it. However, in the past Netbeans and C/C++ didn’t play along. Since I upgraded to Ubuntu 11.10, I decided to give it another go, and the results are pleasing! As there was no install guide available online for my situation, I decided to summarize the steps I used in order to get things running.
 

OpenCV (Open Source Computer Vision Library) is a library of programming functions mainly aimed at real time computer vision, developed by Intel and now supported by Willow Garage. It is free for use under the open source BSD license. The library is cross-platform. It focuses mainly on real-time image processing.

 

1. Installation of OpenCV 2.3

First of all, Ubuntu 11.10 comes with OpenCV 2.1, and I wanted 2.3. Luckely our friend Gijs Molenaar provides us with a PPA for OpenCV 2.3.

$ sudo add-apt-repository ppa:gijzelaar/cuda
$ sudo add-apt-repository ppa:gijzelaar/opencv2.3
$ sudo apt-get update
$ sudo apt-get install libopencv-dev

(Little notice: the package that comes with Ubuntu 11.10 is called libcv-dev, however in the PPA of Gijs the package is called libopencv-dev)

You might also want to install other packages related to OpenCV, just search for them in the Ubuntu Software Center. However, libopencv-dev will do.

2. Installation of Netbeans 7.0

Ubuntu 11.10 also comes with Netbeans 6.9, just download the new version from http://netbeans.org and you’re all set. Be sure you download the version with C/C++ support.

3. Set the project properties

Then create a new C/C++ project in Netbeans 7.0. First, set the project properties correctly. These settings worked for me.

In the C++ Compiler dialog add “/usr/locale/opencv2″ to the “Include Directories” field, also do this in the Linker dialog. In the Linker Dialog, also add the libraries opencv_core and opencv_highgui. You can find these libraries directly under “/usr/lib/”.

4. Set the includes

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>

I find it easy to work with the cv and std namespace by default, so I don’t have to type “cv::” before every function.

using namespace cv;
using namespace std;

And if we put this all together in to a little program that shows an image, you have something like this:

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
 
int main(int argc, char *argv[]) {
 
    Mat image;
    image = imread(argv[1], CV_LOAD_IMAGE_COLOR);
 
    if (!image.data) // Check for invalid input
    {
        cout &lt;&lt; "Could not open or find the image" &lt;&lt; endl;
        return -1;
    }
 
    namedWindow("Display window", CV_WINDOW_AUTOSIZE); // Create a window for display.
    imshow("Display window", image);
 
    return 0;
}

There we go: Our first OpenCV program in Netbeans! I hope this will work for you too ;)

Share and Enjoy:
  • Print
  • Digg
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Yahoo! Buzz
  • Twitter
  • Google Bookmarks

Written by ruben

November 26th, 2011 at 1:47 pm

4 Responses to 'Setting up OpenCV 2.3 and Netbeans 7.0 on Ubuntu Oneiric 11.10'

Subscribe to comments with RSS or TrackBack to 'Setting up OpenCV 2.3 and Netbeans 7.0 on Ubuntu Oneiric 11.10'.

  1. Thank you very much.
    In my case, I had to add the opencv_imgproc library as well. Otherwise it doesn’t work.

    AimingHigh

    6 Dec 11 at 15:38

  2. A couple of days ago, the PPA was updated to OpenCV 2.3.1

    It’s better to first purge libopencv-dev and all opencv packages before upgrading.

    Also, I’m not quite sure which command is best to install opencv. Gijzelaar’s launchpad says

    sudo apt-get install libcv-dev

    But I got better results using

    sudo apt-get install libopencv-dev

    Try it out

    ruben

    7 Jan 12 at 22:03

  3. UPDATE!

    I wrote a follow-up article for OpenCV 2.3.1 and Netbeans 7.1, regarding the recent updates in Gijzelaar’s PPA: http://ninetynine.be/blog/2012/01/setting-up-opencv-2-3-1-and-netbeans-7-1-on-ubuntu-oneiric-11-10/

    ruben

    8 Jan 12 at 00:45

  4. Thank you very much! It was very usefulll !

    Hugo Barros

    17 May 12 at 19:23

Leave a Reply

Do NOT fill this !

Spam protection by WP Captcha-Free