Merge pull request #7289 from alalek:android24

This commit is contained in:
Alexander Alekhin 2016-09-16 15:55:39 +00:00
commit 14ac55d05e
19 changed files with 305 additions and 34 deletions

View File

@ -3,13 +3,13 @@
#### Resources
* Homepage: <http://opencv.org>
* Docs: <http://docs.opencv.org>
* Docs: <http://docs.opencv.org/2.4/>
* Q&A forum: <http://answers.opencv.org>
* Issue tracking: <http://code.opencv.org>
* Issue tracking: <https://github.com/opencv/opencv/issues>
#### Contributing
Please read before starting work on a pull request: <http://code.opencv.org/projects/opencv/wiki/How_to_contribute>
Please read before starting work on a pull request: <https://github.com/opencv/opencv/wiki/How_to_contribute>
Summary of guidelines:

View File

@ -274,6 +274,17 @@ macro(add_android_project target path)
file(GLOB_RECURSE android_proj_jni_files "${path}/jni/*.c" "${path}/jni/*.h" "${path}/jni/*.cpp" "${path}/jni/*.hpp")
ocv_list_filterout(android_proj_jni_files "\\\\.svn")
foreach(lib "opencv_java")
get_property(f TARGET ${lib} PROPERTY LOCATION)
get_filename_component(f_name ${f} NAME)
add_custom_command(
OUTPUT "${android_proj_bin_dir}/libs/${ANDROID_NDK_ABI_NAME}/${f_name}"
COMMAND ${CMAKE_COMMAND} -E copy "${f}" "${android_proj_bin_dir}/libs/${ANDROID_NDK_ABI_NAME}/${f_name}"
DEPENDS "${lib}" VERBATIM
COMMENT "Embedding ${f}")
list(APPEND android_proj_file_deps "${android_proj_bin_dir}/libs/${ANDROID_NDK_ABI_NAME}/${f_name}")
endforeach()
if(android_proj_jni_files AND EXISTS ${path}/jni/Android.mk AND NOT DEFINED JNI_LIB_NAME)
# find local module name in Android.mk file to build native lib
file(STRINGS "${path}/jni/Android.mk" JNI_LIB_NAME REGEX "LOCAL_MODULE[ ]*:=[ ]*.*" )
@ -307,6 +318,7 @@ macro(add_android_project target path)
# copy opencv_java, tbb if it is shared and dynamicuda if present if FORCE_EMBED_OPENCV flag is set
if(android_proj_FORCE_EMBED_OPENCV)
set(native_deps ${android_proj_NATIVE_DEPS})
list(REMOVE_ITEM native_deps "opencv_java")
# filter out gpu module as it is always static library on Android
list(REMOVE_ITEM native_deps "opencv_gpu")
if(ENABLE_DYNAMIC_CUDA)

View File

@ -123,10 +123,11 @@ if(PYTHON_EXECUTABLE)
find_host_program(SPHINX_BUILD sphinx-build)
if(SPHINX_BUILD)
execute_process(COMMAND "${SPHINX_BUILD}"
OUTPUT_QUIET
ERROR_VARIABLE SPHINX_OUTPUT
ERROR_VARIABLE SPHINX_STDERR
OUTPUT_VARIABLE SPHINX_STDOUT
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(SPHINX_OUTPUT MATCHES "Sphinx v([0-9][^ \n]*)")
if(SPHINX_STDERR MATCHES "Sphinx v([0-9][^ \n]*)"
OR SPHINX_STDOUT MATCHES "Sphinx v([0-9][^ \n]*)")
set(SPHINX_VERSION "${CMAKE_MATCH_1}")
set(HAVE_SPHINX 1)
message(STATUS "Found Sphinx ${SPHINX_VERSION}: ${SPHINX_BUILD}")

View File

@ -110,6 +110,10 @@ else
OPENCV_INSTALL_MODULES:=on
endif
ifeq ($(OPENCV_INSTALL_MODULES),)
OPENCV_INSTALL_MODULES:=on
endif
define add_opencv_module
include $(CLEAR_VARS)
LOCAL_MODULE:=opencv_$1

View File

@ -40,9 +40,7 @@ endif(HAVE_DOC_GENERATOR)
# ========= Sphinx docs =========
if(BUILD_DOCS AND HAVE_SPHINX)
if(NOT INSTALL_CREATE_DISTRIB)
list(APPEND DOC_LIST "${OpenCV_SOURCE_DIR}/doc/haartraining.htm")
endif()
# build lists of documentation files and generate table of contents for reference manual
set(DOC_FAKE_ROOT "${CMAKE_CURRENT_BINARY_DIR}/fake-root")

View File

@ -315,7 +315,7 @@ extlinks = {
# 'opencv_group' : ('http://answers.opencv.org/%s', None),
'opencv_qa' : ('http://answers.opencv.org/%s', None),
'how_to_contribute' : ('http://code.opencv.org/projects/opencv/wiki/How_to_contribute/%s', None),
'how_to_contribute' : ('https://github.com/opencv/opencv/wiki/How_to_contribute/%s', None),
'cvt_color' : ('http://docs.opencv.org/modules/imgproc/doc/miscellaneous_transformations.html?highlight=cvtcolor#cvtcolor%s', None),
'imread' : ('http://docs.opencv.org/modules/highgui/doc/reading_and_writing_images_and_video.html?highlight=imread#imread%s', None),

View File

@ -22,7 +22,7 @@ Code
* In this tutorial, we intend to use *random* values for the drawing parameters. Also, we intend to populate our image with a big number of geometric figures. Since we will be initializing them in a random fashion, this process will be automatic and made by using *loops* .
* This code is in your OpenCV sample folder. Otherwise you can grab it from `here <http://code.opencv.org/projects/opencv/repository/revisions/master/raw/samples/cpp/tutorial_code/core/Matrix/Drawing_2.cpp>`_ .
* This code is in your OpenCV sample folder. Otherwise you can grab it from `here <https://github.com/opencv/opencv/blob/2.4/samples/cpp/tutorial_code/core/Matrix/Drawing_2.cpp>`_ .
Explanation
============

View File

@ -22,7 +22,7 @@ Theory
Code
====
This tutorial code's is shown lines below. You can also download it from `here <http://code.opencv.org/projects/opencv/repository/revisions/master/raw/samples/cpp/tutorial_code/features2D/SURF_detector.cpp>`_
This tutorial code's is shown lines below. You can also download it from `here <https://github.com/opencv/opencv/blob/2.4/samples/cpp/tutorial_code/features2D/SURF_detector.cpp>`_
.. code-block:: cpp

View File

@ -20,7 +20,7 @@ Theory
Code
====
This tutorial code's is shown lines below. You can also download it from `here <http://code.opencv.org/projects/opencv/repository/revisions/master/raw/samples/cpp/tutorial_code/features2D/SURF_Homography.cpp>`_
This tutorial code's is shown lines below. You can also download it from `here <https://github.com/opencv/opencv/blob/2.4/samples/cpp/tutorial_code/features2D/SURF_Homography.cpp>`_
.. code-block:: cpp

View File

@ -48,11 +48,7 @@ The structure of package contents looks as follows:
::
OpenCV-2.4.11-android-sdk
|_ apk
| |_ OpenCV_2.4.11_binary_pack_armv7a.apk
| |_ OpenCV_2.4.11_Manager_2.20_XXX.apk
|
OpenCV-2.4.13-android-sdk
|_ doc
|_ samples
|_ sdk

View File

@ -55,14 +55,14 @@ Manager to access OpenCV libraries externally installed in the target system.
:guilabel:`File -> Import -> Existing project in your workspace`.
Press :guilabel:`Browse` button and locate OpenCV4Android SDK
(:file:`OpenCV-2.4.11-android-sdk/sdk`).
(:file:`OpenCV-2.4.13-android-sdk/sdk`).
.. image:: images/eclipse_opencv_dependency0.png
:alt: Add dependency from OpenCV library
:align: center
#. In application project add a reference to the OpenCV Java SDK in
:guilabel:`Project -> Properties -> Android -> Library -> Add` select ``OpenCV Library - 2.4.11``.
:guilabel:`Project -> Properties -> Android -> Library -> Add` select ``OpenCV Library - 2.4.13``.
.. image:: images/eclipse_opencv_dependency1.png
:alt: Add dependency from OpenCV library
@ -128,27 +128,27 @@ described above.
#. Add the OpenCV library project to your workspace the same way as for the async initialization
above. Use menu :guilabel:`File -> Import -> Existing project in your workspace`,
press :guilabel:`Browse` button and select OpenCV SDK path
(:file:`OpenCV-2.4.11-android-sdk/sdk`).
(:file:`OpenCV-2.4.13-android-sdk/sdk`).
.. image:: images/eclipse_opencv_dependency0.png
:alt: Add dependency from OpenCV library
:align: center
#. In the application project add a reference to the OpenCV4Android SDK in
:guilabel:`Project -> Properties -> Android -> Library -> Add` select ``OpenCV Library - 2.4.11``;
:guilabel:`Project -> Properties -> Android -> Library -> Add` select ``OpenCV Library - 2.4.13``;
.. image:: images/eclipse_opencv_dependency1.png
:alt: Add dependency from OpenCV library
:align: center
#. If your application project **doesn't have a JNI part**, just copy the corresponding OpenCV
native libs from :file:`<OpenCV-2.4.11-android-sdk>/sdk/native/libs/<target_arch>` to your
native libs from :file:`<OpenCV-2.4.13-android-sdk>/sdk/native/libs/<target_arch>` to your
project directory to folder :file:`libs/<target_arch>`.
In case of the application project **with a JNI part**, instead of manual libraries copying you
need to modify your ``Android.mk`` file:
add the following two code lines after the ``"include $(CLEAR_VARS)"`` and before
``"include path_to_OpenCV-2.4.11-android-sdk/sdk/native/jni/OpenCV.mk"``
``"include path_to_OpenCV-2.4.13-android-sdk/sdk/native/jni/OpenCV.mk"``
.. code-block:: make
:linenos:
@ -221,7 +221,7 @@ taken:
.. code-block:: make
include C:\Work\OpenCV4Android\OpenCV-2.4.11-android-sdk\sdk\native\jni\OpenCV.mk
include C:\Work\OpenCV4Android\OpenCV-2.4.13-android-sdk\sdk\native\jni\OpenCV.mk
Should be inserted into the :file:`jni/Android.mk` file **after** this line:
@ -230,7 +230,8 @@ taken:
include $(CLEAR_VARS)
#. Several variables can be used to customize OpenCV stuff, but you **don't need** to use them when
your application uses the `async initialization` via the `OpenCV Manager` API.
your application uses the `async initialization` via the `OpenCV Manager` API
(It is not recommended since OpenCV 2.4.13).
.. note:: These variables should be set **before** the ``"include .../OpenCV.mk"`` line:

View File

@ -5,10 +5,6 @@ OpenCV 2.4 now comes with the very new :ocv:class:`FaceRecognizer` class for fac
These documents are the help I have wished for, when I was working myself into face recognition. I hope you also think the new :ocv:class:`FaceRecognizer` is a useful addition to OpenCV.
Please issue any feature requests and/or bugs on the official OpenCV bug tracker at:
* http://code.opencv.org/projects/opencv/issues
Contents
========

View File

@ -1,12 +1,15 @@
package org.opencv.android;
import android.content.Context;
import android.util.Log;
/**
* Helper class provides common initialization methods for OpenCV library.
*/
public class OpenCVLoader
{
private static final String TAG = "OpenCVLoader";
/**
* OpenCV Library version 2.4.2.
*/
@ -62,6 +65,11 @@ public class OpenCVLoader
*/
public static final String OPENCV_VERSION_2_4_12 = "2.4.12";
/**
* OpenCV Library version 2.4.13.
*/
public static final String OPENCV_VERSION_2_4_13 = "2.4.13";
/**
* Loads and initializes OpenCV library from current application package. Roughly, it's an analog of system.loadLibrary("opencv_java").
* @return Returns true is initialization of OpenCV was successful.
@ -91,6 +99,11 @@ public class OpenCVLoader
public static boolean initAsync(String Version, Context AppContext,
LoaderCallbackInterface Callback)
{
if (initDebug()) {
Callback.onManagerConnected(LoaderCallbackInterface.SUCCESS);
return true;
}
Log.w(TAG, "OpenCV binaries are not packaged with application. Trying to use OpenCV Manager...");
return AsyncServiceHelper.initOpenCV(Version, AppContext, Callback);
}
}

View File

@ -0,0 +1,243 @@
#!/usr/bin/env python
import os, sys, subprocess, argparse, shutil, glob, re
import logging as log
import xml.etree.ElementTree as ET
class Fail(Exception):
def __init__(self, text=None):
self.t = text
def __str__(self):
return "ERROR" if self.t is None else self.t
def execute(cmd, shell=False, allowFail=False):
try:
log.info("Executing: %s" % cmd)
retcode = subprocess.call(cmd, shell=shell)
if retcode < 0:
raise Fail("Child was terminated by signal:" %s -retcode)
elif retcode > 0 and not allowFail:
raise Fail("Child returned: %s" % retcode)
except OSError as e:
raise Fail("Execution failed: %d / %s" % (e.errno, e.strerror))
def rm_one(d):
d = os.path.abspath(d)
if os.path.exists(d):
if os.path.isdir(d):
log.info("Removing dir: %s", d)
shutil.rmtree(d)
elif os.path.isfile(d):
log.info("Removing file: %s", d)
os.remove(d)
def check_dir(d, create=False, clean=False):
d = os.path.abspath(d)
log.info("Check dir %s (create: %s, clean: %s)", d, create, clean)
if os.path.exists(d):
if not os.path.isdir(d):
raise Fail("Not a directory: %s" % d)
if clean:
for x in glob.glob(os.path.join(d, "*")):
rm_one(x)
else:
if create:
os.makedirs(d)
return d
def determine_opencv_version(version_hpp_path):
# version in 2.4 - CV_VERSION_EPOCH.CV_VERSION_MAJOR.CV_VERSION_MINOR.CV_VERSION_REVISION
# version in master - CV_VERSION_MAJOR.CV_VERSION_MINOR.CV_VERSION_REVISION-CV_VERSION_STATUS
with open(version_hpp_path, "rt") as f:
data = f.read()
epoch = re.search(r'^#define\W+CV_VERSION_EPOCH\W+(\d+)$', data, re.MULTILINE).group(1)
major = re.search(r'^#define\W+CV_VERSION_MAJOR\W+(\d+)$', data, re.MULTILINE).group(1)
minor = re.search(r'^#define\W+CV_VERSION_MINOR\W+(\d+)$', data, re.MULTILINE).group(1)
revision = re.search(r'^#define\W+CV_VERSION_REVISION\W+(\d+)$', data, re.MULTILINE).group(1)
revision = '' if revision == '0' else '.' + revision
return "%(epoch)s.%(major)s.%(minor)s%(revision)s" % locals()
#===================================================================================================
class ABI:
def __init__(self, platform_id, name, toolchain, api_level=8, cmake_name=None):
self.platform_id = platform_id # platform code to add to apk version (for cmake)
self.name = name # general name (official Android ABI identifier)
self.toolchain = toolchain # toolchain identifier (for cmake)
self.api_level = api_level
self.cmake_name = cmake_name # name of android toolchain (for cmake)
if self.cmake_name is None:
self.cmake_name = self.name
def __str__(self):
return "%s (%s)" % (self.name, self.toolchain)
ABIs = [
ABI("2", "armeabi-v7a", "arm-linux-androideabi-4.6", cmake_name="armeabi-v7a with NEON"),
ABI("1", "armeabi", "arm-linux-androideabi-4.6"),
ABI("4", "x86", "x86-clang3.1", api_level=9),
ABI("6", "mips", "mipsel-linux-android-4.6", api_level=9)
]
#===================================================================================================
class Builder:
def __init__(self, workdir, opencvdir):
self.workdir = check_dir(workdir, create=True)
self.opencvdir = check_dir(opencvdir)
self.libdest = check_dir(os.path.join(self.workdir, "o4a"), create=True, clean=True)
self.docdest = check_dir(os.path.join(self.workdir, "javadoc"), create=True, clean=True)
self.resultdest = check_dir(os.path.join(self.workdir, "OpenCV-android-sdk"), create=True, clean=True)
self.opencv_version = determine_opencv_version(os.path.join(self.opencvdir, "modules", "core", "include", "opencv2", "core", "version.hpp"))
self.use_ccache = True
def get_toolchain_file(self):
return os.path.join(self.opencvdir, "platforms", "android", "android.toolchain.cmake")
def clean_library_build_dir(self):
for d in ["CMakeCache.txt", "CMakeFiles/", "bin/", "libs/", "lib/", "package/", "install/samples/"]:
rm_one(d)
def build_library(self, abi, do_install, build_docs):
cmd = [
"cmake",
"-GNinja",
"-DCMAKE_TOOLCHAIN_FILE='%s'" % self.get_toolchain_file(),
"-DINSTALL_CREATE_DISTRIB=ON",
#"-DWITH_OPENCL=OFF",
"-DWITH_CUDA=OFF", "-DBUILD_opencv_gpu=OFF",
"-DBUILD_opencv_nonfree=OFF",
"-DWITH_TBB=OFF",
"-DWITH_IPP=OFF",
"-DBUILD_EXAMPLES=OFF",
"-DBUILD_TESTS=OFF",
"-DBUILD_PERF_TESTS=OFF",
"-DBUILD_DOCS=OFF",
"-DBUILD_ANDROID_EXAMPLES=ON",
"-DINSTALL_ANDROID_EXAMPLES=ON",
"-DANDROID_STL=gnustl_static",
"-DANDROID_NATIVE_API_LEVEL=%s" % abi.api_level,
"-DANDROID_ABI='%s'" % abi.cmake_name,
"-DANDROID_TOOLCHAIN_NAME=%s" % abi.toolchain
]
cmd.append(self.opencvdir)
if self.use_ccache == True:
cmd.append("-DNDK_CCACHE=ccache")
if do_install:
cmd.extend(["-DBUILD_TESTS=ON", "-DINSTALL_TESTS=ON"])
if do_install and build_docs:
cmd.extend(["-DBUILD_DOCS=ON"])
execute(cmd)
if do_install:
execute(["cmake", "--build", "."])
if do_install and build_docs:
execute(["cmake", "--build", ".", "--target", "docs"])
for c in ["libs", "dev", "java", "samples"] + (["docs"] if do_install and build_docs else []):
execute(["cmake", "-DCOMPONENT=%s" % c, "-P", "cmake_install.cmake"])
else:
execute(["cmake", "--build", ".", "--target", "install/strip"])
def build_javadoc(self):
classpaths = [os.path.join(self.libdest, "bin", "classes")]
for dir, _, files in os.walk(os.environ["ANDROID_SDK"]):
for f in files:
if f == "android.jar" or f == "annotations.jar":
classpaths.append(os.path.join(dir, f))
cmd = [
"javadoc",
"-encoding", "UTF-8",
"-header", "OpenCV %s" % self.opencv_version,
"-nodeprecated",
"-footer", '<a href="http://docs.opencv.org">OpenCV %s Documentation</a>' % self.opencv_version,
"-public",
"-sourcepath", os.path.join(self.libdest, "src"),
"-d", self.docdest,
"-classpath", ":".join(classpaths)
]
for _, dirs, _ in os.walk(os.path.join(self.libdest, "src", "org", "opencv")):
cmd.extend(["org.opencv." + d for d in dirs])
execute(cmd, allowFail=True) # FIXIT javadoc currenly reports some errors
def gather_results(self, with_samples_apk):
# Copy all files
root = os.path.join(self.libdest, "install")
for item in os.listdir(root):
name = item
item = os.path.join(root, item)
if os.path.isdir(item):
log.info("Copy dir: %s", item)
shutil.copytree(item, os.path.join(self.resultdest, name))
elif os.path.isfile(item):
log.info("Copy file: %s", item)
shutil.copy2(item, os.path.join(self.resultdest, name))
# Copy javadoc
log.info("Copy docs: %s", self.docdest)
shutil.copytree(self.docdest, os.path.join(self.resultdest, "sdk", "java", "javadoc"))
# Clean samples
path = os.path.join(self.resultdest, "samples")
for item in os.listdir(path):
item = os.path.join(path, item)
if os.path.isdir(item):
for name in ["build.xml", "local.properties", "proguard-project.txt"]:
rm_one(os.path.join(item, name))
if not with_samples_apk:
if re.search(r'\.apk$', item): # reduce size of SDK
rm_one(item)
#===================================================================================================
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Build OpenCV for Android SDK')
parser.add_argument("work_dir", help="Working directory (and output)")
parser.add_argument("opencv_dir", help="Path to OpenCV source dir")
parser.add_argument('--ndk_path', help="Path to Android NDK to use for build")
parser.add_argument('--sdk_path', help="Path to Android SDK to use for build")
parser.add_argument('--build_doc', action="store_true", help="Build documentation")
parser.add_argument('--build_javadoc', action="store_true", help="Build javadoc")
parser.add_argument('--no_ccache', action="store_true", help="Do not use ccache during library build")
parser.add_argument('--with_samples_apk', action="store_true", help="Include samples APKs")
args = parser.parse_args()
log.basicConfig(format='%(message)s', level=log.DEBUG)
log.debug("Args: %s", args)
if args.ndk_path is not None:
os.environ["ANDROID_NDK"] = args.ndk_path
if args.sdk_path is not None:
os.environ["ANDROID_SDK"] = args.sdk_path
log.info("Android NDK path: %s", os.environ["ANDROID_NDK"])
log.info("Android SDK path: %s", os.environ["ANDROID_SDK"])
builder = Builder(args.work_dir, args.opencv_dir)
if args.no_ccache:
builder.use_ccache = False
log.info("Detected OpenCV version: %s", builder.opencv_version)
for i, abi in enumerate(ABIs):
do_install = (i == 0)
log.info("=====")
log.info("===== Building library for %s", abi)
log.info("=====")
os.chdir(builder.libdest)
builder.clean_library_build_dir()
builder.build_library(abi, do_install, build_docs=args.build_doc)
if args.build_doc or args.build_javadoc:
builder.build_javadoc()
builder.gather_results(with_samples_apk=args.with_samples_apk)
log.info("=====")
log.info("===== Build finished")
log.info("=====")
log.info("SDK location: %s", builder.resultdest)
log.info("Documentation location: %s", builder.docdest)

View File

@ -2,5 +2,3 @@ if(BUILD_ANDROID_SERVICE)
add_subdirectory(engine)
#add_subdirectory(engine_test)
endif()
install(FILES "readme.txt" DESTINATION "apk/" COMPONENT libs)

View File

@ -79,3 +79,11 @@ OpenCV version constants
.. data:: OPENCV_VERSION_2_4_11
OpenCV Library version 2.4.11
.. data:: OPENCV_VERSION_2_4_12
OpenCV Library version 2.4.12
.. data:: OPENCV_VERSION_2_4_13
OpenCV Library version 2.4.13

View File

@ -1,6 +1,8 @@
How to select the proper version of OpenCV Manager
--------------------------------------------------
DEPRECATED: This information is outdated since OpenCV 2.4.12
Since version 1.7 several packages of OpenCV Manager are built. Every package is targeted for some
specific hardware platform and includes corresponding OpenCV binaries. So, in most cases OpenCV
Manager uses built-in version of OpenCV. Separate package with OpenCV binaries is currently used in

View File

@ -3,7 +3,6 @@ LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
#OPENCV_CAMERA_MODULES:=off
#OPENCV_INSTALL_MODULES:=off
#OPENCV_LIB_TYPE:=SHARED
include ../../sdk/native/jni/OpenCV.mk

View File

@ -30,7 +30,7 @@ static void help()
"Using OpenCV version " << CV_VERSION << "\n\n"
" 1) This demo is mainly based on work from Javier Barandiaran Martirena\n"
" See this page http://code.opencv.org/projects/opencv/wiki/Posit.\n"
" See this page https://github.com/opencv/opencv/wiki/Posit .\n"
" 2) This is a demo to illustrate how to use **OpenGL Callback**.\n"
" 3) You need Qt binding to compile this sample with OpenGL support enabled.\n"
" 4) The features' detection is very basic and could highly be improved\n"