OpenCV + Java = UnsatisfiedLinkError

后端 未结 5 1361
故里飘歌
故里飘歌 2020-12-11 00:08

I need capture a video stream from my USB webcam, for this i use Opencv 2.4.6 for developing in Java. I follow the steps listed in here

I add the \"C:\\opencv\\build

相关标签:
5条回答
  • 2020-12-11 00:45

    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() );
       }
    

    }

    0 讨论(0)
  • 2020-12-11 00:49

    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)
    
    0 讨论(0)
  • 2020-12-11 00:53

    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");
    
    0 讨论(0)
  • 2020-12-11 00:55

    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.

    0 讨论(0)
  • 2020-12-11 01:01

    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.
    0 讨论(0)
提交回复
热议问题