diff --git a/modules/java/CMakeLists.txt b/modules/java/CMakeLists.txt index 2fc52a703c..2639fe5a5c 100644 --- a/modules/java/CMakeLists.txt +++ b/modules/java/CMakeLists.txt @@ -217,6 +217,12 @@ endif(ANDROID AND ANDROID_EXECUTABLE) set(step3_depends ${step2_depends} ${step3_input_files} ${copied_files}) +if(ANDROID) + set(LIB_NAME_SUFIX "") +else() + set(LIB_NAME_SUFIX "${OPENCV_VERSION_MAJOR}${OPENCV_VERSION_MINOR}${OPENCV_VERSION_PATCH}") +endif() + # step 4: build jar if(ANDROID) set(JAR_FILE "${OpenCV_BINARY_DIR}/bin/classes.jar") @@ -241,7 +247,7 @@ if(ANDROID) ) endif() else(ANDROID) - set(JAR_NAME opencv-${OPENCV_VERSION}.jar) + set(JAR_NAME opencv-${LIB_NAME_SUFIX}.jar) set(JAR_FILE "${OpenCV_BINARY_DIR}/bin/${JAR_NAME}") configure_file("${CMAKE_CURRENT_SOURCE_DIR}/build.xml.in" "${OpenCV_BINARY_DIR}/build.xml" IMMEDIATE @ONLY) list(APPEND step3_depends "${OpenCV_BINARY_DIR}/build.xml") @@ -294,8 +300,8 @@ endif() # Additional target properties set_target_properties(${the_module} PROPERTIES - OUTPUT_NAME "${the_module}${OPENCV_DLLVERSION}" - DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}" + OUTPUT_NAME "${the_module}${LIB_NAME_SUFIX}" + #DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}" ARCHIVE_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_PATH} RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} INSTALL_NAME_DIR ${OPENCV_LIB_INSTALL_PATH} diff --git a/modules/java/generator/gen_java.py b/modules/java/generator/gen_java.py index 0f3ba1d336..c0da34fe09 100755 --- a/modules/java/generator/gen_java.py +++ b/modules/java/generator/gen_java.py @@ -559,6 +559,15 @@ func_arg_fix = { }, # '', i.e. no class } # func_arg_fix + +def getLibVersion(version_hpp_path): + version_file = open(version_hpp_path, "rt").read() + epoch = re.search("^W*#\W*define\W+CV_VERSION_EPOCH\W+(\d+)\W*$", version_file, re.MULTILINE).group(1) + major = re.search("^W*#\W*define\W+CV_VERSION_MAJOR\W+(\d+)\W*$", version_file, re.MULTILINE).group(1) + minor = re.search("^W*#\W*define\W+CV_VERSION_MINOR\W+(\d+)\W*$", version_file, re.MULTILINE).group(1) + revision = re.search("^W*#\W*define\W+CV_VERSION_REVISION\W+(\d+)\W*$", version_file, re.MULTILINE).group(1) + return (epoch, major, minor, revision) + class ConstInfo(object): def __init__(self, cname, name, val, addedManually=False): self.cname = cname @@ -721,13 +730,16 @@ $imports public class %(jc)s { """ % { 'm' : self.module, 'jc' : jname } ) -# self.java_code[class_name]["jn_code"].write(""" -# // -# // native stuff -# // -# static { System.loadLibrary("opencv_java"); } -#""" ) - + if class_name == 'Core': + (epoch, major, minor, revision) = getLibVersion( + (os.path.dirname(__file__) or '.') + '/../../core/include/opencv2/core/version.hpp') + version_str = '.'.join( (epoch, major, minor, revision) ) + version_suffix = ''.join( (epoch, major, minor) ) + self.classes[class_name].imports.add("java.lang.String") + self.java_code[class_name]["j_code"].write(""" + public static final String VERSION = "%(v)s", NATIVE_LIBRARY_NAME = "opencv_java%(vs)s"; + public static final int VERSION_EPOCH = %(ep)s, VERSION_MAJOR = %(ma)s, VERSION_MINOR = %(mi)s, VERSION_REVISION = %(re)s; +""" % { 'v' : version_str, 'vs' : version_suffix, 'ep' : epoch, 'ma' : major, 'mi' : minor, 're' : revision } ) def add_class(self, decl): diff --git a/samples/java/ant/src/SimpleSample.java b/samples/java/ant/src/SimpleSample.java index 990536f2b8..a0375c5624 100644 --- a/samples/java/ant/src/SimpleSample.java +++ b/samples/java/ant/src/SimpleSample.java @@ -1,12 +1,14 @@ +import org.opencv.core.Core; import org.opencv.core.Mat; import org.opencv.core.CvType; import org.opencv.core.Scalar; class SimpleSample { - static{ System.loadLibrary("opencv_java244"); } + static{ System.loadLibrary(Core.NATIVE_LIBRARY_NAME); } public static void main(String[] args) { + System.out.println("Welcome to OpenCV " + Core.VERSION); Mat m = new Mat(5, 10, CvType.CV_8UC1, new Scalar(0)); System.out.println("OpenCV Mat: " + m); Mat mr1 = m.row(1); diff --git a/samples/java/eclipse/HelloCV/src/Main.java b/samples/java/eclipse/HelloCV/src/Main.java index 0e9bb5898f..44f2bb02b3 100644 --- a/samples/java/eclipse/HelloCV/src/Main.java +++ b/samples/java/eclipse/HelloCV/src/Main.java @@ -1,10 +1,12 @@ +import org.opencv.core.Core; import org.opencv.core.CvType; import org.opencv.core.Mat; public class Main { public static void main(String[] args) { - System.loadLibrary("opencv_java244"); + System.out.println("Welcome to OpenCV " + Core.VERSION); + System.loadLibrary(Core.NATIVE_LIBRARY_NAME); Mat m = Mat.eye(3, 3, CvType.CV_8UC1); System.out.println("m = " + m.dump()); } diff --git a/samples/java/sbt/src/main/scala/Main.scala b/samples/java/sbt/src/main/scala/Main.scala index 4a68d144a4..6f07aa19ce 100644 --- a/samples/java/sbt/src/main/scala/Main.scala +++ b/samples/java/sbt/src/main/scala/Main.scala @@ -8,11 +8,14 @@ * You're invited to submit your own examples, in any JVM language of * your choosing so long as you can get them to build. */ + +import org.opencv.core.Core + object Main extends App { // We must load the native library before using any OpenCV functions. // You must load this library _exactly once_ per Java invocation. // If you load it more than once, you will get a java.lang.UnsatisfiedLinkError. - System.loadLibrary("opencv_java") + System.loadLibrary(Core.NATIVE_LIBRARY_NAME) ScalaCorrespondenceMatchingDemo.run() ScalaDetectFaceDemo.run()