Ask Your Question
0

java opencv Helloworld - how?

asked 2019-05-24 23:27:06 -0600

xyzzy gravatar image

I really am missing something.

I can build opencv on my raspberry pi, and end up with opencv-XXX.jar and libopencv_javaXXX.so in /usr/local/share/OpenCV/java/

Great! I believe the so file is statically linked because i set BUILD_SHARED_LIBS=OFF in my cmake command, however, I did note in the cmake output it does say "Link libraries: Dynamic load"

My Helloworld.java program looks like this:

  import org.opencv.core.*;

  class HelloWorld {
    static {
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
    }
     public static void main(String[] args) {
        System.out.println("hello.");
    }
  }

I can compile this when I put the jar file in the classpath using "javac -cp /usr.../opencv-XXX.ar HelloWorld.java" but when I run it after (successfully) putting the .so file in the LD_LIBRARY_PATH, I get:

 Segmentation fault

It does it with 4.1.0, 4.0.0, and 3.4.1 and is obviously something I am not doing right.

Help!

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2019-05-27 05:43:13 -0600

xyzzy gravatar image

updated 2019-05-30 01:50:52 -0600

it seems the problem is not with the way the library is constructed (i.e. cmake's "Link Libraries: Dynamic load" does not mean that they are not statically loaded" ????) but rather a bug in ffmpeg causes opencv to crash on a raspberry pi: https://github.com/opencv/opencv/issu...

I guess there is some magic cmake incantation that removes ffmpeg from the link list and substitutes v2l4 instead... yes, done that but I still get an unadorned segmentation fault.

I am giving up with opencv as it is packaged. My java skills are excellent, and my C skills are rusty, but I suspect I will have more success compiling the parts of opencv I want with gcc and then packaging them as I want them with JNI myself.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2019-05-24 23:27:06 -0600

Seen: 510 times

Last updated: May 30 '19