java.library.path中没有jniopencv_highgui

时间:2016-05-06 08:38:10

标签: java opencv javacv

我正在使用opencv 3.1,在为javacv设置所有配置后,我收到以下错误

Exception in thread "main" java.lang.UnsatisfiedLinkError: no jniopencv_highgui in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1738)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1028)
at com.googlecode.javacpp.Loader.loadLibrary(Loader.java:711)
at com.googlecode.javacpp.Loader.load(Loader.java:586)
at com.googlecode.javacpp.Loader.load(Loader.java:540)
at com.googlecode.javacv.cpp.opencv_highgui.<clinit>(opencv_highgui.java:79)
at demo.main(demo.java:10)
Caused by: java.lang.UnsatisfiedLinkError: C:\Users\pankajs\AppData\Local\Temp\javacpp16045999146511\jniopencv_highgui.dll: Can't find dependent libraries
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1807)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1703)
at java.lang.Runtime.load0(Runtime.java:770)
at java.lang.System.load(System.java:1003)
at com.googlecode.javacpp.Loader.loadLibrary(Loader.java:700)
... 4 more

我认为这是因为javacv版本。我使用的是0.7版本。我不知道哪个版本实际上会用于opencv 3.1.0以及它将在哪里找到。

import static com.googlecode.javacv.cpp.opencv_core.*;
import static com.googlecode.javacv.cpp.opencv_highgui.*;
import com.googlecode.javacv.CanvasFrame;
public class demo {
  public static void main(String[] args) {
    //Load image img1 as IplImage
    final IplImage image = cvLoadImage("img1.png");
    //create canvas frame named 'Demo'
    final CanvasFrame canvas = new CanvasFrame("Demo");
    //Show image in canvas frame
    canvas.showImage(image);
    //This will close canvas frame on exit
    canvas.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
  }
}

1 个答案:

答案 0 :(得分:1)

以上示例使用javacv 0.9

为我工作

以下是修改后的代码:

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import org.bytedeco.javacpp.opencv_core.IplImage;
import org.bytedeco.javacv.CanvasFrame;

public class Demo {
public static void main(String[] args) throws IOException {         
 //Load image img1 as IplImage
    BufferedImage img = ImageIO.read(new File("C:\\Users\\Public\\Pictures\\Sample Pictures\\beach.jpg"));
    final IplImage image = IplImage.createFrom(img);

    //create canvas frame named 'Demo'
    final CanvasFrame canvas = new CanvasFrame("Demo");

    //Show image in canvas frame
    canvas.showImage(image);

    //This will close canvas frame on exit
    canvas.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);        
}    
}