Ask Your Question

java opencv Helloworld - how?

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

xyzzy gravatar image

I really am missing something.

I can build opencv on my raspberry pi, and end up with opencv-XXX.jar and 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 program looks like this:

  import org.opencv.core.*;

  class HelloWorld {
    static {
     public static void main(String[] args) {

I can compile this when I put the jar file in the classpath using "javac -cp /usr.../" 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.


edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

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

xyzzy gravatar image

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

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:

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


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

Seen: 166 times

Last updated: May 30 '19