0

GENERAL:

Im programming a face detection Programm with OpenCV and I want to get it working on other Computers without a OpenCV install. My Programm is for Mac OS X, Linux and Windows.

WHAT I ALREADY TRIED:

I tried to compile it on my first Mac, then I copied to my second mac, but I always get Errors, because there are absolute paths (i think) that pointing to my Desktop (Where i compiled the Library on my first mac). I asked my teacher if it is possible to rewrite these absolute paths to relative path, but he said that it is not possible. Now im here :)

CODE: (Nice Formatting xD)

public static void loadOpenCVLibrary() {
    //all opencv libs must be copyed to OpenCV_lib in the project workspace

    File folder = new File(directory+seperator+"System"+seperator+"OpenCV_Linux"+seperator+"build"+seperator+"lib"+seperator);
    //File folder = new File("/Users/Tech/Documents/Development/workspace/opencv-3.0.0/bin/");
    File[] listOfFiles = folder.listFiles(); 

for (int i = 0; i < listOfFiles.length; i++) {
    if (listOfFiles[i].isFile() && listOfFiles[i].getName().endsWith(".dylib")) {
        File lib = new File(directory+seperator+"System"+seperator+"OpenCV_Linux"+seperator+"build"+seperator+"lib"+seperator + listOfFiles[i].getName());
        //File lib = new File("/Users/Tech/Documents/Development/workspace/opencv-3.0.0/bin/" + listOfFiles[i].getName());
        System.load(lib.getAbsoluteFile().toString());
    }
}}

If you need more infos, send a message :)

Thank you very MUCH! Tech

Tech
  • 21
  • 4

1 Answers1

0

If you are using eclipse you can try this:

  1. Copy your OpenCV folder into your current project (not just the jar, the whole folder).
  2. Open your Buildpath and add the OpenCV jar (over workspace not absolute)
  3. Now open the menu of the jar and select native-library and click on edit
  4. Choose workspace again and this time point to the folder where the linux/windows (what you need) native library is

When you build your *.jar it now has the library inside and should run.

Be aware though that this is not run on all platforms but only for the one you selected.

You can also look into loading opencv over the classpath option if cross-plattform running is a potential issue: Load Native Library from Class path

Community
  • 1
  • 1
Gildraths
  • 376
  • 1
  • 10
  • Now it is looking like that... http://prntscr.com/bduxfg. When i use System.loadLibrary(Core.NATIVE_LIBRARY_NAME); it is working only in eclipse, and when i use my Method "loadOpenCVLibrary() in my Question it isn't working because i must set a correct path. What do i need to change. I think the absolute paths are in the Library itself. But thank you for helping :) – Tech Jun 08 '16 at 13:25
  • @Tech Where else should it be working besides eclipse then? Because if its like this you should be able to check the project into your source control and just download it at any place and keep using it. Or do you mean the jar? – Gildraths Jun 08 '16 at 16:21
  • It already was exportable and usable on my mac. But i want to sell the program to my customers. I want to make it as a jar – Tech Jun 08 '16 at 21:07