Skip to content

Commit

Permalink
Merge branch 'feature/opencv4.4.0' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
paulosousadias committed Oct 9, 2020
2 parents 6002511 + 41dcd97 commit f786ce9
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = "<br>" + I18n.text("Install OpenCv 4.4 and dependencies at <br>https://www.lsts.pt/bin/opencv/v4.4.0-x64_x86/deb/");
else if(OsInfo.getFamily() == Family.WINDOWS)
opencvInstallLink = "<br>" + I18n.text("Install OpenCv 4.4 and dependencies at <br>https://www.lsts.pt/bin/opencv/v4.4.0-x64_x86/win-x64_86/");
warningText = new JLabel("<html>" + 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);
}
Expand Down
88 changes: 58 additions & 30 deletions src/pt/lsts/neptus/util/SearchOpenCv.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -49,12 +50,12 @@
*
*/
public class SearchOpenCv {

private static Boolean resultState = null;

private SearchOpenCv() {
}

public synchronized static boolean searchJni() {
if (resultState != null)
return resultState;
Expand All @@ -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
Expand All @@ -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<String> 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;
}

Expand Down

0 comments on commit f786ce9

Please sign in to comment.