Ninetynine is a creative design & coding agency

Setting up OpenCV 2.3.1 and Netbeans 7.1 on Ubuntu Oneiric 11.10

with one comment

Hi there,

This is a follow-up of my previous post: Setting up OpenCV 2.3 and Netbeans 7.0 on Ubuntu Oneiric 11.10. A couple of days ago Gijzelaar’s PPA for OpenCV has updated from 2.3 to version 2.3.1. So I thought I’d share this with you guys. I also think this is a slightly better approach

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. (Wikipedia)

The upgrade did leave my machine with some broken packages, so be cautious! I managed to fix the broken packages, but that’s another story and it probably was a rare case.

Okay, so here is a quick guide:

1. Installation of OpenCV 2.3.1

Launch a terminal and execute these commands. This adds the PPA of our friend Gijs Molenaar, which now contains OpenCV 2.3.1.

$ 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

2. Installation of Netbeans 7.1

Ubuntu 11.10 also comes with Netbeans 6.9, just download the Netbeans 7.1 from the Netbeans Homepage and you’re all set. Be sure you download the version with C/C++ support.

3. Set the project properties

Create a new C/C++ project in Netbeans 7.1. 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.

In the Linker Dialog, Click on the “…” button for Libraries, a new Dialog appears, choose “Add PkgConfig Library…”. Search for “opencv” and add it.

This should add the following library expression

`pkg-config --libs opencv`

(Note that this is a better solution than in my previous post)

4. Set the includes

Note: this has also changed since my previous post!

#include "opencv2/highgui/highgui.hpp"
#include "opencv2/core/core.hpp" 
#include "opencv2/imgproc/imgproc.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 re-use our previous example (yea, I’m lazy), a little program that shows an image, you have something like this:

#include "opencv2/highgui/highgui.hpp"
#include "opencv2/core/core.hpp" 
#include "opencv2/imgproc/imgproc.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 << "Could not open or find the image" << endl;
        return -1;
    }
 
    namedWindow("Display window", CV_WINDOW_AUTOSIZE); // Create a window for display.
    imshow("Display window", image);
 
    return 0;
}

OpenCV has really poor/decentralized documentation, which makes these simple things over-complicated. I hope this helps some people struggling with getting OpenCV to work. Let me know if it works!

Cheers!
Ruben Verhack

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

Written by ruben

January 8th, 2012 at 12:05 am