merged Android Manager and new java layout
This commit is contained in:
@@ -7,7 +7,7 @@ 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)
|
||||
ocv_module_include_directories("${CMAKE_CURRENT_SOURCE_DIR}/src/cpp")
|
||||
ocv_module_include_directories("${CMAKE_CURRENT_SOURCE_DIR}/generator/src/cpp")
|
||||
|
||||
# get list of modules to wrap
|
||||
string(REPLACE "opencv_" "" OPENCV_JAVA_MODULES "${OPENCV_MODULE_${the_module}_REQ_DEPS};${OPENCV_MODULE_${the_module}_OPT_DEPS}")
|
||||
@@ -17,10 +17,10 @@ foreach(module ${OPENCV_JAVA_MODULES})
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
set(GEN_JAVA "${CMAKE_CURRENT_SOURCE_DIR}/gen_java.py")
|
||||
set(GEN_JAVA "${CMAKE_CURRENT_SOURCE_DIR}/generator/gen_java.py")
|
||||
set(HDR_PARSER "${CMAKE_CURRENT_SOURCE_DIR}/../python/src2/hdr_parser.py")
|
||||
set(GEN_JAVADOC "${CMAKE_CURRENT_SOURCE_DIR}/gen_javadoc.py")
|
||||
set(RST_PARSER "${CMAKE_CURRENT_SOURCE_DIR}/rst_parser.py")
|
||||
set(GEN_JAVADOC "${CMAKE_CURRENT_SOURCE_DIR}/generator/gen_javadoc.py")
|
||||
set(RST_PARSER "${CMAKE_CURRENT_SOURCE_DIR}/generator/rst_parser.py")
|
||||
|
||||
# add dependencies to cmake (we should rerun cmake if any of these scripts is modified)
|
||||
configure_file("${GEN_JAVA}" "${OpenCV_BINARY_DIR}/junk/gen_java.junk" COPYONLY)
|
||||
@@ -33,8 +33,8 @@ set(generated_java_sources "")
|
||||
# setup raw java and cpp files generation (without javadoc and at temporary location)
|
||||
foreach(module ${OPENCV_JAVA_MODULES})
|
||||
# get list of module headers
|
||||
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/config/${module}.filelist")
|
||||
file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/config/${module}.filelist" module_headers)
|
||||
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/generator/config/${module}.filelist")
|
||||
file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/generator/config/${module}.filelist" module_headers)
|
||||
ocv_list_add_prefix(module_headers "${OPENCV_MODULE_opencv_${module}_LOCATION}/")
|
||||
else()
|
||||
set(module_headers "${OPENCV_MODULE_opencv_${module}_HEADERS}")
|
||||
@@ -78,9 +78,10 @@ foreach(module ${OPENCV_JAVA_MODULES})
|
||||
endforeach()
|
||||
|
||||
# get handwritten files used for wrappers generation
|
||||
file(GLOB handwrittren_h_sources "${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/*.h" "${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/*.hpp")
|
||||
file(GLOB handwrittren_cpp_sources "${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/*.cpp")
|
||||
file(GLOB handwrittren_java_sources "${CMAKE_CURRENT_SOURCE_DIR}/src/java/*.java")
|
||||
file(GLOB handwrittren_h_sources "${CMAKE_CURRENT_SOURCE_DIR}/generator/src/cpp/*.h" "${CMAKE_CURRENT_SOURCE_DIR}/generator/src/cpp/*.hpp")
|
||||
file(GLOB handwrittren_cpp_sources "${CMAKE_CURRENT_SOURCE_DIR}/generator/src/cpp/*.cpp")
|
||||
file(GLOB handwrittren_java_sources "${CMAKE_CURRENT_SOURCE_DIR}/generator/src/java/*.java")
|
||||
file(GLOB handwrittren_aidl_sources "${CMAKE_CURRENT_SOURCE_DIR}/generator/src/java/*.aidl")
|
||||
|
||||
# remove handwritten java files for disabled modules
|
||||
foreach(jfile ${handwrittren_java_sources})
|
||||
@@ -92,7 +93,7 @@ endforeach()
|
||||
|
||||
# remove VideoCapture wrapper if highgui is disabled
|
||||
if(NOT HAVE_opencv_highgui)
|
||||
list(REMOVE_ITEM handwrittren_cpp_sources "${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/VideoCapture.cpp")
|
||||
list(REMOVE_ITEM handwrittren_cpp_sources "${CMAKE_CURRENT_SOURCE_DIR}/generator/src/cpp/VideoCapture.cpp")
|
||||
endif()
|
||||
|
||||
# create list of javadoc documented files
|
||||
@@ -110,7 +111,7 @@ set(java_documented_headers_deps ${handwrittren_java_sources} ${generated_java_s
|
||||
#TODO: pass list of modules
|
||||
add_custom_command(
|
||||
OUTPUT ${documented_java_files}
|
||||
COMMAND ${PYTHON_EXECUTABLE} "${GEN_JAVADOC}" "${CMAKE_CURRENT_SOURCE_DIR}/src/java" "${CMAKE_CURRENT_BINARY_DIR}" 2>"${CMAKE_CURRENT_BINARY_DIR}/get_javadoc_errors.log"
|
||||
COMMAND ${PYTHON_EXECUTABLE} "${GEN_JAVADOC}" "${CMAKE_CURRENT_SOURCE_DIR}/generator/src/java" "${CMAKE_CURRENT_BINARY_DIR}" 2>"${CMAKE_CURRENT_BINARY_DIR}/get_javadoc_errors.log"
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||
DEPENDS ${java_documented_headers_deps}
|
||||
)
|
||||
@@ -120,7 +121,7 @@ set(JAVA_OUTPUT_DIR "src/org/opencv")
|
||||
|
||||
# copy each documented header to the final destination
|
||||
set(java_files "")
|
||||
foreach(java_file ${documented_java_files})
|
||||
foreach(java_file ${documented_java_files} ${handwrittren_aidl_sources})
|
||||
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}")
|
||||
@@ -184,14 +185,14 @@ if(ANDROID)
|
||||
set(lib_proj_files "")
|
||||
|
||||
# manifest, jni, Eclipse project
|
||||
file(GLOB_RECURSE android_lib_project_files RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/android/" "${CMAKE_CURRENT_SOURCE_DIR}/android/*")
|
||||
file(GLOB_RECURSE android_lib_project_files RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/android_lib/" "${CMAKE_CURRENT_SOURCE_DIR}/android_lib/*")
|
||||
list(REMOVE_ITEM android_lib_project_files "${ANDROID_MANIFEST_FILE}")
|
||||
foreach(f ${android_lib_project_files})
|
||||
if(NOT f MATCHES "\\.svn")
|
||||
add_custom_command(
|
||||
OUTPUT "${OpenCV_BINARY_DIR}/${f}"
|
||||
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/android/${f}" "${OpenCV_BINARY_DIR}/${f}"
|
||||
MAIN_DEPENDENCY "${CMAKE_CURRENT_SOURCE_DIR}/android/${f}"
|
||||
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/android_lib/${f}" "${OpenCV_BINARY_DIR}/${f}"
|
||||
MAIN_DEPENDENCY "${CMAKE_CURRENT_SOURCE_DIR}/android_lib/${f}"
|
||||
COMMENT "Generating ${f}"
|
||||
)
|
||||
|
||||
@@ -227,10 +228,10 @@ if(ANDROID)
|
||||
add_custom_command(
|
||||
OUTPUT ${lib_target_files} "${OpenCV_BINARY_DIR}/${ANDROID_MANIFEST_FILE}"
|
||||
COMMAND ${CMAKE_COMMAND} -E remove ${lib_target_files}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/android/${ANDROID_MANIFEST_FILE}" "${OpenCV_BINARY_DIR}/${ANDROID_MANIFEST_FILE}"
|
||||
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/android_lib/${ANDROID_MANIFEST_FILE}" "${OpenCV_BINARY_DIR}/${ANDROID_MANIFEST_FILE}"
|
||||
COMMAND ${ANDROID_EXECUTABLE} --silent create lib-project --path \"${OpenCV_BINARY_DIR}\" --target \"${lib_target_sdk_target}\" --name OpenCV --package org.opencv 2>\"${CMAKE_CURRENT_BINARY_DIR}/create_lib_project.log\"
|
||||
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/android/${ANDROID_MANIFEST_FILE}" "${OpenCV_BINARY_DIR}/${ANDROID_MANIFEST_FILE}"
|
||||
MAIN_DEPENDENCY "${CMAKE_CURRENT_SOURCE_DIR}/android/${ANDROID_MANIFEST_FILE}"
|
||||
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/android_lib/${ANDROID_MANIFEST_FILE}" "${OpenCV_BINARY_DIR}/${ANDROID_MANIFEST_FILE}"
|
||||
MAIN_DEPENDENCY "${CMAKE_CURRENT_SOURCE_DIR}/android_lib/${ANDROID_MANIFEST_FILE}"
|
||||
DEPENDS ${lib_proj_files}
|
||||
COMMENT "Generating OpenCV Android library project. SDK target: ${lib_target_sdk_target}"
|
||||
)
|
||||
@@ -248,8 +249,8 @@ if(ANDROID)
|
||||
DEPENDS ${lib_proj_files} ${lib_target_files} ${java_files}
|
||||
COMMENT "Building OpenCV Android library project"
|
||||
)
|
||||
install(FILES "${OpenCV_BINARY_DIR}/bin/classes.jar" "${OpenCV_BINARY_DIR}/bin/jarlist.cache" "${OpenCV_BINARY_DIR}/bin/build.prop" DESTINATION bin COMPONENT main)
|
||||
install(DIRECTORY "${OpenCV_BINARY_DIR}/bin/res" "${OpenCV_BINARY_DIR}/bin/classes" DESTINATION bin COMPONENT main)
|
||||
#install(FILES "${OpenCV_BINARY_DIR}/bin/classes.jar" "${OpenCV_BINARY_DIR}/bin/jarlist.cache" "${OpenCV_BINARY_DIR}/bin/build.prop" DESTINATION bin COMPONENT main)
|
||||
#install(DIRECTORY "${OpenCV_BINARY_DIR}/bin/res" "${OpenCV_BINARY_DIR}/bin/classes" DESTINATION bin COMPONENT main)
|
||||
list(APPEND lib_target_files "${OpenCV_BINARY_DIR}/bin/classes.jar")
|
||||
endif()
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>OpenCV-2.4.0</name>
|
||||
<name>OpenCV-2.4.2</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.opencv"
|
||||
android:versionCode="240"
|
||||
android:versionName="2.4.0">
|
||||
android:versionCode="242"
|
||||
android:versionName="2.4.2">
|
||||
</manifest>
|
@@ -23,7 +23,9 @@ import android.util.Log;
|
||||
|
||||
public class OpenCVTestRunner extends InstrumentationTestRunner {
|
||||
|
||||
public static String LENA_PATH;
|
||||
static { System.loadLibrary("opencv_java"); }
|
||||
|
||||
public static String LENA_PATH;
|
||||
public static String CHESS_PATH;
|
||||
public static String LBPCASCADE_FRONTALFACE_PATH;
|
||||
public static Context context;
|
||||
|
@@ -1,2 +0,0 @@
|
||||
include/opencv2/core/core.hpp
|
||||
../java/src/cpp/core_manual.hpp
|
@@ -1 +0,0 @@
|
||||
../java/src/cpp/features2d_manual.hpp
|
2
modules/java/generator/config/core.filelist
Normal file
2
modules/java/generator/config/core.filelist
Normal file
@@ -0,0 +1,2 @@
|
||||
include/opencv2/core/core.hpp
|
||||
../java/generator/src/cpp/core_manual.hpp
|
1
modules/java/generator/config/features2d.filelist
Normal file
1
modules/java/generator/config/features2d.filelist
Normal file
@@ -0,0 +1 @@
|
||||
../java/generator/src/cpp/features2d_manual.hpp
|
@@ -717,12 +717,12 @@ $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"); }
|
||||
""" )
|
||||
# self.java_code[class_name]["jn_code"].write("""
|
||||
# //
|
||||
# // native stuff
|
||||
# //
|
||||
# static { System.loadLibrary("opencv_java"); }
|
||||
#""" )
|
||||
|
||||
|
||||
|
@@ -238,7 +238,7 @@ if __name__ == "__main__":
|
||||
exit(0)
|
||||
|
||||
selfpath = os.path.dirname(os.path.abspath(sys.argv[0]))
|
||||
hdr_parser_path = os.path.join(selfpath, "../python/src2")
|
||||
hdr_parser_path = os.path.join(selfpath, "../../python/src2")
|
||||
|
||||
sys.path.append(selfpath)
|
||||
sys.path.append(hdr_parser_path)
|
||||
@@ -248,7 +248,7 @@ if __name__ == "__main__":
|
||||
print "Parsing documentation..."
|
||||
parser = rst_parser.RstParser(hdr_parser.CppHeaderParser())
|
||||
for m in allmodules:
|
||||
parser.parse(m, os.path.join(selfpath, "../" + m))
|
||||
parser.parse(m, os.path.join(selfpath, "../../" + m))
|
||||
|
||||
parser.printSummary()
|
||||
|
@@ -719,14 +719,14 @@ if __name__ == "__main__":
|
||||
verbose = True
|
||||
|
||||
rst_parser_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
|
||||
hdr_parser_path = os.path.join(rst_parser_dir, "../python/src2")
|
||||
hdr_parser_path = os.path.join(rst_parser_dir, "../../python/src2")
|
||||
|
||||
sys.path.append(hdr_parser_path)
|
||||
import hdr_parser
|
||||
|
||||
module = sys.argv[1]
|
||||
|
||||
if module != "all" and not os.path.isdir(os.path.join(rst_parser_dir, "../" + module)):
|
||||
if module != "all" and not os.path.isdir(os.path.join(rst_parser_dir, "../../" + module)):
|
||||
print "RST parser error E%03d: module \"%s\" could not be found." % (ERROR_010_NOMODULE, module)
|
||||
exit(1)
|
||||
|
||||
@@ -734,9 +734,9 @@ if __name__ == "__main__":
|
||||
|
||||
if module == "all":
|
||||
for m in allmodules:
|
||||
parser.parse(m, os.path.join(rst_parser_dir, "../" + m))
|
||||
parser.parse(m, os.path.join(rst_parser_dir, "../../" + m))
|
||||
else:
|
||||
parser.parse(module, os.path.join(rst_parser_dir, "../" + module))
|
||||
parser.parse(module, os.path.join(rst_parser_dir, "../../" + module))
|
||||
|
||||
# summary
|
||||
parser.printSummary()
|
279
modules/java/generator/src/java/android+AsyncServiceHelper.java
Normal file
279
modules/java/generator/src/java/android+AsyncServiceHelper.java
Normal file
@@ -0,0 +1,279 @@
|
||||
package org.opencv.android;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import org.opencv.engine.OpenCVEngineInterface;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.ServiceConnection;
|
||||
import android.net.Uri;
|
||||
import android.os.IBinder;
|
||||
import android.os.RemoteException;
|
||||
import android.util.Log;
|
||||
|
||||
class AsyncServiceHelper
|
||||
{
|
||||
public static boolean initOpenCV(String Version, final Context AppContext,
|
||||
final LoaderCallbackInterface Callback)
|
||||
{
|
||||
AsyncServiceHelper helper = new AsyncServiceHelper(Version, AppContext, Callback);
|
||||
if (AppContext.bindService(new Intent("org.opencv.engine.BIND"),
|
||||
helper.mServiceConnection, Context.BIND_AUTO_CREATE))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
AppContext.unbindService(helper.mServiceConnection);
|
||||
InstallService(AppContext, Callback);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected AsyncServiceHelper(String Version, Context AppContext,
|
||||
LoaderCallbackInterface Callback)
|
||||
{
|
||||
mOpenCVersion = Version;
|
||||
mUserAppCallback = Callback;
|
||||
mAppContext = AppContext;
|
||||
}
|
||||
|
||||
protected static final String TAG = "OpenCVManager/Helper";
|
||||
protected static final int MINIMUM_ENGINE_VERSION = 1;
|
||||
protected OpenCVEngineInterface mEngineService;
|
||||
protected LoaderCallbackInterface mUserAppCallback;
|
||||
protected String mOpenCVersion;
|
||||
protected Context mAppContext;
|
||||
protected int mStatus = LoaderCallbackInterface.SUCCESS;
|
||||
|
||||
private static void InstallService(final Context AppContext, final LoaderCallbackInterface Callback)
|
||||
{
|
||||
InstallCallbackInterface InstallQuery = new InstallCallbackInterface() {
|
||||
private Context mAppContext = AppContext;
|
||||
private LoaderCallbackInterface mUserAppCallback = Callback;
|
||||
public String getPackageName()
|
||||
{
|
||||
return "OpenCV Manager Service";
|
||||
}
|
||||
public void install() {
|
||||
Log.d(TAG, "Trying to install OpenCV Manager via Google Play");
|
||||
|
||||
boolean result = true;
|
||||
try
|
||||
{
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(OPEN_CV_SERVICE_URL));
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
mAppContext.startActivity(intent);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
|
||||
if (result)
|
||||
{
|
||||
int Status = LoaderCallbackInterface.RESTART_REQUIRED;
|
||||
Log.d(TAG, "Init finished with status " + Status);
|
||||
Log.d(TAG, "Calling using callback");
|
||||
mUserAppCallback.onManagerConnected(Status);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.d(TAG, "OpenCV package was not installed!");
|
||||
int Status = LoaderCallbackInterface.MARKET_ERROR;
|
||||
Log.d(TAG, "Init finished with status " + Status);
|
||||
Log.d(TAG, "Unbind from service");
|
||||
Log.d(TAG, "Calling using callback");
|
||||
mUserAppCallback.onManagerConnected(Status);
|
||||
}
|
||||
}
|
||||
|
||||
public void cancel()
|
||||
{
|
||||
Log.d(TAG, "OpenCV library installation was canceled");
|
||||
int Status = LoaderCallbackInterface.INSTALL_CANCELED;
|
||||
Log.d(TAG, "Init finished with status " + Status);
|
||||
Log.d(TAG, "Calling using callback");
|
||||
mUserAppCallback.onManagerConnected(Status);
|
||||
}
|
||||
};
|
||||
|
||||
Callback.onPackageInstall(InstallQuery);
|
||||
}
|
||||
|
||||
/**
|
||||
* URI for OpenCV Manager on Google Play (Android Market)
|
||||
*/
|
||||
protected static final String OPEN_CV_SERVICE_URL = "market://details?id=org.opencv.engine";
|
||||
|
||||
protected ServiceConnection mServiceConnection = new ServiceConnection()
|
||||
{
|
||||
public void onServiceConnected(ComponentName className, IBinder service)
|
||||
{
|
||||
Log.d(TAG, "Service connection created");
|
||||
mEngineService = OpenCVEngineInterface.Stub.asInterface(service);
|
||||
if (null == mEngineService)
|
||||
{
|
||||
Log.d(TAG, "OpenCV Manager Service connection fails. May be service was not installed?");
|
||||
InstallService(mAppContext, mUserAppCallback);
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
if (mEngineService.getEngineVersion() < MINIMUM_ENGINE_VERSION)
|
||||
{
|
||||
mStatus = LoaderCallbackInterface.INCOMPATIBLE_MANAGER_VERSION;
|
||||
Log.d(TAG, "Init finished with status " + mStatus);
|
||||
Log.d(TAG, "Unbind from service");
|
||||
mAppContext.unbindService(mServiceConnection);
|
||||
Log.d(TAG, "Calling using callback");
|
||||
mUserAppCallback.onManagerConnected(mStatus);
|
||||
return;
|
||||
}
|
||||
|
||||
Log.d(TAG, "Trying to get library path");
|
||||
String path = mEngineService.getLibPathByVersion(mOpenCVersion);
|
||||
if ((null == path) || (path.length() == 0))
|
||||
{
|
||||
InstallCallbackInterface InstallQuery = new InstallCallbackInterface() {
|
||||
public String getPackageName()
|
||||
{
|
||||
return "OpenCV library";
|
||||
}
|
||||
public void install() {
|
||||
Log.d(TAG, "Trying to install OpenCV lib via Google Play");
|
||||
try
|
||||
{
|
||||
if (mEngineService.installVersion(mOpenCVersion))
|
||||
{
|
||||
mStatus = LoaderCallbackInterface.RESTART_REQUIRED;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.d(TAG, "OpenCV package was not installed!");
|
||||
mStatus = LoaderCallbackInterface.MARKET_ERROR;
|
||||
}
|
||||
} catch (RemoteException e) {
|
||||
e.printStackTrace();
|
||||
mStatus = LoaderCallbackInterface.INIT_FAILED;
|
||||
}
|
||||
|
||||
Log.d(TAG, "Init finished with status " + mStatus);
|
||||
Log.d(TAG, "Unbind from service");
|
||||
mAppContext.unbindService(mServiceConnection);
|
||||
Log.d(TAG, "Calling using callback");
|
||||
mUserAppCallback.onManagerConnected(mStatus);
|
||||
}
|
||||
public void cancel() {
|
||||
Log.d(TAG, "OpenCV library installation was canceled");
|
||||
mStatus = LoaderCallbackInterface.INSTALL_CANCELED;
|
||||
Log.d(TAG, "Init finished with status " + mStatus);
|
||||
Log.d(TAG, "Unbind from service");
|
||||
mAppContext.unbindService(mServiceConnection);
|
||||
Log.d(TAG, "Calling using callback");
|
||||
mUserAppCallback.onManagerConnected(mStatus);
|
||||
}
|
||||
};
|
||||
|
||||
mUserAppCallback.onPackageInstall(InstallQuery);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.d(TAG, "Trying to get library list");
|
||||
String libs = mEngineService.getLibraryList(mOpenCVersion);
|
||||
Log.d(TAG, "Library list: \"" + libs + "\"");
|
||||
Log.d(TAG, "First attempt to load libs");
|
||||
if (initOpenCVLibs(path, libs))
|
||||
{
|
||||
Log.d(TAG, "First attempt to load libs is OK");
|
||||
mStatus = LoaderCallbackInterface.SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.d(TAG, "First attempt to load libs fails");
|
||||
mStatus = LoaderCallbackInterface.INIT_FAILED;
|
||||
}
|
||||
|
||||
Log.d(TAG, "Init finished with status " + mStatus);
|
||||
Log.d(TAG, "Unbind from service");
|
||||
mAppContext.unbindService(mServiceConnection);
|
||||
Log.d(TAG, "Calling using callback");
|
||||
mUserAppCallback.onManagerConnected(mStatus);
|
||||
}
|
||||
}
|
||||
catch (RemoteException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
mStatus = LoaderCallbackInterface.INIT_FAILED;
|
||||
Log.d(TAG, "Init finished with status " + mStatus);
|
||||
Log.d(TAG, "Unbind from service");
|
||||
mAppContext.unbindService(mServiceConnection);
|
||||
Log.d(TAG, "Calling using callback");
|
||||
mUserAppCallback.onManagerConnected(mStatus);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onServiceDisconnected(ComponentName className)
|
||||
{
|
||||
mEngineService = null;
|
||||
}
|
||||
};
|
||||
|
||||
private boolean loadLibrary(String AbsPath)
|
||||
{
|
||||
boolean result = true;
|
||||
|
||||
Log.d(TAG, "Trying to load library " + AbsPath);
|
||||
try
|
||||
{
|
||||
System.load(AbsPath);
|
||||
Log.d(TAG, "OpenCV libs init was ok!");
|
||||
}
|
||||
catch(UnsatisfiedLinkError e)
|
||||
{
|
||||
Log.d(TAG, "Cannot load library \"" + AbsPath + "\"");
|
||||
e.printStackTrace();
|
||||
result &= false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private boolean initOpenCVLibs(String Path, String Libs)
|
||||
{
|
||||
Log.d(TAG, "Trying to init OpenCV libs");
|
||||
if ((null != Path) && (Path.length() != 0))
|
||||
{
|
||||
boolean result = true;
|
||||
if ((null != Libs) && (Libs.length() != 0))
|
||||
{
|
||||
Log.d(TAG, "Trying to load libs by dependency list");
|
||||
StringTokenizer splitter = new StringTokenizer(Libs, ";");
|
||||
while(splitter.hasMoreTokens())
|
||||
{
|
||||
String AbsLibraryPath = Path + File.separator + splitter.nextToken();
|
||||
result &= loadLibrary(AbsLibraryPath);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// If dependencies list is not defined or empty
|
||||
String AbsLibraryPath = Path + File.separator + "libopencv_java.so";
|
||||
result &= loadLibrary(AbsLibraryPath);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.d(TAG, "Library path \"" + Path + "\" is empty");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
126
modules/java/generator/src/java/android+BaseLoaderCallback.java
Normal file
126
modules/java/generator/src/java/android+BaseLoaderCallback.java
Normal file
@@ -0,0 +1,126 @@
|
||||
package org.opencv.android;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.DialogInterface.OnClickListener;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* Basic implementation of LoaderCallbackInterface
|
||||
*/
|
||||
public abstract class BaseLoaderCallback implements LoaderCallbackInterface {
|
||||
|
||||
public BaseLoaderCallback(Activity AppContext) {
|
||||
mAppContext = AppContext;
|
||||
}
|
||||
|
||||
public void onManagerConnected(int status)
|
||||
{
|
||||
switch (status)
|
||||
{
|
||||
/** OpenCV initialization was successful. **/
|
||||
case LoaderCallbackInterface.SUCCESS:
|
||||
{
|
||||
/** Application must override this method to handle successful library initialization **/
|
||||
} break;
|
||||
/** OpenCV Manager or library package installation is in progress. Restart of application is required **/
|
||||
case LoaderCallbackInterface.RESTART_REQUIRED:
|
||||
{
|
||||
Log.d(TAG, "OpenCV downloading. App restart is needed!");
|
||||
AlertDialog RestartMessage = new AlertDialog.Builder(mAppContext).create();
|
||||
RestartMessage.setTitle("App restart is required");
|
||||
RestartMessage.setMessage("Application will be closed now. Start it when installation will be finished!");
|
||||
RestartMessage.setCancelable(false); // This blocks the 'BACK' button
|
||||
RestartMessage.setButton("OK", new OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
mAppContext.finish();
|
||||
}
|
||||
});
|
||||
|
||||
RestartMessage.show();
|
||||
} break;
|
||||
/** OpenCV loader cannot start Google Play **/
|
||||
case LoaderCallbackInterface.MARKET_ERROR:
|
||||
{
|
||||
Log.d(TAG, "Google Play service is not installed! You can get it here");
|
||||
AlertDialog MarketErrorMessage = new AlertDialog.Builder(mAppContext).create();
|
||||
MarketErrorMessage.setTitle("OpenCV Manager");
|
||||
MarketErrorMessage.setMessage("Package installation failed!");
|
||||
MarketErrorMessage.setCancelable(false); // This blocks the 'BACK' button
|
||||
MarketErrorMessage.setButton("OK", new OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
mAppContext.finish();
|
||||
}
|
||||
});
|
||||
MarketErrorMessage.show();
|
||||
} break;
|
||||
/** Package installation was canceled **/
|
||||
case LoaderCallbackInterface.INSTALL_CANCELED:
|
||||
{
|
||||
Log.d(TAG, "OpenCV library instalation was canceled by user");
|
||||
mAppContext.finish();
|
||||
} break;
|
||||
/** Application is incompatible with this version of OpenCV Manager. Possible Service update is needed **/
|
||||
case LoaderCallbackInterface.INCOMPATIBLE_MANAGER_VERSION:
|
||||
{
|
||||
Log.d(TAG, "OpenCV Manager Service is uncompatible with this app!");
|
||||
AlertDialog IncomatibilityMessage = new AlertDialog.Builder(mAppContext).create();
|
||||
IncomatibilityMessage.setTitle("OpenCV Manager");
|
||||
IncomatibilityMessage.setMessage("OpenCV Manager service is incompatible with this app. Update it!");
|
||||
IncomatibilityMessage.setCancelable(false); // This blocks the 'BACK' button
|
||||
IncomatibilityMessage.setButton("OK", new OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
mAppContext.finish();
|
||||
}
|
||||
});
|
||||
IncomatibilityMessage.show();
|
||||
}
|
||||
/** Other status, i.e. INIT_FAILED **/
|
||||
default:
|
||||
{
|
||||
Log.e(TAG, "OpenCV loading failed!");
|
||||
AlertDialog InitFailedDialog = new AlertDialog.Builder(mAppContext).create();
|
||||
InitFailedDialog.setTitle("OpenCV error");
|
||||
InitFailedDialog.setMessage("OpenCV was not initialised correctly. Application will be shut down");
|
||||
InitFailedDialog.setCancelable(false); // This blocks the 'BACK' button
|
||||
InitFailedDialog.setButton("OK", new OnClickListener() {
|
||||
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
mAppContext.finish();
|
||||
}
|
||||
});
|
||||
|
||||
InitFailedDialog.show();
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
public void onPackageInstall(final InstallCallbackInterface callback)
|
||||
{
|
||||
AlertDialog InstallMessage = new AlertDialog.Builder(mAppContext).create();
|
||||
InstallMessage.setTitle("Package not found");
|
||||
InstallMessage.setMessage(callback.getPackageName() + " package was not found! Try to install it?");
|
||||
InstallMessage.setCancelable(false); // This blocks the 'BACK' button
|
||||
InstallMessage.setButton("Yes", new OnClickListener()
|
||||
{
|
||||
public void onClick(DialogInterface dialog, int which)
|
||||
{
|
||||
callback.install();
|
||||
}
|
||||
});
|
||||
|
||||
InstallMessage.setButton2("No", new OnClickListener() {
|
||||
|
||||
public void onClick(DialogInterface dialog, int which)
|
||||
{
|
||||
callback.cancel();
|
||||
}
|
||||
});
|
||||
|
||||
InstallMessage.show();
|
||||
}
|
||||
|
||||
protected Activity mAppContext;
|
||||
private final static String TAG = "OpenCVLoader/BaseLoaderCallback";
|
||||
}
|
@@ -0,0 +1,21 @@
|
||||
package org.opencv.android;
|
||||
|
||||
/**
|
||||
* Installation callback interface
|
||||
*/
|
||||
public interface InstallCallbackInterface
|
||||
{
|
||||
/**
|
||||
* Target package name
|
||||
* @return Return target package name
|
||||
*/
|
||||
public String getPackageName();
|
||||
/**
|
||||
* Installation of package is approved
|
||||
*/
|
||||
public void install();
|
||||
/**
|
||||
* Installation canceled
|
||||
*/
|
||||
public void cancel();
|
||||
};
|
@@ -0,0 +1,44 @@
|
||||
package org.opencv.android;
|
||||
|
||||
/**
|
||||
* Interface for callback object in case of asynchronous initialization of OpenCV
|
||||
*/
|
||||
public interface LoaderCallbackInterface
|
||||
{
|
||||
/**
|
||||
* OpenCV initialization finished successfully
|
||||
*/
|
||||
static final int SUCCESS = 0;
|
||||
/**
|
||||
* OpenCV library installation via Google Play service was initialized. Application restart is required
|
||||
*/
|
||||
static final int RESTART_REQUIRED = 1;
|
||||
/**
|
||||
* Google Play (Android Market) cannot be invoked
|
||||
*/
|
||||
static final int MARKET_ERROR = 2;
|
||||
/**
|
||||
* OpenCV library installation was canceled by user
|
||||
*/
|
||||
static final int INSTALL_CANCELED = 3;
|
||||
/**
|
||||
* Version of OpenCV Manager Service is incompatible with this app. Service update is needed
|
||||
*/
|
||||
static final int INCOMPATIBLE_MANAGER_VERSION = 4;
|
||||
/**
|
||||
* OpenCV library initialization failed
|
||||
*/
|
||||
static final int INIT_FAILED = 0xff;
|
||||
|
||||
/**
|
||||
* Callback method that is called after OpenCV library initialization
|
||||
* @param status Status of initialization. See Initialization status constants
|
||||
*/
|
||||
public void onManagerConnected(int status);
|
||||
|
||||
/**
|
||||
* Callback method that is called in case when package installation is needed
|
||||
* @param callback Answer object with approve and cancel methods and package description
|
||||
*/
|
||||
public void onPackageInstall(InstallCallbackInterface callback);
|
||||
};
|
41
modules/java/generator/src/java/android+OpenCVLoader.java
Normal file
41
modules/java/generator/src/java/android+OpenCVLoader.java
Normal file
@@ -0,0 +1,41 @@
|
||||
package org.opencv.android;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
/**
|
||||
* Helper class provides common initialization methods for OpenCV library
|
||||
*/
|
||||
public class OpenCVLoader
|
||||
{
|
||||
/**
|
||||
* OpenCV Library version 2.4.0
|
||||
*/
|
||||
public static final String OPEN_CV_VERSION_2_4_0 = "2.4.0";
|
||||
|
||||
/**
|
||||
* OpenCV Library version 2.4.0
|
||||
*/
|
||||
public static final String OPEN_CV_VERSION_2_4_2 = "2.4.2";
|
||||
|
||||
/**
|
||||
* Load and initialize OpenCV library from current application package. Roughly it is analog of system.loadLibrary("opencv_java")
|
||||
* @return Return true is initialization of OpenCV was successful
|
||||
*/
|
||||
public static boolean initDebug()
|
||||
{
|
||||
return StaticHelper.initOpenCV();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load and initialize OpenCV library using OpenCV Engine service.
|
||||
* @param Version OpenCV Library version
|
||||
* @param AppContext Application context for connecting to service
|
||||
* @param Callback Object, that implements LoaderCallbackInterface for handling Connection status
|
||||
* @return Return true if initialization of OpenCV starts successfully
|
||||
*/
|
||||
public static boolean initAsync(String Version, Context AppContext,
|
||||
LoaderCallbackInterface Callback)
|
||||
{
|
||||
return AsyncServiceHelper.initOpenCV(Version, AppContext, Callback);
|
||||
}
|
||||
}
|
89
modules/java/generator/src/java/android+StaticHelper.java
Normal file
89
modules/java/generator/src/java/android+StaticHelper.java
Normal file
@@ -0,0 +1,89 @@
|
||||
package org.opencv.android;
|
||||
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
class StaticHelper {
|
||||
|
||||
public static boolean initOpenCV()
|
||||
{
|
||||
boolean result;
|
||||
String libs = "";
|
||||
|
||||
Log.d(TAG, "Trying to get library list");
|
||||
|
||||
try
|
||||
{
|
||||
System.loadLibrary("opencvinfo");
|
||||
libs = getLibraryList();
|
||||
}
|
||||
catch(UnsatisfiedLinkError e)
|
||||
{
|
||||
Log.e(TAG, "OpenCV error: Cannot load info library for OpenCV");
|
||||
}
|
||||
|
||||
Log.d(TAG, "Library list: \"" + libs + "\"");
|
||||
Log.d(TAG, "First attempt to load libs");
|
||||
if (initOpenCVLibs(libs))
|
||||
{
|
||||
Log.d(TAG, "First attempt to load libs is OK");
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.d(TAG, "First attempt to load libs fails");
|
||||
result = false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static boolean loadLibrary(String Name)
|
||||
{
|
||||
boolean result = true;
|
||||
|
||||
Log.d(TAG, "Trying to load library " + Name);
|
||||
try
|
||||
{
|
||||
System.loadLibrary(Name);
|
||||
Log.d(TAG, "OpenCV libs init was ok!");
|
||||
}
|
||||
catch(UnsatisfiedLinkError e)
|
||||
{
|
||||
Log.d(TAG, "Cannot load library \"" + Name + "\"");
|
||||
e.printStackTrace();
|
||||
result &= false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static boolean initOpenCVLibs(String Libs)
|
||||
{
|
||||
Log.d(TAG, "Trying to init OpenCV libs");
|
||||
|
||||
boolean result = true;
|
||||
|
||||
if ((null != Libs) && (Libs.length() != 0))
|
||||
{
|
||||
Log.d(TAG, "Trying to load libs by dependency list");
|
||||
StringTokenizer splitter = new StringTokenizer(Libs, ";");
|
||||
while(splitter.hasMoreTokens())
|
||||
{
|
||||
result &= loadLibrary(splitter.nextToken());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// If dependencies list is not defined or empty
|
||||
result &= loadLibrary("opencv_java");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static final String TAG = "OpenCV/StaticHelper";
|
||||
|
||||
private static native String getLibraryList();
|
||||
}
|
@@ -113,11 +113,6 @@ public class Utils {
|
||||
nMatToBitmap(m.nativeObj, b);
|
||||
}
|
||||
|
||||
// native stuff
|
||||
static {
|
||||
System.loadLibrary("opencv_java");
|
||||
}
|
||||
|
||||
private static native void nBitmapToMat(Bitmap b, long m_addr);
|
||||
|
||||
private static native void nMatToBitmap(long m_addr, Bitmap b);
|
7
modules/java/generator/src/java/android+sync.py
Normal file
7
modules/java/generator/src/java/android+sync.py
Normal file
@@ -0,0 +1,7 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
import os
|
||||
import shutil
|
||||
|
||||
for f in os.listdir("."):
|
||||
shutil.copyfile(f, os.path.join("../../../../../../modules/java/generator/src/java/", "android+" + f));
|
@@ -1082,13 +1082,6 @@ public class Mat {
|
||||
return nativeObj;
|
||||
}
|
||||
|
||||
//
|
||||
// native stuff
|
||||
//
|
||||
static {
|
||||
System.loadLibrary("opencv_java");
|
||||
}
|
||||
|
||||
// C++: Mat::Mat()
|
||||
private static native long n_Mat();
|
||||
|
@@ -0,0 +1,33 @@
|
||||
package org.opencv.engine;
|
||||
|
||||
/**
|
||||
* Class provides Java interface to OpenCV Engine Service. Is synchronous with native OpenCVEngine class.
|
||||
*/
|
||||
interface OpenCVEngineInterface
|
||||
{
|
||||
/**
|
||||
* @return Return service version
|
||||
*/
|
||||
int getEngineVersion();
|
||||
|
||||
/**
|
||||
* Find installed OpenCV library
|
||||
* @param OpenCV version
|
||||
* @return Return path to OpenCV native libs or empty string if OpenCV was not found
|
||||
*/
|
||||
String getLibPathByVersion(String version);
|
||||
|
||||
/**
|
||||
* Try to install defined version of OpenCV from Google Play (Android Market).
|
||||
* @param OpenCV version
|
||||
* @return Return true if installation was successful or OpenCV package has been already installed
|
||||
*/
|
||||
boolean installVersion(String version);
|
||||
|
||||
/**
|
||||
* Return list of libraries in loading order separated by ";" symbol
|
||||
* @param OpenCV version
|
||||
* @return Return OpenCV libraries names separated by symbol ";" in loading order
|
||||
*/
|
||||
String getLibraryList(String version);
|
||||
}
|
@@ -194,12 +194,6 @@ public class VideoCapture {
|
||||
super.finalize();
|
||||
}
|
||||
|
||||
// native stuff
|
||||
|
||||
static {
|
||||
System.loadLibrary("opencv_java");
|
||||
}
|
||||
|
||||
// C++: VideoCapture::VideoCapture()
|
||||
private static native long n_VideoCapture();
|
||||
|
@@ -721,10 +721,4 @@ public class Converters {
|
||||
llb.add(lb);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static {
|
||||
System.loadLibrary("opencv_java");
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user