diff --git a/plugins-dev/videostream/pt/lsts/neptus/plugins/videostream/VideoStream.java b/plugins-dev/videostream/pt/lsts/neptus/plugins/videostream/VideoStream.java index 29a36cfdf7..ca01eb4702 100644 --- a/plugins-dev/videostream/pt/lsts/neptus/plugins/videostream/VideoStream.java +++ b/plugins-dev/videostream/pt/lsts/neptus/plugins/videostream/VideoStream.java @@ -114,6 +114,8 @@ import pt.lsts.neptus.params.SystemProperty; import pt.lsts.neptus.params.SystemProperty.Scope; import pt.lsts.neptus.params.SystemProperty.Visibility; +import pt.lsts.neptus.platform.OsInfo; +import pt.lsts.neptus.platform.OsInfo.Family; import pt.lsts.neptus.plugins.NeptusProperty; import pt.lsts.neptus.plugins.PluginDescription; import pt.lsts.neptus.plugins.Popup; @@ -351,6 +353,7 @@ public VideoStream(ConsoleLayout console) { updateSizeVariables(this); if (findOpenCV()) { + NeptusLog.pub().info(I18n.text("OpenCv-4.4.0 found.")); // clears all the unused initializations of the standard ConsolePanel removeAll(); // Resize Console @@ -447,10 +450,15 @@ public void keyTyped(KeyEvent e) { closingPanel = true; setBackground(Color.BLACK); // JLabel for image - this.setLayout(new MigLayout("filly")); + this.setLayout(new MigLayout("al center center")); // JLabel info - warningText = new JLabel(" " + I18n.text("Please install OpenCV 2.4 and its dependencies.") + " "); - warningText.setForeground(new Color(252, 68, 35)); + String opencvInstallLink = ""; + if (OsInfo.getFamily() == Family.UNIX) + opencvInstallLink = "
" + I18n.text("Install OpenCv 4.4 and dependencies at
https://www.lsts.pt/bin/opencv/v4.4.0-x64_x86/deb/"); + else if(OsInfo.getFamily() == Family.WINDOWS) + opencvInstallLink = "
" + I18n.text("Install OpenCv 4.4 and dependencies at
https://www.lsts.pt/bin/opencv/v4.4.0-x64_x86/win-x64_86/"); + warningText = new JLabel("" + I18n.text("Please install OpenCV 4.4.0 and its dependencies." + opencvInstallLink)); + warningText.setForeground(Color.BLACK); warningText.setFont(new Font("Courier New", Font.ITALIC, 18)); this.add(warningText); } diff --git a/src/pt/lsts/neptus/util/SearchOpenCv.java b/src/pt/lsts/neptus/util/SearchOpenCv.java index 5cc491d9c3..d8ee015443 100644 --- a/src/pt/lsts/neptus/util/SearchOpenCv.java +++ b/src/pt/lsts/neptus/util/SearchOpenCv.java @@ -35,6 +35,7 @@ import java.io.File; import java.io.FilenameFilter; import java.util.Arrays; +import java.util.List; import java.lang.reflect.Field; import pt.lsts.neptus.NeptusLog; @@ -49,12 +50,12 @@ * */ public class SearchOpenCv { - + private static Boolean resultState = null; - + private SearchOpenCv() { } - + public synchronized static boolean searchJni() { if (resultState != null) return resultState; @@ -68,10 +69,9 @@ public synchronized static boolean searchJni() { try { addLibraryPath("/usr/share/java/opencv4/"); } - catch (Exception e1) { - NeptusLog.pub().error("Opencv path not found - " + e1.getMessage()); - //e1.printStackTrace(); - } + catch (Exception e1) { + NeptusLog.pub().error("Opencv path not found - " + e1.getMessage()); + } String[] children = !path.exists() ? new String[0] : path.list(new FilenameFilter() { @Override @@ -98,36 +98,64 @@ public boolean accept(File dir, String name) { } } } - else { - // If we are here is not loaded yet - try { - System.loadLibrary("opencv_java440"); - System.loadLibrary("libopencv_core440"); - System.loadLibrary("libopencv_highgui440"); + else if(OsInfo.getFamily() == Family.WINDOWS){ + boolean fail = false; + if(OsInfo.getDataModel() == DataModel.B64) { try { - System.loadLibrary("opencv_ffmpeg440"+ (OsInfo.getDataModel() == DataModel.B64 ? "_64" : "")); + String libpath = System.getProperty("java.library.path"); + libpath = libpath + ";C:\\opencv4.40-x64_86\\x64"; + System.setProperty("java.library.path",libpath); } - catch (Exception e1) { - System.loadLibrary("opencv_ffmpeg440"); + catch (Exception e) { + System.err.println("Add OpenCv path to java.library.path: " + e); + fail = true; } - catch (Error e1) { - System.loadLibrary("opencv_ffmpeg440"); + + if(!fail) { + File path = new File("C:\\opencv4.40-x64_86\\x64"); + List libOpencvDll = Arrays.asList("opencv_videoio_ffmpeg440_64.dll", + "libopencv_core440.dll", "libopencv_imgproc440.dll", "libopencv_dnn440.dll", + "libopencv_flann440.dll", "libopencv_imgcodecs440.dll", "libopencv_ml440.dll", + "libopencv_photo440.dll", "libopencv_videoio440.dll", "libopencv_highgui440.dll", + "libopencv_features2d440.dll", "libopencv_calib3d440.dll", "libopencv_objdetect440.dll", + "libopencv_stitching440.dll", "libopencv_video440.dll", "libopencv_gapi440.dll", + "libopencv_java440.dll"); + if (path.exists()) { + try { + for (String lib : libOpencvDll) { + System.load("C:\\opencv4.40-x64_86\\x64\\" + lib); + NeptusLog.pub().info("OpenCv - Load DLL: " + lib); + } + resultState = true; + } + catch (Exception e) { + NeptusLog.pub().error("Opencv not found - " + e.getMessage()); + resultState = false; + } + catch (Error e) { + NeptusLog.pub().error("Opencv not found - " + e.getMessage()); + resultState = false; + } + } + else { + NeptusLog.pub().error("Opencv path not found"); + resultState = false; + } } - resultState = true; - } - catch (Exception e) { - resultState = false; - NeptusLog.pub().error("Opencv not found - " + e.getMessage()); - } - catch (Error e) { - resultState = false; - NeptusLog.pub().error("Opencv not found - " + e.getMessage()); } } + else { + NeptusLog.pub().error("Only compatible with x64 architecture"); + resultState = false; + } + + if (!resultState) { + if (OsInfo.getFamily() == Family.UNIX) + NeptusLog.pub().error("Opencv not found - please install OpenCv 4.4 and dependencies at https://www.lsts.pt/bin/opencv/v4.4.0-x64_x86/deb/"); + else if(OsInfo.getFamily() == Family.WINDOWS) + NeptusLog.pub().error("Opencv not found - please install OpenCv 4.4 and dependencies at https://www.lsts.pt/bin/opencv/v4.4.0-x64_x86/win-x64_86/"); + } - if (!resultState) - NeptusLog.pub().error("Opencv not found - please install OpenCv 4.4 and dependencies at https://www.lsts.pt/bin/opencv/v4.4.0-x64_x86/deb/"); - return resultState; }