OpenCV + Java = UnsatisfiedLinkError

。_饼干妹妹 提交于 2019-11-28 11:55:30

in your second example , you skipped this line

 System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

so the opencv libs werent loaded, UnsatisfiedLinkError, etc...

[edit]:

thanks to @Jishnu Prathap for highlighting the java.library path issue, if you run into problems setting that, you can still try to use an absolute path to the java wrapper so/dll/dylib like:

 System.load("/path to/our/java_wrapper");

I had a similar error while using OpenCV with java.I did 2 things to resolve it.

  1. static{ System.loadLibrary(Core.NATIVE_LIBRARY_NAME); }
  2. I added the path to OpenCV dll or .so to javalibpath or path. which actually didnt work for some reason and i ended up putting the OpenCV dll in the system32 folder.

For general users using opencv3.x:

HighGUI module does not exist anymore in Java for opencv 3.0 and above.

import org.opencv.videoio.VideoCapture;

instead of

import org.opencv.highgui.VideoCapture;

videoio includes VideoCapture, VideoWriter.

Similarly:

imgcodecs includes imread/imwrite and friends

Example:

Highgui.imread(fileName)

-->

 Imgcodecs.imread(fileName)

Try the below code

import org.opencv.core.CvType; import org.opencv.core.Mat;

import nu.pattern.OpenCV;

public class OpencvMain {

public static void main( String[] args )
   {

      OpenCV.loadLocally();
      Mat mat = Mat.eye( 3, 3, CvType.CV_8UC1 );
      System.out.println( "mat = " + mat.dump() );
   }

}

So, I was having this problem too and I did what you all suggested, it worked fine in my x64 windows, but in a x86 couldn't make it work.

At last I found a solution by changing:

VideoCapture capture = new VideoCapture(0);

for

    VideoCapture capture = new VideoCapture();
    capture.open("resources/vid.MP4");

I don't know why this worked but I hope it may help somebody with my same problem.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!