提交 fe0d07ae 编写于 作者: A Andrey Kamaev

Add experimental support for desktop Java

Based on pull request #31 (thanks to Eric Christiansen)
Support for Java is turned off by default and can be enabled setting
BUILD_opencv_java to ON (e.g. cmake -DBUILD_opencv_java=ON ..)
上级 ece71d6a
......@@ -396,14 +396,16 @@ endif(BUILD_DOCS)
include(cmake/OpenCVDetectPython.cmake)
# --- Java Support ---
include(cmake/OpenCVDetectApacheAnt.cmake)
if(ANDROID)
include(cmake/OpenCVDetectApacheAnt.cmake)
include(cmake/OpenCVDetectAndroidSDK.cmake)
if(NOT ANDROID_TOOLS_Pkg_Revision GREATER 13)
message(WARNING "OpenCV requires Android SDK tools revision 14 or newer. Otherwise tests and samples will no be compiled.")
endif()
endif(ANDROID)
elseif(ANT_EXECUTABLE)
find_package(JNI)
endif()
if(ANDROID AND ANDROID_EXECUTABLE AND ANT_EXECUTABLE AND (ANT_VERSION VERSION_GREATER 1.7) AND (ANDROID_TOOLS_Pkg_Revision GREATER 13))
SET(CAN_BUILD_ANDROID_PROJECTS TRUE)
......
# ----------------------------------------------------------------------------
# CMake file for java support
# ----------------------------------------------------------------------------
if(NOT ANDROID OR NOT PYTHON_EXECUTABLE OR ANDROID_NATIVE_API_LEVEL LESS 8)
if(IOS OR NOT PYTHON_EXECUTABLE OR NOT (JNI_FOUND OR (ANDROID AND ANDROID_NATIVE_API_LEVEL GREATER 7)))
ocv_module_disable(java)
endif()
if(NOT ANDROID)
# disable java by default because java support on desktop is experimental
set(BUILD_opencv_java_INIT OFF)
endif()
set(the_description "The java bindings")
ocv_add_module(java BINDINGS opencv_core opencv_imgproc OPTIONAL opencv_objdetect opencv_features2d opencv_video opencv_highgui opencv_ml opencv_calib3d opencv_photo opencv_nonfree opencv_contrib)
ocv_module_include_directories("${CMAKE_CURRENT_SOURCE_DIR}/generator/src/cpp")
if(NOT ANDROID)
include_directories(${JNI_INCLUDE_DIRS})
endif()
# get list of modules to wrap
string(REPLACE "opencv_" "" OPENCV_JAVA_MODULES "${OPENCV_MODULE_${the_module}_REQ_DEPS};${OPENCV_MODULE_${the_module}_OPT_DEPS}")
foreach(module ${OPENCV_JAVA_MODULES})
......@@ -123,7 +132,12 @@ set(JNI_INSTALL_ROOT "sdk/native")
# copy each documented header to the final destination
set(java_files "")
foreach(java_file ${documented_java_files} ${handwrittren_aidl_sources})
set(source_java_files ${documented_java_files} ${handwrittren_aidl_sources})
if(NOT ANDROID)
ocv_list_filterout(source_java_files "/(engine|android)\\\\+")
endif()
foreach(java_file ${source_java_files})
get_filename_component(java_file_name "${java_file}" NAME)
string(REPLACE "-jdoc.java" ".java" java_file_name "${java_file_name}")
string(REPLACE "+" "/" java_file_name "${java_file_name}")
......@@ -175,6 +189,7 @@ set_target_properties(${the_module} PROPERTIES
install(TARGETS ${the_module} LIBRARY DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT main)
set(lib_target ${the_module}_library)
if(ANDROID)
target_link_libraries(${the_module} jnigraphics) # for Mat <=> Bitmap converters
......@@ -223,8 +238,6 @@ if(ANDROID)
# create Android library project in build folder
if(ANDROID_EXECUTABLE)
set(lib_target ${the_module}_android_library)
set(lib_target_files ${ANDROID_LIB_PROJECT_FILES})
ocv_list_add_prefix(lib_target_files "${OpenCV_BINARY_DIR}/")
......@@ -263,12 +276,26 @@ if(ANDROID)
endif()
add_custom_target(${lib_target} SOURCES ${lib_proj_files} ${lib_target_files} "${OpenCV_BINARY_DIR}/${ANDROID_MANIFEST_FILE}")
add_dependencies(${lib_target} ${api_target})
add_dependencies(${the_module} ${lib_target})
endif()
else(ANDROID)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/jar/build.xml" "${OpenCV_BINARY_DIR}/build.xml" IMMEDIATE @ONLY)
set(JAR_NAME opencv-${OPENCV_VERSION_MAJOR}.${OPENCV_VERSION_MINOR}.${OPENCV_VERSION_PATCH}.jar)
add_custom_command(
OUTPUT "${OpenCV_BINARY_DIR}/bin/${JAR_NAME}" "${OpenCV_BINARY_DIR}/bin/.${JAR_NAME}.dephelper"
COMMAND ${ANT_EXECUTABLE} -q -noinput -k jar
COMMAND ${CMAKE_COMMAND} -E touch "${OpenCV_BINARY_DIR}/bin/.${JAR_NAME}.dephelper"
WORKING_DIRECTORY "${OpenCV_BINARY_DIR}"
DEPENDS "${OpenCV_BINARY_DIR}/build.xml" ${java_files}
COMMENT "Generating ${JAR_NAME}"
)
add_custom_target(${lib_target} SOURCES "${OpenCV_BINARY_DIR}/bin/${JAR_NAME}")
endif(ANDROID)
add_dependencies(${lib_target} ${api_target})
add_dependencies(${the_module} ${lib_target})
#android test project
if(ANDROID AND BUILD_TESTS)
add_subdirectory(android_test)
......
......@@ -871,7 +871,7 @@ public class %(jc)s {
#include "converters.h"
#ifdef DEBUG
#if defined DEBUG && defined ANDROID
#include <android/log.h>
#define MODULE_LOG_TAG "OpenCV.%(m)s"
#define LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, MODULE_LOG_TAG, __VA_ARGS__))
......
......@@ -2,6 +2,8 @@
#include "converters.h"
#ifdef ANDROID
#include <android/log.h>
#define LOG_TAG "org.opencv.core.Mat"
#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))
......@@ -11,6 +13,11 @@
#define LOGD(...)
#endif //DEBUG
#else
#define LOGE(...)
#define LOGD(...)
#endif
#include "opencv2/core/core.hpp"
using namespace cv;
......
......@@ -3,6 +3,8 @@
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#ifdef ANDROID
#include <android/bitmap.h>
#include <android/log.h>
......@@ -165,3 +167,5 @@ JNIEXPORT void JNICALL Java_org_opencv_android_Utils_nMatToBitmap
}
} // extern "C"
#endif //ANDROID
\ No newline at end of file
<!-- This is an Apache Ant build file. As part of the desktop java build -->
<!-- process, this config is used to package the autogenerated .java -->
<!-- interface files into OpenCV.jar -->
<project name="OpenCV">
<target name="jar">
<!-- This is to make a jar with a source attachment, for e.g. easy -->
<!-- navigation in Eclipse. See this question: -->
<!-- http://stackoverflow.com/questions/3584968/ant-how-to-compile-jar-that-includes-source-attachment -->
<javac sourcepath="" srcdir="src" destdir="src" debug="on" includeantruntime="false" >
<include name="**/*.java"/>
</javac>
<jar basedir="src" destfile="bin/opencv-@OPENCV_VERSION_MAJOR@.@OPENCV_VERSION_MINOR@.@OPENCV_VERSION_PATCH@.jar"/>
</target>
</project>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册