Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
450 views
in Technique[技术] by (71.8m points)

opencv3.0 - Java programming, opencv unsatisfied link error

OpenCV libraries gives unsatisfied link error in capturing a video stream.

Where should be the opencv 3.2.0 libraries? What is the correct path for packages of opencv classes?

Code where to generate this error:

package opencv;

import org.opencv.core.*; 

import org.opencv.imgcodecs.Imgcodecs;        
import org.opencv.videoio.VideoCapture;     
public class VideoCap 
{

    public static void main (String args[]){

        System.loadLibrary(Core.NATIVE_LIBRARY_NAME); // error

        VideoCapture camera = new VideoCapture(0);

        if(!camera.isOpened()){
            System.out.println("Error");
        }
    else {
            Mat frame = new Mat();
            while(true){
                if (camera.read(frame)){
                    System.out.println("Frame Obtained");
                    System.out.println("Captured Frame Width " + 
                    frame.width() + " Height " + frame.height());
                    Imgcodecs.imwrite("camera.jpg", frame);
                    System.out.println("OK");
                    break;
                }
            }   
        }
        camera.release();
    }
}

The exception is:

Exception in thread "main" java.lang.UnsatisfiedLinkError:
    no opencv_java320 in java.library.path
    at java.lang.ClassLoader.loadLibrary(Unknown Source)
    at java.lang.Runtime.loadLibrary0(Unknown Source)
    at java.lang.System.loadLibrary(Unknown Source)
    at opencv.VideoCap.main(VideoCap.java:9)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try to clone the repository below:

https://github.com/hellonico/opencv4_java_tutorial.git

Add your class in the java folder, and instead of using System.loadLibrary ... use:

NativeLoader.loadLibrary(Core.NATIVE_LIBRARY_NAME);

This will load a properly compiled version of OpenCV to run within the JVM.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...