Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using OpenCV in Java with JavaCV

I am getting desperate !! I am trying to use OpenCV in Java, via JavaCV (JNA to wrap OpenCV for java).

I am on Mac Os X 1.5.

I installed OpenCV, and I can compile and run the examples included. So that works.

Now I open Eclipse, and I create a new project, as described here : http://code.google.com/p/javacv/

In that new project, only one small class with a call to a opencv function (I used the sample code) :

import static name.audet.samuel.javacv.jna.cxcore.*;
import static name.audet.samuel.javacv.jna.cv.*;
import static name.audet.samuel.javacv.jna.highgui.*;
import static name.audet.samuel.javacv.jna.cvaux.*;

public class Test {
    public static void main(String[] args) {
        IplImage image = cvLoadImage("test.png", 1);
        if (image == null) {
            System.err.println("Could not load image file.");
        } else {
            cvSmooth(image, image, CV_GAUSSIAN, 3, 0, 0, 0);
            // ...
        }
    }
}

When I run it, I have the following error :

Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'cxcore': dlopen(libcxcore.dylib, 9): image not found

Please, I need help, I looked over google for hours, I don't know where to look for anymore.

like image 634
Matthieu Napoli Avatar asked Sep 13 '10 23:09

Matthieu Napoli


2 Answers

It turned out the SVN version was not compatible with JavaCV.

I downloaded the latest official version (2.1) and compiled it and installed it, and it works.

See http://code.google.com/p/javacv/issues/detail?id=19

like image 96
Matthieu Napoli Avatar answered Sep 23 '22 12:09

Matthieu Napoli


You need to link these two libraries:

- javacpp.jar
- javacv.jar

In the JavaCV/lib-opencv/win_x86_64 you have to have files of your like:

 - msvcp100.dll
 - msvcr100.dll
 - opencv_core220.dll
 - opencv_calib3d220.dll
 - ...

These DLLs have to be compiled for your platform (win 32 / win 64 / Linux / etc.

You have to define path to your OpneCV DLL files:

-Djava.library.path=lib-opencv/win_x86_64/
- or the DLLs have to be somewhere in your system PATH of your operating system
like image 38
Radim Burget Avatar answered Sep 22 '22 12:09

Radim Burget