Running a Java Program Referencing OpenCV's Jar File -


i'm finding impossible run program that's relying on opencv jar file. have compiled "javac -cp opencv-300.jar *.java", trying run java program meant couldn't find main class, ran java program.program threw exceptions regarding finding opencv classes.

i tried java "-djava.library.path=". -jar opencv-300.jar returned "no main manifest attribute, in opencv-300.jar". tried uncompiling jar , running java -cp . program.program , returned "unsatisfiedlinkerror: no opencv_java300 in java.library.path", seems terrible path.

does have clue how can make damn thing run? trying on windows 8 , ubuntu 14.04lts, identical results on both. please help!

edit: can upload public dropbox link people can see if help.

you need package static library jar file, load static library temperory file, , load static library path.

make folder in resources named opencv , place .dll, .dylib , .so files in respective folders.

public class loadlibrary { public static void loadopencv() {     try {         inputstream inputstream = null;         file fileout = null;         string osname = system.getproperty("os.name");         system.out.println(osname);          if (osname.startswith("windows")) {             int bitness = integer.parseint(system.getproperty("sun.arch.data.model"));             if (bitness == 32) {                 inputstream = loadlibrary.class.getresourceasstream("/opencv/windows/x86/opencv_java300.dll");                 fileout = file.createtempfile("lib", ".dll");             } else if (bitness == 64) {                 inputstream = loadlibrary.class.getresourceasstream("/opencv/windows/x64/opencv_java300.dll");                 fileout = file.createtempfile("lib", ".dll");             } else {                 inputstream = loadlibrary.class.getresourceasstream("/opencv/windows/x86/opencv_java300.dll");                 fileout = file.createtempfile("lib", ".dll");             }         } else if (osname.equals("mac os x")) {             inputstream = loadlibrary.class.getresourceasstream("/opencv/mac/libopencv_java300.dylib");             fileout = file.createtempfile("lib", ".dylib");         }  //make check linux          if (fileout != null) {             outputstream outputstream = new fileoutputstream(fileout);             byte[] buffer = new byte[1024];             int length;              while ((length = inputstream.read(buffer)) > 0) {                 outputstream.write(buffer, 0, length);             }              inputstream.close();             outputstream.close();             system.load(fileout.tostring());         }     } catch (exception e) {         e.printstacktrace();     } } 

}

change static { system.loadlibrary(core.native_library_name); } loadlibrary.loadopencv(); in main or before calling opencv functions.

and try export jar file eclipse. work fine.


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -