11

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.

7
  • @Matthieu: OSX users sometimes have a library compatibility issue between 32-bit or 64-bit VM. Can you try by the -d32 option as VM argument in starting Eclipse launch configuration Commented Sep 14, 2010 at 6:18
  • 1
    I added the code (this is the sample code from JavaCV). I tried the "-d32" argument, and I get the following error : "Cannot run Java in 32 bit mode. Continuing in 64 bit mode." Maybe it is that ? Commented Sep 14, 2010 at 10:54
  • @Matthieu: Could be. See code.google.com/p/javacv/issues/detail?id=12#c11. As your Eclipse is in 64 bit mode, you need to confirm you're using the 64-bit OpenCV version. Commented Sep 14, 2010 at 12:18
  • Yes but I explicitely compiled openCV in 32bits because my architecture is 32 bits (well I am fairly certain of that ! I have a macbook bought in 2009, the cheapest one). So I don't understand why Eclipse is in 64 bits ? Is there a way to know if my Mac is 32 ou 64 bits ? Commented Sep 14, 2010 at 12:42
  • @Matthieu: try stata.com/support/faqs/win/64bit.html Commented Sep 14, 2010 at 12:51

3 Answers 3

5

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

Sign up to request clarification or add additional context in comments.

2 Comments

for a simpler implementation also have a look here: ubaa.net/shared/processing/opencv
Well well well it turns out that 2.1 release doesn't work (at least on my machine with OS X 10.5), but the SVN works in C++ programs. But the 2.1 is compatible with JavaCV, and not the SVN version. So for me now, OpenCV can work, but not JavaCV.
1

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

Comments

0

I had looked at this problem for a while, as the OP suggests all kinds of problems start crawling out of the woodwork. I went through a ton of StackOverflow posts to be able to come up with a relatively painless experience for setting up a OpenCV project in Java. I went through JavaCV and found that it did not meet my needs. I was however able to directly implement functionality referenced in OpenCV posts (C++ posts) but in the Java language when I used certain javacpp versions. I had a ton of compilation issues too since javacpp depends on compiled C++ libraries that must be native to the environment the user is in (something people that live in Java land love to not deal with). Anyway I was able to construct and environment with Maven. I use eclipse but this should work fine with other programming environments. I put up an example project to illustrate how to start build a bootstrap project and start working. The project compares 2 images, given their URLs. It's a equality test, wither the images are identical or not. Hopefully this can help folks setup and get working in this environment and avoid the tons and tons of pitfalls that I encountered when trying to work with OpenCV in Java (I was in the exact same place as OP mentally at that time :) ).

The example: https://github.com/darkhipo/ImgzCmp

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.