使用javacv和Swing的UnsatisfiedLinkError

时间:2017-12-09 12:10:47

标签: java swing opencv javacv unsatisfiedlinkerror

我想在用户成功登录后在我的MainClass上打开网络摄像头。

Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: org.opencv.videoio.VideoCapture.VideoCapture_2(I)J
    at org.opencv.videoio.VideoCapture.VideoCapture_2(Native Method)
    at org.opencv.videoio.VideoCapture.<init>(VideoCapture.java:55)
    at view.MainMenu.Open(MainMenu.java:235)
    at view.MainMenu.btnRegisterWebcamActionPerformed(MainMenu.java:5768)
    at view.MainMenu.access$700(MainMenu.java:76)
    at view.MainMenu$9.actionPerformed(MainMenu.java:1647)

当我使用LoginClass打开MainClass时,它会给我这些错误

在LoginClass中调用MainClass:

MainMenu  mm = new MainMenu();
mm.setVisible(true);

MainClass:

VideoCapture webSource;
private DaemonThread myThread;
Mat frame;
MatOfByte mem;
p

void Open(){
      VideoCapture webSources = new VideoCapture(0);
      webSource = webSources;
      myThread = new DaemonThread();
      Thread t = new Thread(myThread);
      t.setDaemon(true);
      myThread.runnable = true;
      t.start();
}

void preOpen() {
    frame = new Mat();
    mem = new MatOfByte();
}

我的MainClass中的DaemonThread:

  public class DaemonThread implements Runnable {

        protected volatile boolean runnable = false;
        @Override
       public void run() {
           synchronized (this) {
               while (runnable) {
                   if (webSource.grab()) {
                       try {
                           webSource.retrieve(frame);
                           Imgcodecs.imencode("image.png", frame, mem);
                           Image im = ImageIO.read(new ByteArrayInputStream(mem.toArray()));

                           BufferedImage buff = (BufferedImage) im;
                           Graphics g = panelCamera.getGraphics();

                           if (g.drawImage(buff,
                                   50,
                                   0,
//                                   getWidth() - 00,
                                   getWidth() - 800,
//                                   getHeight() - 150,
                                   getHeight() - 400,
                                   0,
                                   0, 
                                   buff.getWidth() + 800,
                                   buff.getHeight() + 500, 
                                   null)) {
                               if (runnable == false) {
                                   System.out.println("Going to wait()");
                                   this.wait();
                               }
                           }
                       } catch (Exception ex) {
                           System.out.println("Error");
                       }
                   }
               }
           }
       }     
    }

在我的MainClass中激活Javacv / OpenCv的代码:

public static final void loadOpenCVLib(String path) throws Exception {
    File lib_dir = new File(path);
    System.setProperty("java.library.path", lib_dir.getAbsolutePath());
    Field sys_paths = ClassLoader.class.getDeclaredField("sys_paths");
    sys_paths.setAccessible(true);
    sys_paths.set(null, null);
    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
    // it is for the ffmpeg name
    String[] list = lib_dir.list();

    assert list != null;
    String ffmpeg_dll_file_name = null;
    for (String s : list) {
        if (s.contains("ffmpeg")) {
            ffmpeg_dll_file_name = s.substring(0, s.indexOf("."));
        }
    }
    System.loadLibrary(ffmpeg_dll_file_name);
}

我的MainClass的主要类:

public static void main(String args[]) {
    try {
        loadOpenCVLib("D:\\System\\javacv\\opencv\\build\\java\\x64");
    } catch (Exception ex) {
        Logger.getLogger(MainMenu.class.getName()).log(Level.SEVERE, null, ex);
    }

    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            new MainMenu().setVisible(true);
        }
    });
}

0 个答案:

没有答案