0

I want to open the webcam on my MainClass after the user has successfully logged in.

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)

When I open the MainClass using LoginClass it gives me those error

call MainClass in the LoginClass:

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

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

DaemonThread inside my MainClass:

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

code for Activating Javacv/OpenCv inside my MainClass:

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

Main class of my 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);
        }
    });
}
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • Possible duplicate of [Trying to make java application (Executable Jar) that uses OpenCV portable. Getting unsatisfied link error](https://stackoverflow.com/questions/16269517/trying-to-make-java-application-executable-jar-that-uses-opencv-portable-gett) – ThomasEdwin Dec 09 '17 at 12:14
  • thanks for your comment but that is not the error that i have. – Kurt Ruzell Dec 09 '17 at 12:56
  • *"that is not the error that i have."* Umm.. `UnsatisfiedLinkError`. Both the question linked by @ThomasEdwin & the stack trace above seem to suggest it **is the error.** For better help sooner, post a [MCVE] or [Short, Self Contained, Correct Example](http://www.sscce.org/). – Andrew Thompson Dec 09 '17 at 18:12

0 Answers0