diff --git a/3rdparty/libjasper/CMakeLists.txt b/3rdparty/libjasper/CMakeLists.txt index a6fb71ec5..42855e2a6 100644 --- a/3rdparty/libjasper/CMakeLists.txt +++ b/3rdparty/libjasper/CMakeLists.txt @@ -24,6 +24,7 @@ if(WIN32 AND NOT MINGW) endif(WIN32 AND NOT MINGW) ocv_warnings_disable(CMAKE_C_FLAGS -Wno-implicit-function-declaration -Wno-uninitialized -Wmissing-prototypes -Wmissing-declarations -Wunused -Wshadow -Wsign-compare) +ocv_warnings_disable(CMAKE_C_FLAGS -Wunused-parameter) # clang ocv_warnings_disable(CMAKE_C_FLAGS /wd4013 /wd4018 /wd4101 /wd4244 /wd4267 /wd4715) # vs2005 if(UNIX) diff --git a/3rdparty/libjpeg/CMakeLists.txt b/3rdparty/libjpeg/CMakeLists.txt index 708e63e25..b4000a40a 100644 --- a/3rdparty/libjpeg/CMakeLists.txt +++ b/3rdparty/libjpeg/CMakeLists.txt @@ -26,6 +26,7 @@ if(CMAKE_COMPILER_IS_GNUCXX) endif() ocv_warnings_disable(CMAKE_C_FLAGS -Wcast-align -Wshadow -Wunused) +ocv_warnings_disable(CMAKE_C_FLAGS -Wunused-parameter) # clang set_target_properties(${JPEG_LIBRARY} PROPERTIES OUTPUT_NAME ${JPEG_LIBRARY} diff --git a/3rdparty/libtiff/CMakeLists.txt b/3rdparty/libtiff/CMakeLists.txt index 25ff0d94e..46fef61c7 100644 --- a/3rdparty/libtiff/CMakeLists.txt +++ b/3rdparty/libtiff/CMakeLists.txt @@ -89,6 +89,7 @@ endif(WIN32) ocv_warnings_disable(CMAKE_C_FLAGS -Wno-unused-but-set-variable -Wmissing-prototypes -Wmissing-declarations -Wundef -Wunused -Wsign-compare -Wcast-align -Wshadow -Wno-maybe-uninitialized -Wno-pointer-to-int-cast -Wno-int-to-pointer-cast) +ocv_warnings_disable(CMAKE_C_FLAGS -Wunused-parameter) # clang ocv_warnings_disable(CMAKE_CXX_FLAGS -Wmissing-declarations -Wunused-parameter) ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4018 /wd4100 /wd4127 /wd4311 /wd4701 /wd4706) # vs2005 ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4244) # vs2008 diff --git a/3rdparty/tbb/CMakeLists.txt b/3rdparty/tbb/CMakeLists.txt index bf91f4d8b..a362e0460 100644 --- a/3rdparty/tbb/CMakeLists.txt +++ b/3rdparty/tbb/CMakeLists.txt @@ -5,40 +5,46 @@ endif() project(tbb) -# 4.1 - works fine -set(tbb_ver "tbb41_20120718oss") -set(tbb_url "http://threadingbuildingblocks.org/uploads/77/188/4.1/tbb41_20120718oss_src.tgz") -set(tbb_md5 "31b9ec300f3d09da2504d5d882788dd4") +# 4.1 update 1 - works fine +set(tbb_ver "tbb41_20121003oss") +set(tbb_url "http://threadingbuildingblocks.org/sites/default/files/software_releases/source/tbb41_20121003oss_src.tgz") +set(tbb_md5 "2a684fefb855d2d0318d1ef09afa75ff") set(tbb_version_file "version_string.ver") +# 4.1 - works fine +#set(tbb_ver "tbb41_20120718oss") +#set(tbb_url "http://threadingbuildingblocks.org/sites/default/files/software_releases/source/tbb41_20120718oss_src.tgz") +#set(tbb_md5 "31b9ec300f3d09da2504d5d882788dd4") +#set(tbb_version_file "version_string.ver") + # 4.0 update 5 - works fine #set(tbb_ver "tbb40_20120613oss") -#set(tbb_url "http://threadingbuildingblocks.org/uploads/77/187/4.0%20update%205/tbb40_20120613oss_src.tgz") +#set(tbb_url "http://threadingbuildingblocks.org/sites/default/files/software_releases/source/tbb40_20120613oss_src.tgz") #set(tbb_md5 "da01ed74944ec5950cfae3476901a172") #set(tbb_version_file "version_string.ver") # 4.0 update 4 - works fine #set(tbb_ver "tbb40_20120408oss") -#set(tbb_url "http://threadingbuildingblocks.org/uploads/77/185/4.0%20update%204/tbb40_20120408oss_src.tgz") +#set(tbb_url "http://threadingbuildingblocks.org/sites/default/files/software_releases/source/tbb40_20120408oss_src.tgz") #set(tbb_md5 "734b356da7fe0ed308741f3e6018251e") #set(tbb_version_file "version_string.ver") # 4.0 update 3 - build broken #set(tbb_ver "tbb40_20120201oss") -#set(tbb_url "http://threadingbuildingblocks.org/uploads/77/182/4.0%20update%203/tbb40_20120201oss_src.tgz") +#set(tbb_url "http://threadingbuildingblocks.org/sites/default/files/software_releases/source/tbb40_20120201oss_src.tgz") #set(tbb_md5 "4669e7d4adee018de7a7b8b972987218") #set(tbb_version_file "version_string.tmp") # 4.0 update 2 - works fine #set(tbb_ver "tbb40_20111130oss") -#set(tbb_url "http://threadingbuildingblocks.org/uploads/77/180/4.0%20update%202/tbb40_20111130oss_src.tgz") +#set(tbb_url "http://threadingbuildingblocks.org/sites/default/files/software_releases/source/tbb40_20111130oss_src.tgz") #set(tbb_md5 "1e6926b21e865e79772119cd44fc3ad8") #set(tbb_version_file "version_string.tmp") #set(tbb_need_GENERIC_DWORD_LOAD_STORE TRUE) # 4.0 update 1 - works fine #set(tbb_ver "tbb40_20111003oss") -#set(tbb_url "http://threadingbuildingblocks.org/uploads/77/177/4.0%20update%201/tbb40_20111003oss_src.tgz") +#set(tbb_url "http://threadingbuildingblocks.org/sites/default/files/software_releases/source/tbb40_20111003oss_src.tgz") #set(tbb_md5 "7b5d94eb35a563b29ef402e0fd8f15c9") #set(tbb_version_file "version_string.tmp") #set(tbb_need_GENERIC_DWORD_LOAD_STORE TRUE) @@ -123,6 +129,11 @@ add_definitions(-D__TBB_DYNAMIC_LOAD_ENABLED=0 #required -DDO_ITT_NOTIFY=0 #it seems that we don't need these notifications ) +if(ANDROID_COMPILER_IS_CLANG) + add_definitions(-D__TBB_GCC_BUILTIN_ATOMICS_PRESENT=1) + ocv_warnings_disable(CMAKE_CXX_FLAGS -Wmissing-prototypes) +endif() + if(tbb_need_GENERIC_DWORD_LOAD_STORE) #needed by TBB 4.0 update 1,2; fixed in TBB 4.0 update 3 but it has 2 new problems add_definitions(-D__TBB_USE_GENERIC_DWORD_LOAD_STORE=1) diff --git a/CMakeLists.txt b/CMakeLists.txt index adc457c4c..7123eaf19 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -468,7 +468,7 @@ if(BUILD_ANDROID_PACKAGE) add_subdirectory(android/package) endif() -if (ANDROID AND NOT BUILD_ANDROID_SERVICE AND NOT BUILD_ANDROID_PACKAGE AND NOT BUILD_CAMERA_WRAPER) +if (ANDROID) add_subdirectory(android/libinfo) endif() diff --git a/android/android.toolchain.cmake b/android/android.toolchain.cmake index 7ab966835..25cef0f98 100644 --- a/android/android.toolchain.cmake +++ b/android/android.toolchain.cmake @@ -1,7 +1,37 @@ +# Copyright (c) 2010-2011, Ethan Rublee +# Copyright (c) 2011-2012, Andrey Kamaev +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 3. The name of the copyright holders may be used to endorse or promote +# products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + # ------------------------------------------------------------------------------ # Android CMake toolchain file, for use with the Android NDK r5-r8 # Requires cmake 2.6.3 or newer (2.8.5 or newer is recommended). -# See home page: http://code.google.com/p/android-cmake/ +# See home page: https://github.com/taka-no-me/android-cmake # # The file is mantained by the OpenCV project. The latest version can be get at # http://code.opencv.org/projects/opencv/repository/revisions/master/changes/android/android.toolchain.cmake @@ -64,6 +94,20 @@ # ANDROID_NATIVE_API_LEVEL=android-8 - level of Android API compile for. # Option is read-only when standalone toolchain is used. # +# ANDROID_TOOLCHAIN_NAME=arm-linux-androideabi-4.6 - the name of compiler +# toolchain to be used. The list of possible values depends on the NDK +# version. For NDK r8c the possible values are: +# +# * arm-linux-androideabi-4.4.3 +# * arm-linux-androideabi-4.6 +# * arm-linux-androideabi-clang3.1 +# * mipsel-linux-android-4.4.3 +# * mipsel-linux-android-4.6 +# * mipsel-linux-android-clang3.1 +# * x86-4.4.3 +# * x86-4.6 +# * x86-clang3.1 +# # ANDROID_FORCE_ARM_BUILD=OFF - set ON to generate 32-bit ARM instructions # instead of Thumb. Is not available for "x86" (inapplicable) and # "armeabi-v6 with VFP" (is forced to be ON) ABIs. @@ -147,13 +191,9 @@ # under the ${LIBRARY_OUTPUT_PATH_ROOT}/libs/${ANDROID_NDK_ABI_NAME} # (depending on the target ABI). This is convenient for Android packaging. # -# Authors: -# Ethan Rublee ethan.ruble@gmail.com -# Andrey Kamaev andrey.kamaev@itseez.com -# # Change Log: # - initial version December 2010 -# - modified April 2011 +# - April 2011 # [+] added possibility to build with NDK (without standalone toolchain) # [+] support cross-compilation on Windows (native, no cygwin support) # [+] added compiler option to force "char" type to be signed @@ -164,13 +204,13 @@ # [+] EXECUTABLE_OUTPUT_PATH is set by toolchain (required on Windows) # [~] Fixed bug with ANDROID_API_LEVEL variable # [~] turn off SWIG search if it is not found first time -# - modified May 2011 +# - May 2011 # [~] ANDROID_LEVEL is renamed to ANDROID_API_LEVEL # [+] ANDROID_API_LEVEL is detected by toolchain if not specified # [~] added guard to prevent changing of output directories on the first # cmake pass # [~] toolchain exits with error if ARM_TARGET is not recognized -# - modified June 2011 +# - June 2011 # [~] default NDK path is updated for version r5c # [+] variable CMAKE_SYSTEM_PROCESSOR is set based on ARM_TARGET # [~] toolchain install directory is added to linker paths @@ -178,13 +218,13 @@ # [+] added macro find_host_package, find_host_program to search # packages/programs on the host system # [~] fixed path to STL library -# - modified July 2011 +# - July 2011 # [~] fixed options caching # [~] search for all supported NDK versions # [~] allowed spaces in NDK path -# - modified September 2011 +# - September 2011 # [~] updated for NDK r6b -# - modified November 2011 +# - November 2011 # [*] rewritten for NDK r7 # [+] x86 toolchain support (experimental) # [+] added "armeabi-v6 with VFP" ABI for ARMv6 processors. @@ -197,37 +237,37 @@ # [~] ARM_TARGET is renamed to ANDROID_ABI # [~] ARMEABI_NDK_NAME is renamed to ANDROID_NDK_ABI_NAME # [~] ANDROID_API_LEVEL is renamed to ANDROID_NATIVE_API_LEVEL -# - modified January 2012 +# - January 2012 # [+] added stlport_static support (experimental) # [+] added special check for cygwin # [+] filtered out hidden files (starting with .) while globbing inside NDK # [+] automatically applied GLESv2 linkage fix for NDK revisions 5-6 # [+] added ANDROID_GET_ABI_RAWNAME to get NDK ABI names by CMake flags -# - modified February 2012 +# - February 2012 # [+] updated for NDK r7b # [~] fixed cmake try_compile() command # [~] Fix for missing install_name_tool on OS X -# - modified March 2012 +# - March 2012 # [~] fixed incorrect C compiler flags # [~] fixed CMAKE_SYSTEM_PROCESSOR change on ANDROID_ABI change # [+] improved toolchain loading speed # [+] added assembler language support (.S) # [+] allowed preset search paths and extra search suffixes -# - modified April 2012 +# - April 2012 # [+] updated for NDK r7c # [~] fixed most of problems with compiler/linker flags and caching # [+] added option ANDROID_FUNCTION_LEVEL_LINKING -# - modified May 2012 +# - May 2012 # [+] updated for NDK r8 # [+] added mips architecture support -# - modified August 2012 +# - August 2012 # [+] updated for NDK r8b # [~] all intermediate files generated by toolchain are moved to CMakeFiles # [~] libstdc++ and libsupc are removed from explicit link libraries # [+] added CCache support (via NDK_CCACHE environment or cmake variable) # [+] added gold linker support for NDK r8b # [~] fixed mips linker flags for NDK r8b -# - modified September 2012 +# - September 2012 # [+] added NDK release name detection (see ANDROID_NDK_RELEASE) # [+] added support for all C++ runtimes from NDK # (system, gabi++, stlport, gnustl) @@ -235,8 +275,11 @@ # [~] use gold linker as default if available (NDK r8b) # [~] globally turned off rpath # [~] compiler options are aligned with NDK r8b -# - modified October 2012 +# - October 2012 # [~] fixed C++ linking: explicitly link with math library (OpenCV #2426) +# - November 2012 +# [+] updated for NDK r8c +# [+] added support for clang compiler # ------------------------------------------------------------------------------ cmake_minimum_required( VERSION 2.6.3 ) @@ -259,7 +302,7 @@ set( CMAKE_SYSTEM_VERSION 1 ) # rpath makes low sence for Android set( CMAKE_SKIP_RPATH TRUE CACHE BOOL "If set, runtime paths are not added when using shared libraries." ) -set( ANDROID_SUPPORTED_NDK_VERSIONS ${ANDROID_EXTRA_NDK_VERSIONS} -r8b -r8 -r7c -r7b -r7 -r6b -r6 -r5c -r5b -r5 "" ) +set( ANDROID_SUPPORTED_NDK_VERSIONS ${ANDROID_EXTRA_NDK_VERSIONS} -r8c -r8b -r8 -r7c -r7b -r7 -r6b -r6 -r5c -r5b -r5 "" ) if(NOT DEFINED ANDROID_NDK_SEARCH_PATHS) if( CMAKE_HOST_WIN32 ) file( TO_CMAKE_PATH "$ENV{PROGRAMFILES}" ANDROID_NDK_SEARCH_PATHS ) @@ -367,8 +410,8 @@ endmacro() macro( __DETECT_TOOLCHAIN_MACHINE_NAME _var _root ) if( EXISTS "${_root}" ) - file( GLOB __gccExePath "${_root}/bin/*-gcc${TOOL_OS_SUFFIX}" ) - __LIST_FILTER( __gccExePath "bin/[.].*-gcc${TOOL_OS_SUFFIX}$" ) + file( GLOB __gccExePath RELATIVE "${_root}/bin/" "${_root}/bin/*-gcc${TOOL_OS_SUFFIX}" ) + __LIST_FILTER( __gccExePath "^[.].*" ) list( LENGTH __gccExePath __gccExePathsCount ) if( NOT __gccExePathsCount EQUAL 1 AND NOT _CMAKE_IN_TRY_COMPILE ) message( WARNING "Could not determine machine name for compiler from ${_root}" ) @@ -506,55 +549,73 @@ if( BUILD_WITH_STANDALONE_TOOLCHAIN ) elseif( __availableToolchainMachines MATCHES mipsel ) set( __availableToolchainArchs "mipsel" ) endif() - if( ANDROID_COMPILER_VERSION ) - # do not run gcc every time because it is relatevely expencive - set( __availableToolchainCompilerVersions "${ANDROID_COMPILER_VERSION}" ) - else() - execute_process( COMMAND "${ANDROID_STANDALONE_TOOLCHAIN}/bin/${__availableToolchainMachines}-gcc${TOOL_OS_SUFFIX}" --version - OUTPUT_VARIABLE __availableToolchainCompilerVersions OUTPUT_STRIP_TRAILING_WHITESPACE ) - string( REGEX MATCH "[0-9]+[.][0-9]+([.][0-9]+)?" __availableToolchainCompilerVersions "${__availableToolchainCompilerVersions}" ) + execute_process( COMMAND "${ANDROID_STANDALONE_TOOLCHAIN}/bin/${__availableToolchainMachines}-gcc${TOOL_OS_SUFFIX}" -dumpversion + OUTPUT_VARIABLE __availableToolchainCompilerVersions OUTPUT_STRIP_TRAILING_WHITESPACE ) + string( REGEX MATCH "[0-9]+[.][0-9]+([.][0-9]+)?" __availableToolchainCompilerVersions "${__availableToolchainCompilerVersions}" ) + if( EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/bin/clang${TOOL_OS_SUFFIX}" ) + list( APPEND __availableToolchains "standalone-clang" ) + list( APPEND __availableToolchainMachines ${__availableToolchainMachines} ) + list( APPEND __availableToolchainArchs ${__availableToolchainArchs} ) + list( APPEND __availableToolchainCompilerVersions ${__availableToolchainCompilerVersions} ) endif() endif() +macro( __GLOB_NDK_TOOLCHAINS __availableToolchainsVar ) + foreach( __toolchain ${${__availableToolchainsVar}} ) + if( "${__toolchain}" MATCHES "-clang3[.][0-9]$" AND NOT EXISTS "${ANDROID_NDK}/toolchains/${__toolchain}/prebuilt/" ) + string( REGEX REPLACE "-clang3[.][0-9]$" "-4.6" __gcc_toolchain "${__toolchain}" ) + else() + set( __gcc_toolchain "${__toolchain}" ) + endif() + __DETECT_TOOLCHAIN_MACHINE_NAME( __machine "${ANDROID_NDK}/toolchains/${__gcc_toolchain}/prebuilt/${ANDROID_NDK_HOST_SYSTEM_NAME}" ) + if( __machine ) + string( REGEX MATCH "[0-9]+[.][0-9]+([.][0-9]+)?$" __version "${__gcc_toolchain}" ) + string( REGEX MATCH "^[^-]+" __arch "${__gcc_toolchain}" ) + list( APPEND __availableToolchainMachines "${__machine}" ) + list( APPEND __availableToolchainArchs "${__arch}" ) + list( APPEND __availableToolchainCompilerVersions "${__version}" ) + else() + list( REMOVE_ITEM ${__availableToolchainsVar} "${__toolchain}" ) + endif() + unset( __gcc_toolchain ) + endforeach() +endmacro() + # get all the details about NDK if( BUILD_WITH_ANDROID_NDK ) file( GLOB ANDROID_SUPPORTED_NATIVE_API_LEVELS RELATIVE "${ANDROID_NDK}/platforms" "${ANDROID_NDK}/platforms/android-*" ) string( REPLACE "android-" "" ANDROID_SUPPORTED_NATIVE_API_LEVELS "${ANDROID_SUPPORTED_NATIVE_API_LEVELS}" ) - file( GLOB __availableToolchains RELATIVE "${ANDROID_NDK}/toolchains" "${ANDROID_NDK}/toolchains/*" ) - __LIST_FILTER( __availableToolchains "^[.]" ) + set( __availableToolchains "" ) set( __availableToolchainMachines "" ) set( __availableToolchainArchs "" ) set( __availableToolchainCompilerVersions "" ) - foreach( __toolchain ${__availableToolchains} ) - __DETECT_TOOLCHAIN_MACHINE_NAME( __machine "${ANDROID_NDK}/toolchains/${__toolchain}/prebuilt/${ANDROID_NDK_HOST_SYSTEM_NAME}" ) - if( __machine ) - string( REGEX MATCH "[0-9]+[.][0-9]+([.][0-9]+)?$" __version "${__toolchain}" ) - string( REGEX MATCH "^[^-]+" __arch "${__toolchain}" ) - list( APPEND __availableToolchainMachines "${__machine}" ) - list( APPEND __availableToolchainArchs "${__arch}" ) - list( APPEND __availableToolchainCompilerVersions "${__version}" ) - else() - list( REMOVE_ITEM __availableToolchains "${__toolchain}" ) - endif() - endforeach() + if( ANDROID_TOOLCHAIN_NAME AND EXISTS "${ANDROID_NDK}/toolchains/${ANDROID_TOOLCHAIN_NAME}/" ) + # do not go through all toolchains if we know the name + set( __availableToolchains "${ANDROID_TOOLCHAIN_NAME}" ) + __GLOB_NDK_TOOLCHAINS( __availableToolchains ) + endif() if( NOT __availableToolchains ) - message( FATAL_ERROR "Could not any working toolchain in the NDK. Probably your Android NDK is broken." ) + file( GLOB __availableToolchains RELATIVE "${ANDROID_NDK}/toolchains" "${ANDROID_NDK}/toolchains/*" ) + __LIST_FILTER( __availableToolchains "^[.]" ) + __LIST_FILTER( __availableToolchains "llvm" ) + __GLOB_NDK_TOOLCHAINS( __availableToolchains ) + endif() + if( NOT __availableToolchains ) + message( FATAL_ERROR "Could not find any working toolchain in the NDK. Probably your Android NDK is broken." ) endif() endif() # build list of available ABIs +set( ANDROID_SUPPORTED_ABIS "" ) +set( __uniqToolchainArchNames ${__availableToolchainArchs} ) +list( REMOVE_DUPLICATES __uniqToolchainArchNames ) +list( SORT __uniqToolchainArchNames ) +foreach( __arch ${__uniqToolchainArchNames} ) +list( APPEND ANDROID_SUPPORTED_ABIS ${ANDROID_SUPPORTED_ABIS_${__arch}} ) +endforeach() +unset( __uniqToolchainArchNames ) if( NOT ANDROID_SUPPORTED_ABIS ) - set( ANDROID_SUPPORTED_ABIS "" ) - set( __uniqToolchainArchNames ${__availableToolchainArchs} ) - list( REMOVE_DUPLICATES __uniqToolchainArchNames ) - list( SORT __uniqToolchainArchNames ) - foreach( __arch ${__uniqToolchainArchNames} ) - list( APPEND ANDROID_SUPPORTED_ABIS ${ANDROID_SUPPORTED_ABIS_${__arch}} ) - endforeach() - unset( __uniqToolchainArchNames ) - if( NOT ANDROID_SUPPORTED_ABIS ) - message( FATAL_ERROR "No one of known Android ABIs is supported by this cmake toolchain." ) - endif() +message( FATAL_ERROR "No one of known Android ABIs is supported by this cmake toolchain." ) endif() # choose target ABI @@ -569,33 +630,34 @@ if( __androidAbiIdx EQUAL -1 ) endif() unset( __androidAbiIdx ) -# remember target ABI -set( ANDROID_ABI "${ANDROID_ABI}" CACHE STRING "The target ABI for Android. If arm, then armeabi-v7a is recommended for hardware floating point." FORCE ) - # set target ABI options if( ANDROID_ABI STREQUAL "x86" ) set( X86 true ) set( ANDROID_NDK_ABI_NAME "x86" ) set( ANDROID_ARCH_NAME "x86" ) set( ANDROID_ARCH_FULLNAME "x86" ) + set( ANDROID_LLVM_TRIPLE "i686-none-linux-android" ) set( CMAKE_SYSTEM_PROCESSOR "i686" ) elseif( ANDROID_ABI STREQUAL "mips" ) set( MIPS true ) set( ANDROID_NDK_ABI_NAME "mips" ) set( ANDROID_ARCH_NAME "mips" ) set( ANDROID_ARCH_FULLNAME "mipsel" ) + set( ANDROID_LLVM_TRIPLE "mipsel-none-linux-android" ) set( CMAKE_SYSTEM_PROCESSOR "mips" ) elseif( ANDROID_ABI STREQUAL "armeabi" ) set( ARMEABI true ) set( ANDROID_NDK_ABI_NAME "armeabi" ) set( ANDROID_ARCH_NAME "arm" ) set( ANDROID_ARCH_FULLNAME "arm" ) + set( ANDROID_LLVM_TRIPLE "armv5te-none-linux-androideabi" ) set( CMAKE_SYSTEM_PROCESSOR "armv5te" ) elseif( ANDROID_ABI STREQUAL "armeabi-v6 with VFP" ) set( ARMEABI_V6 true ) set( ANDROID_NDK_ABI_NAME "armeabi" ) set( ANDROID_ARCH_NAME "arm" ) set( ANDROID_ARCH_FULLNAME "arm" ) + set( ANDROID_LLVM_TRIPLE "armv5te-none-linux-androideabi" ) set( CMAKE_SYSTEM_PROCESSOR "armv6" ) # need always fallback to older platform set( ARMEABI true ) @@ -604,12 +666,14 @@ elseif( ANDROID_ABI STREQUAL "armeabi-v7a") set( ANDROID_NDK_ABI_NAME "armeabi-v7a" ) set( ANDROID_ARCH_NAME "arm" ) set( ANDROID_ARCH_FULLNAME "arm" ) + set( ANDROID_LLVM_TRIPLE "armv7-none-linux-androideabi" ) set( CMAKE_SYSTEM_PROCESSOR "armv7-a" ) elseif( ANDROID_ABI STREQUAL "armeabi-v7a with VFPV3" ) set( ARMEABI_V7A true ) set( ANDROID_NDK_ABI_NAME "armeabi-v7a" ) set( ANDROID_ARCH_NAME "arm" ) set( ANDROID_ARCH_FULLNAME "arm" ) + set( ANDROID_LLVM_TRIPLE "armv7-none-linux-androideabi" ) set( CMAKE_SYSTEM_PROCESSOR "armv7-a" ) set( VFPV3 true ) elseif( ANDROID_ABI STREQUAL "armeabi-v7a with NEON" ) @@ -617,6 +681,7 @@ elseif( ANDROID_ABI STREQUAL "armeabi-v7a with NEON" ) set( ANDROID_NDK_ABI_NAME "armeabi-v7a" ) set( ANDROID_ARCH_NAME "arm" ) set( ANDROID_ARCH_FULLNAME "arm" ) + set( ANDROID_LLVM_TRIPLE "armv7-none-linux-androideabi" ) set( CMAKE_SYSTEM_PROCESSOR "armv7-a" ) set( VFPV3 true ) set( NEON true ) @@ -630,12 +695,6 @@ if( CMAKE_BINARY_DIR AND EXISTS "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMa file( APPEND "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeSystem.cmake" "SET(CMAKE_SYSTEM_PROCESSOR \"${CMAKE_SYSTEM_PROCESSOR}\")\n" ) endif() -set( ANDROID_SUPPORTED_ABIS ${ANDROID_SUPPORTED_ABIS_${ANDROID_ARCH_FULLNAME}} CACHE INTERNAL "ANDROID_ABI can be changed only to one of these ABIs. Changing to any other ABI requires to reset cmake cache." FORCE ) -if( CMAKE_VERSION VERSION_GREATER "2.8" ) - list( SORT ANDROID_SUPPORTED_ABIS_${ANDROID_ARCH_FULLNAME} ) - set_property( CACHE ANDROID_ABI PROPERTY STRINGS ${ANDROID_SUPPORTED_ABIS_${ANDROID_ARCH_FULLNAME}} ) -endif() - if( ANDROID_ARCH_NAME STREQUAL "arm" AND NOT ARMEABI_V6 ) __INIT_VARIABLE( ANDROID_FORCE_ARM_BUILD OBSOLETE_FORCE_ARM VALUES OFF ) set( ANDROID_FORCE_ARM_BUILD ${ANDROID_FORCE_ARM_BUILD} CACHE BOOL "Use 32-bit ARM instructions instead of Thumb-1" FORCE ) @@ -648,11 +707,15 @@ endif() if( ANDROID_TOOLCHAIN_NAME ) list( FIND __availableToolchains "${ANDROID_TOOLCHAIN_NAME}" __toolchainIdx ) if( __toolchainIdx EQUAL -1 ) - message( FATAL_ERROR "Previously selected toolchain \"${ANDROID_TOOLCHAIN_NAME}\" is missing. You need to remove CMakeCache.txt and rerun cmake manually to change the toolchain" ) + list( SORT __availableToolchains ) + string( REPLACE ";" "\n * " toolchains_list "${__availableToolchains}" ) + set( toolchains_list " * ${toolchains_list}") + message( FATAL_ERROR "Specified toolchain \"${ANDROID_TOOLCHAIN_NAME}\" is missing in your NDK or broken. Please verify that your NDK is working or select another compiler toolchain. +To configure the toolchain set CMake variable ANDROID_TOOLCHAIN_NAME to one of the following values:\n${toolchains_list}\n" ) endif() list( GET __availableToolchainArchs ${__toolchainIdx} __toolchainArch ) if( NOT __toolchainArch STREQUAL ANDROID_ARCH_FULLNAME ) - message( SEND_ERROR "Previously selected toolchain \"${ANDROID_TOOLCHAIN_NAME}\" is not able to compile binaries for the \"${ANDROID_ARCH_NAME}\" platform." ) + message( SEND_ERROR "Selected toolchain \"${ANDROID_TOOLCHAIN_NAME}\" is not able to compile binaries for the \"${ANDROID_ARCH_NAME}\" platform." ) endif() else() set( __toolchainIdx -1 ) @@ -681,8 +744,7 @@ endif() list( GET __availableToolchains ${__toolchainIdx} ANDROID_TOOLCHAIN_NAME ) list( GET __availableToolchainMachines ${__toolchainIdx} ANDROID_TOOLCHAIN_MACHINE_NAME ) list( GET __availableToolchainCompilerVersions ${__toolchainIdx} ANDROID_COMPILER_VERSION ) -set( ANDROID_TOOLCHAIN_NAME "${ANDROID_TOOLCHAIN_NAME}" CACHE INTERNAL "Name of toolchain used" FORCE ) -set( ANDROID_COMPILER_VERSION "${ANDROID_COMPILER_VERSION}" CACHE INTERNAL "compiler version from selected toolchain" FORCE ) + unset( __toolchainIdx ) unset( __availableToolchains ) unset( __availableToolchainMachines ) @@ -692,37 +754,35 @@ unset( __availableToolchainCompilerVersions ) # choose native API level __INIT_VARIABLE( ANDROID_NATIVE_API_LEVEL ENV_ANDROID_NATIVE_API_LEVEL ANDROID_API_LEVEL ENV_ANDROID_API_LEVEL ANDROID_STANDALONE_TOOLCHAIN_API_LEVEL ANDROID_DEFAULT_NDK_API_LEVEL_${ANDROID_ARCH_NAME} ANDROID_DEFAULT_NDK_API_LEVEL ) string( REGEX MATCH "[0-9]+" ANDROID_NATIVE_API_LEVEL "${ANDROID_NATIVE_API_LEVEL}" ) +# TODO: filter out unsupported levels # validate list( FIND ANDROID_SUPPORTED_NATIVE_API_LEVELS "${ANDROID_NATIVE_API_LEVEL}" __levelIdx ) if( __levelIdx EQUAL -1 ) message( SEND_ERROR "Specified Android native API level (${ANDROID_NATIVE_API_LEVEL}) is not supported by your NDK/toolchain." ) +else() + if( BUILD_WITH_ANDROID_NDK ) + __DETECT_NATIVE_API_LEVEL( __realApiLevel "${ANDROID_NDK}/platforms/android-${ANDROID_NATIVE_API_LEVEL}/arch-${ANDROID_ARCH_NAME}/usr/include/android/api-level.h" ) + if( NOT __realApiLevel EQUAL ANDROID_NATIVE_API_LEVEL ) + message( SEND_ERROR "Specified Android API level (${ANDROID_NATIVE_API_LEVEL}) does not match to the level found (${__realApiLevel}). Probably your copy of NDK is broken." ) + endif() + unset( __realApiLevel ) + endif() + set( ANDROID_NATIVE_API_LEVEL "${ANDROID_NATIVE_API_LEVEL}" CACHE STRING "Android API level for native code" FORCE ) + if( CMAKE_VERSION VERSION_GREATER "2.8" ) + list( SORT ANDROID_SUPPORTED_NATIVE_API_LEVELS ) + set_property( CACHE ANDROID_NATIVE_API_LEVEL PROPERTY STRINGS ${ANDROID_SUPPORTED_NATIVE_API_LEVELS} ) + endif() endif() unset( __levelIdx ) -if( BUILD_WITH_ANDROID_NDK ) - __DETECT_NATIVE_API_LEVEL( __realApiLevel "${ANDROID_NDK}/platforms/android-${ANDROID_NATIVE_API_LEVEL}/arch-${ANDROID_ARCH_NAME}/usr/include/android/api-level.h" ) - if( NOT __realApiLevel EQUAL ANDROID_NATIVE_API_LEVEL ) - message( SEND_ERROR "Specified Android API level (${ANDROID_NATIVE_API_LEVEL}) does not match to the level found (${__realApiLevel}). Probably your copy of NDK is broken." ) - endif() - unset( __realApiLevel ) -endif() -set( ANDROID_NATIVE_API_LEVEL "${ANDROID_NATIVE_API_LEVEL}" CACHE STRING "Android API level for native code" FORCE ) + + +# remember target ABI +set( ANDROID_ABI "${ANDROID_ABI}" CACHE STRING "The target ABI for Android. If arm, then armeabi-v7a is recommended for hardware floating point." FORCE ) if( CMAKE_VERSION VERSION_GREATER "2.8" ) - list( SORT ANDROID_SUPPORTED_NATIVE_API_LEVELS ) - set_property( CACHE ANDROID_NATIVE_API_LEVEL PROPERTY STRINGS ${ANDROID_SUPPORTED_NATIVE_API_LEVELS} ) + list( SORT ANDROID_SUPPORTED_ABIS_${ANDROID_ARCH_FULLNAME} ) + set_property( CACHE ANDROID_ABI PROPERTY STRINGS ${ANDROID_SUPPORTED_ABIS_${ANDROID_ARCH_FULLNAME}} ) endif() -# setup output directories -set( LIBRARY_OUTPUT_PATH_ROOT ${CMAKE_SOURCE_DIR} CACHE PATH "root for library output, set this to change where android libs are installed to" ) -set( CMAKE_INSTALL_PREFIX "${ANDROID_TOOLCHAIN_ROOT}/user" CACHE STRING "path for installing" ) - -if(NOT _CMAKE_IN_TRY_COMPILE) - if( EXISTS "${CMAKE_SOURCE_DIR}/jni/CMakeLists.txt" ) - set( EXECUTABLE_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/bin/${ANDROID_NDK_ABI_NAME}" CACHE PATH "Output directory for applications" ) - else() - set( EXECUTABLE_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/bin" CACHE PATH "Output directory for applications" ) - endif() - set( LIBRARY_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/libs/${ANDROID_NDK_ABI_NAME}" CACHE PATH "path for android libs" ) -endif() # runtime choice (STL, rtti, exceptions) if( NOT ANDROID_STL ) @@ -800,9 +860,84 @@ See https://android.googlesource.com/platform/development.git f907f4f9d4e56ccc80 " ) endif() + +# setup paths and STL for standalone toolchain +if( BUILD_WITH_STANDALONE_TOOLCHAIN ) + set( ANDROID_TOOLCHAIN_ROOT "${ANDROID_STANDALONE_TOOLCHAIN}" ) + set( ANDROID_CLANG_TOOLCHAIN_ROOT "${ANDROID_STANDALONE_TOOLCHAIN}" ) + set( ANDROID_SYSROOT "${ANDROID_STANDALONE_TOOLCHAIN}/sysroot" ) + + if( NOT ANDROID_STL STREQUAL "none" ) + set( ANDROID_STL_INCLUDE_DIRS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/include/c++/${ANDROID_COMPILER_VERSION}" ) + if( ARMEABI_V7A AND EXISTS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/${CMAKE_SYSTEM_PROCESSOR}/bits" ) + list( APPEND ANDROID_STL_INCLUDE_DIRS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/${CMAKE_SYSTEM_PROCESSOR}" ) + elseif( ARMEABI AND NOT ANDROID_FORCE_ARM_BUILD AND EXISTS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/thumb/bits" ) + list( APPEND ANDROID_STL_INCLUDE_DIRS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/thumb" ) + else() + list( APPEND ANDROID_STL_INCLUDE_DIRS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}" ) + endif() + # always search static GNU STL to get the location of libsupc++.a + if( ARMEABI_V7A AND NOT ANDROID_FORCE_ARM_BUILD AND EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/thumb/libstdc++.a" ) + set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/thumb" ) + elseif( ARMEABI_V7A AND EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/libstdc++.a" ) + set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}" ) + elseif( ARMEABI AND NOT ANDROID_FORCE_ARM_BUILD AND EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb/libstdc++.a" ) + set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb" ) + elseif( EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/libstdc++.a" ) + set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib" ) + endif() + if( __libstl ) + set( __libsupcxx "${__libstl}/libsupc++.a" ) + set( __libstl "${__libstl}/libstdc++.a" ) + endif() + if( NOT EXISTS "${__libsupcxx}" ) + message( FATAL_ERROR "The required libstdsupc++.a is missing in your standalone toolchain. + Usually it happens because of bug in make-standalone-toolchain.sh script from NDK r7, r7b and r7c. + You need to either upgrade to newer NDK or manually copy + $ANDROID_NDK/sources/cxx-stl/gnu-libstdc++/libs/${ANDROID_NDK_ABI_NAME}/libsupc++.a + to + ${__libsupcxx} + " ) + endif() + if( ANDROID_STL STREQUAL "gnustl_shared" ) + if( ARMEABI_V7A AND EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/libgnustl_shared.so" ) + set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/libgnustl_shared.so" ) + elseif( ARMEABI AND NOT ANDROID_FORCE_ARM_BUILD AND EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb/libgnustl_shared.so" ) + set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb/libgnustl_shared.so" ) + elseif( EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/libgnustl_shared.so" ) + set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/libgnustl_shared.so" ) + endif() + endif() + endif() +endif() + +# clang +if( "${ANDROID_TOOLCHAIN_NAME}" STREQUAL "standalone-clang" ) + set( ANDROID_COMPILER_IS_CLANG 1 ) + execute_process( COMMAND "${ANDROID_CLANG_TOOLCHAIN_ROOT}/bin/clang${TOOL_OS_SUFFIX}" --version OUTPUT_VARIABLE ANDROID_CLANG_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE ) + string( REGEX MATCH "[0-9]+[.][0-9]+" ANDROID_CLANG_VERSION "${ANDROID_CLANG_VERSION}") +elseif( "${ANDROID_TOOLCHAIN_NAME}" MATCHES "-clang3[.][0-9]?$" ) + string( REGEX MATCH "3[.][0-9]$" ANDROID_CLANG_VERSION "${ANDROID_TOOLCHAIN_NAME}") + string( REGEX REPLACE "-clang${ANDROID_CLANG_VERSION}$" "-4.6" ANDROID_GCC_TOOLCHAIN_NAME "${ANDROID_TOOLCHAIN_NAME}" ) + if( NOT EXISTS "${ANDROID_NDK}/toolchains/llvm-${ANDROID_CLANG_VERSION}/prebuilt/${ANDROID_NDK_HOST_SYSTEM_NAME}/bin/clang${TOOL_OS_SUFFIX}" ) + message( FATAL_ERROR "Could not find the " ) + endif() + set( ANDROID_COMPILER_IS_CLANG 1 ) + set( ANDROID_CLANG_TOOLCHAIN_ROOT "${ANDROID_NDK}/toolchains/llvm-${ANDROID_CLANG_VERSION}/prebuilt/${ANDROID_NDK_HOST_SYSTEM_NAME}" ) +else() + set( ANDROID_GCC_TOOLCHAIN_NAME "${ANDROID_TOOLCHAIN_NAME}" ) + unset( ANDROID_COMPILER_IS_CLANG CACHE ) +endif() + +string( REPLACE "." "" _clang_name "clang${ANDROID_CLANG_VERSION}" ) +if( NOT EXISTS "${ANDROID_CLANG_TOOLCHAIN_ROOT}/bin/${_clang_name}${TOOL_OS_SUFFIX}" ) + set( _clang_name "clang" ) +endif() + + # setup paths and STL for NDK if( BUILD_WITH_ANDROID_NDK ) - set( ANDROID_TOOLCHAIN_ROOT "${ANDROID_NDK}/toolchains/${ANDROID_TOOLCHAIN_NAME}/prebuilt/${ANDROID_NDK_HOST_SYSTEM_NAME}" ) + set( ANDROID_TOOLCHAIN_ROOT "${ANDROID_NDK}/toolchains/${ANDROID_GCC_TOOLCHAIN_NAME}/prebuilt/${ANDROID_NDK_HOST_SYSTEM_NAME}" ) set( ANDROID_SYSROOT "${ANDROID_NDK}/platforms/android-${ANDROID_NATIVE_API_LEVEL}/arch-${ANDROID_ARCH_NAME}" ) if( ANDROID_STL STREQUAL "none" ) @@ -874,54 +1009,6 @@ if( BUILD_WITH_ANDROID_NDK ) endif() endif() -# setup paths and STL for standalone toolchain -if( BUILD_WITH_STANDALONE_TOOLCHAIN ) - set( ANDROID_TOOLCHAIN_ROOT "${ANDROID_STANDALONE_TOOLCHAIN}" ) - set( ANDROID_SYSROOT "${ANDROID_STANDALONE_TOOLCHAIN}/sysroot" ) - - if( NOT ANDROID_STL STREQUAL "none" ) - set( ANDROID_STL_INCLUDE_DIRS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/include/c++/${ANDROID_COMPILER_VERSION}" ) - if( ARMEABI_V7A AND EXISTS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/${CMAKE_SYSTEM_PROCESSOR}/bits" ) - list( APPEND ANDROID_STL_INCLUDE_DIRS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/${CMAKE_SYSTEM_PROCESSOR}" ) - elseif( ARMEABI AND NOT ANDROID_FORCE_ARM_BUILD AND EXISTS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/thumb/bits" ) - list( APPEND ANDROID_STL_INCLUDE_DIRS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/thumb" ) - else() - list( APPEND ANDROID_STL_INCLUDE_DIRS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}" ) - endif() - # always search static GNU STL to get the location of libsupc++.a - if( ARMEABI_V7A AND NOT ANDROID_FORCE_ARM_BUILD AND EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/thumb/libstdc++.a" ) - set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/thumb" ) - elseif( ARMEABI_V7A AND EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/libstdc++.a" ) - set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}" ) - elseif( ARMEABI AND NOT ANDROID_FORCE_ARM_BUILD AND EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb/libstdc++.a" ) - set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb" ) - elseif( EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/libstdc++.a" ) - set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib" ) - endif() - if( __libstl ) - set( __libsupcxx "${__libstl}/libsupc++.a" ) - set( __libstl "${__libstl}/libstdc++.a" ) - endif() - if( NOT EXISTS "${__libsupcxx}" ) - message( FATAL_ERROR "The required libstdsupc++.a is missing in your standalone toolchain. - Usually it happens because of bug in make-standalone-toolchain.sh script from NDK r7, r7b and r7c. - You need to either upgrade to newer NDK or manually copy - $ANDROID_NDK/sources/cxx-stl/gnu-libstdc++/libs/${ANDROID_NDK_ABI_NAME}/libsupc++.a - to - ${__libsupcxx} - " ) - endif() - if( ANDROID_STL STREQUAL "gnustl_shared" ) - if( ARMEABI_V7A AND EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/libgnustl_shared.so" ) - set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/libgnustl_shared.so" ) - elseif( ARMEABI AND NOT ANDROID_FORCE_ARM_BUILD AND EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb/libgnustl_shared.so" ) - set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb/libgnustl_shared.so" ) - elseif( EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/libgnustl_shared.so" ) - set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/libgnustl_shared.so" ) - endif() - endif() - endif() -endif() # case of shared STL linkage if( ANDROID_STL MATCHES "shared" AND DEFINED __libstl ) @@ -937,6 +1024,7 @@ if( ANDROID_STL MATCHES "shared" AND DEFINED __libstl ) endif() endif() + # ccache support __INIT_VARIABLE( _ndk_ccache NDK_CCACHE ENV_NDK_CCACHE ) if( _ndk_ccache ) @@ -946,16 +1034,27 @@ else() endif() unset( _ndk_ccache ) + # setup the cross-compiler if( NOT CMAKE_C_COMPILER ) if( NDK_CCACHE ) set( CMAKE_C_COMPILER "${NDK_CCACHE}" CACHE PATH "ccache as C compiler" ) set( CMAKE_CXX_COMPILER "${NDK_CCACHE}" CACHE PATH "ccache as C++ compiler" ) - set( CMAKE_C_COMPILER_ARG1 "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-gcc${TOOL_OS_SUFFIX}" CACHE PATH "gcc") - set( CMAKE_CXX_COMPILER_ARG1 "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-g++${TOOL_OS_SUFFIX}" CACHE PATH "g++") + if( ANDROID_COMPILER_IS_CLANG ) + set( CMAKE_C_COMPILER_ARG1 "${ANDROID_CLANG_TOOLCHAIN_ROOT}/bin/${_clang_name}${TOOL_OS_SUFFIX}" CACHE PATH "C compiler") + set( CMAKE_CXX_COMPILER_ARG1 "${ANDROID_CLANG_TOOLCHAIN_ROOT}/bin/${_clang_name}++${TOOL_OS_SUFFIX}" CACHE PATH "C++ compiler") + else() + set( CMAKE_C_COMPILER_ARG1 "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-gcc${TOOL_OS_SUFFIX}" CACHE PATH "C compiler") + set( CMAKE_CXX_COMPILER_ARG1 "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-g++${TOOL_OS_SUFFIX}" CACHE PATH "C++ compiler") + endif() else() - set( CMAKE_C_COMPILER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-gcc${TOOL_OS_SUFFIX}" CACHE PATH "gcc" ) - set( CMAKE_CXX_COMPILER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-g++${TOOL_OS_SUFFIX}" CACHE PATH "g++" ) + if( ANDROID_COMPILER_IS_CLANG ) + set( CMAKE_C_COMPILER "${ANDROID_CLANG_TOOLCHAIN_ROOT}/bin/${_clang_name}${TOOL_OS_SUFFIX}" CACHE PATH "C compiler") + set( CMAKE_CXX_COMPILER "${ANDROID_CLANG_TOOLCHAIN_ROOT}/bin/${_clang_name}++${TOOL_OS_SUFFIX}" CACHE PATH "C++ compiler") + else() + set( CMAKE_C_COMPILER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-gcc${TOOL_OS_SUFFIX}" CACHE PATH "C compiler" ) + set( CMAKE_CXX_COMPILER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-g++${TOOL_OS_SUFFIX}" CACHE PATH "C++ compiler" ) + endif() endif() set( CMAKE_ASM_COMPILER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-gcc${TOOL_OS_SUFFIX}" CACHE PATH "assembler" ) set( CMAKE_STRIP "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-strip${TOOL_OS_SUFFIX}" CACHE PATH "strip" ) @@ -982,15 +1081,22 @@ endif() # Force set compilers because standard identification works badly for us include( CMakeForceCompiler ) CMAKE_FORCE_C_COMPILER( "${CMAKE_C_COMPILER}" GNU ) +if( ANDROID_COMPILER_IS_CLANG ) + set( CMAKE_C_COMPILER_ID Clang) +endif() set( CMAKE_C_PLATFORM_ID Linux ) set( CMAKE_C_SIZEOF_DATA_PTR 4 ) set( CMAKE_C_HAS_ISYSROOT 1 ) set( CMAKE_C_COMPILER_ABI ELF ) CMAKE_FORCE_CXX_COMPILER( "${CMAKE_CXX_COMPILER}" GNU ) +if( ANDROID_COMPILER_IS_CLANG ) + set( CMAKE_CXX_COMPILER_ID Clang) +endif() set( CMAKE_CXX_PLATFORM_ID Linux ) set( CMAKE_CXX_SIZEOF_DATA_PTR 4 ) set( CMAKE_CXX_HAS_ISYSROOT 1 ) set( CMAKE_CXX_COMPILER_ABI ELF ) +set( CMAKE_CXX_SOURCE_FILE_EXTENSIONS cc cp cxx cpp CPP c++ C ) # force ASM compiler (required for CMake < 2.8.5) set( CMAKE_ASM_COMPILER_ID_RUN TRUE ) set( CMAKE_ASM_COMPILER_ID GNU ) @@ -1056,10 +1162,10 @@ if( ARMEABI_V7A ) elseif( VFPV3 ) set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -mfpu=vfpv3" ) else() - set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -mfpu=vfp" ) + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -mfpu=vfpv3-d16" ) endif() elseif( ARMEABI_V6 ) - set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -march=armv6 -mfloat-abi=softfp -mfpu=vfp" ) + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -march=armv6 -mfloat-abi=softfp -mfpu=vfp" ) # vfp == vfpv2 elseif( ARMEABI ) set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -march=armv5te -mtune=xscale -msoft-float" ) endif() @@ -1148,17 +1254,25 @@ if( ANDROID_FUNCTION_LEVEL_LINKING ) set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,--gc-sections" ) endif() -if( ANDROID_GOLD_LINKER AND CMAKE_HOST_UNIX AND (ARMEABI OR ARMEABI_V7A OR X86) AND ANDROID_COMPILER_VERSION VERSION_EQUAL "4.6" ) - set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -fuse-ld=gold" ) -elseif( ANDROID_NDK_RELEASE STREQUAL "r8b" AND ARMEABI AND ANDROID_COMPILER_VERSION VERSION_EQUAL "4.6" AND NOT _CMAKE_IN_TRY_COMPILE ) - message( WARNING "The default bfd linker from arm GCC 4.6 toolchain can fail with 'unresolvable R_ARM_THM_CALL relocation' error message. See https://code.google.com/p/android/issues/detail?id=35342 +if( ANDROID_COMPILER_VERSION VERSION_EQUAL "4.6" ) + if( ANDROID_GOLD_LINKER AND (CMAKE_HOST_UNIX OR ANDROID_NDK_RELEASE STRGREATER "r8b") AND (ARMEABI OR ARMEABI_V7A OR X86) ) + set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -fuse-ld=gold" ) + elseif( ANDROID_NDK_RELEASE STREQUAL "r8c") + set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -fuse-ld=bfd" ) + elseif( ANDROID_NDK_RELEASE STREQUAL "r8b" AND ARMEABI AND NOT _CMAKE_IN_TRY_COMPILE ) + message( WARNING "The default bfd linker from arm GCC 4.6 toolchain can fail with 'unresolvable R_ARM_THM_CALL relocation' error message. See https://code.google.com/p/android/issues/detail?id=35342 On Linux and OS X host platform you can workaround this problem using gold linker (default). - Rerun cmake with -DANDROID_GOLD_LINKER=ON option. + Rerun cmake with -DANDROID_GOLD_LINKER=ON option in case of problems. " ) -endif() + endif() +endif() # version 4.6 if( ANDROID_NOEXECSTACK ) - set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -Wa,--noexecstack" ) + if( ANDROID_COMPILER_IS_CLANG ) + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -Xclang -mnoexecstack" ) + else() + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -Wa,--noexecstack" ) + endif() set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,-z,noexecstack" ) endif() @@ -1166,6 +1280,22 @@ if( ANDROID_RELRO ) set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,-z,relro -Wl,-z,now" ) endif() +if( ANDROID_COMPILER_IS_CLANG ) + set( ANDROID_CXX_FLAGS "-Qunused-arguments ${ANDROID_CXX_FLAGS}" ) + if( ARMEABI_V7A AND NOT ANDROID_FORCE_ARM_BUILD ) + set( ANDROID_CXX_FLAGS_RELEASE "-target thumbv7-none-linux-androideabi ${ANDROID_CXX_FLAGS_RELEASE}" ) + set( ANDROID_CXX_FLAGS_DEBUG "-target ${ANDROID_LLVM_TRIPLE} ${ANDROID_CXX_FLAGS_DEBUG}" ) + else() + set( ANDROID_CXX_FLAGS "-target ${ANDROID_LLVM_TRIPLE} ${ANDROID_CXX_FLAGS}" ) + endif() + if( BUILD_WITH_ANDROID_NDK ) + if(ANDROID_ARCH_NAME STREQUAL "arm" ) + set( ANDROID_CXX_FLAGS "-isystem ${ANDROID_CLANG_TOOLCHAIN_ROOT}/lib/clang/${ANDROID_CLANG_VERSION}/include ${ANDROID_CXX_FLAGS}" ) + endif() + set( ANDROID_CXX_FLAGS "-gcc-toolchain ${ANDROID_TOOLCHAIN_ROOT} ${ANDROID_CXX_FLAGS}" ) + endif() +endif() + # cache flags set( CMAKE_CXX_FLAGS "" CACHE STRING "c++ flags" ) set( CMAKE_C_FLAGS "" CACHE STRING "c flags" ) @@ -1189,9 +1319,9 @@ set( CMAKE_MODULE_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} ${CMAKE_MODULE_LINKER_FL set( CMAKE_EXE_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS}" ) if( MIPS AND BUILD_WITH_ANDROID_NDK AND ANDROID_NDK_RELEASE STREQUAL "r8" ) - set( CMAKE_SHARED_LINKER_FLAGS "-Wl,-T,${ANDROID_NDK}/toolchains/${ANDROID_TOOLCHAIN_NAME}/mipself.xsc ${CMAKE_SHARED_LINKER_FLAGS}" ) - set( CMAKE_MODULE_LINKER_FLAGS "-Wl,-T,${ANDROID_NDK}/toolchains/${ANDROID_TOOLCHAIN_NAME}/mipself.xsc ${CMAKE_MODULE_LINKER_FLAGS}" ) - set( CMAKE_EXE_LINKER_FLAGS "-Wl,-T,${ANDROID_NDK}/toolchains/${ANDROID_TOOLCHAIN_NAME}/mipself.x ${CMAKE_EXE_LINKER_FLAGS}" ) + set( CMAKE_SHARED_LINKER_FLAGS "-Wl,-T,${ANDROID_NDK}/toolchains/${ANDROID_GCC_TOOLCHAIN_NAME}/mipself.xsc ${CMAKE_SHARED_LINKER_FLAGS}" ) + set( CMAKE_MODULE_LINKER_FLAGS "-Wl,-T,${ANDROID_NDK}/toolchains/${ANDROID_GCC_TOOLCHAIN_NAME}/mipself.xsc ${CMAKE_MODULE_LINKER_FLAGS}" ) + set( CMAKE_EXE_LINKER_FLAGS "-Wl,-T,${ANDROID_NDK}/toolchains/${ANDROID_GCC_TOOLCHAIN_NAME}/mipself.x ${CMAKE_EXE_LINKER_FLAGS}" ) endif() # configure rtti @@ -1218,6 +1348,19 @@ endif() include_directories( SYSTEM "${ANDROID_SYSROOT}/usr/include" ${ANDROID_STL_INCLUDE_DIRS} ) link_directories( "${CMAKE_INSTALL_PREFIX}/libs/${ANDROID_NDK_ABI_NAME}" ) +# setup output directories +set( LIBRARY_OUTPUT_PATH_ROOT ${CMAKE_SOURCE_DIR} CACHE PATH "root for library output, set this to change where android libs are installed to" ) +set( CMAKE_INSTALL_PREFIX "${ANDROID_TOOLCHAIN_ROOT}/user" CACHE STRING "path for installing" ) + +if(NOT _CMAKE_IN_TRY_COMPILE) + if( EXISTS "${CMAKE_SOURCE_DIR}/jni/CMakeLists.txt" ) + set( EXECUTABLE_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/bin/${ANDROID_NDK_ABI_NAME}" CACHE PATH "Output directory for applications" ) + else() + set( EXECUTABLE_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/bin" CACHE PATH "Output directory for applications" ) + endif() + set( LIBRARY_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/libs/${ANDROID_NDK_ABI_NAME}" CACHE PATH "path for android libs" ) +endif() + # set these global flags for cmake client scripts to change behavior set( ANDROID True ) set( BUILD_ANDROID True ) @@ -1335,7 +1478,7 @@ endif() # Variables controlling behavior or set by cmake toolchain: # ANDROID_ABI : "armeabi-v7a" (default), "armeabi", "armeabi-v7a with NEON", "armeabi-v7a with VFPV3", "armeabi-v6 with VFP", "x86", "mips" # ANDROID_NATIVE_API_LEVEL : 3,4,5,8,9,14 (depends on NDK version) -# ANDROID_SET_OBSOLETE_VARIABLES : ON/OFF +# ANDROID_STL : gnustl_static/gnustl_shared/stlport_static/stlport_shared/gabi++_static/gabi++_shared/system_re/system/none # ANDROID_FORBID_SYGWIN : ON/OFF # ANDROID_NO_UNDEFINED : ON/OFF # ANDROID_SO_UNDEFINED : OFF/ON (default depends on NDK version) @@ -1343,16 +1486,15 @@ endif() # ANDROID_GOLD_LINKER : ON/OFF # ANDROID_NOEXECSTACK : ON/OFF # ANDROID_RELRO : ON/OFF -# Variables that takes effect only at first run: # ANDROID_FORCE_ARM_BUILD : ON/OFF -# ANDROID_STL : gnustl_static/gnustl_shared/stlport_static/stlport_shared/gabi++_static/gabi++_shared/system_re/system/none # ANDROID_STL_FORCE_FEATURES : ON/OFF -# LIBRARY_OUTPUT_PATH_ROOT : -# NDK_CCACHE : +# ANDROID_SET_OBSOLETE_VARIABLES : ON/OFF # Can be set only at the first run: # ANDROID_NDK # ANDROID_STANDALONE_TOOLCHAIN -# ANDROID_TOOLCHAIN_NAME : "arm-linux-androideabi-4.4.3" or "arm-linux-androideabi-4.6" or "mipsel-linux-android-4.4.3" or "mipsel-linux-android-4.6" or "x86-4.4.3" or "x86-4.6" +# ANDROID_TOOLCHAIN_NAME : the NDK name of compiler toolchain +# LIBRARY_OUTPUT_PATH_ROOT : +# NDK_CCACHE : # Obsolete: # ANDROID_API_LEVEL : superseded by ANDROID_NATIVE_API_LEVEL # ARM_TARGET : superseded by ANDROID_ABI @@ -1375,10 +1517,11 @@ endif() # BUILD_WITH_STANDALONE_TOOLCHAIN : TRUE if standalone toolchain is used # ANDROID_NDK_HOST_SYSTEM_NAME : "windows", "linux-x86" or "darwin-x86" depending on host platform # ANDROID_NDK_ABI_NAME : "armeabi", "armeabi-v7a", "x86" or "mips" depending on ANDROID_ABI -# ANDROID_NDK_RELEASE : one of r5, r5b, r5c, r6, r6b, r7, r7b, r7c, r8, r8b; set only for NDK +# ANDROID_NDK_RELEASE : one of r5, r5b, r5c, r6, r6b, r7, r7b, r7c, r8, r8b, r8c; set only for NDK # ANDROID_ARCH_NAME : "arm" or "x86" or "mips" depending on ANDROID_ABI # ANDROID_SYSROOT : path to the compiler sysroot # TOOL_OS_SUFFIX : "" or ".exe" depending on host platform +# ANDROID_COMPILER_IS_CLANG : TRUE if clang compiler is used # Obsolete: # ARMEABI_NDK_NAME : superseded by ANDROID_NDK_ABI_NAME # @@ -1388,10 +1531,13 @@ endif() # ANDROID_SUPPORTED_ABIS : list of currently allowed values for ANDROID_ABI # ANDROID_TOOLCHAIN_MACHINE_NAME : "arm-linux-androideabi", "arm-eabi" or "i686-android-linux" # ANDROID_TOOLCHAIN_ROOT : path to the top level of toolchain (standalone or placed inside NDK) +# ANDROID_CLANG_TOOLCHAIN_ROOT : path to clang tools # ANDROID_SUPPORTED_NATIVE_API_LEVELS : list of native API levels found inside NDK # ANDROID_STL_INCLUDE_DIRS : stl include paths # ANDROID_RTTI : if rtti is enabled by the runtime # ANDROID_EXCEPTIONS : if exceptions are enabled by the runtime +# ANDROID_GCC_TOOLCHAIN_NAME : read-only, differs from ANDROID_TOOLCHAIN_NAME only if clang is used +# ANDROID_CLANG_VERSION : version of clang compiler if clang is used # # Defaults: # ANDROID_DEFAULT_NDK_API_LEVEL diff --git a/android/libinfo/CMakeLists.txt b/android/libinfo/CMakeLists.txt index f8e8e15af..028413ec6 100644 --- a/android/libinfo/CMakeLists.txt +++ b/android/libinfo/CMakeLists.txt @@ -35,5 +35,5 @@ set_target_properties(${the_module} PROPERTIES INSTALL_NAME_DIR lib ) -get_filename_component(lib_name "opencv_info" NAME) -install(FILES "${LIBRARY_OUTPUT_PATH}/${lib_name}" DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT main) \ No newline at end of file +get_filename_component(lib_name "libopencv_info.so" NAME) +install(FILES "${LIBRARY_OUTPUT_PATH}/${lib_name}" DESTINATION ${OPENCV_LIB_INSTALL_PATH} COMPONENT main) diff --git a/android/libinfo/info.c b/android/libinfo/info.c index f1e5bf01e..f0c2dd6a2 100644 --- a/android/libinfo/info.c +++ b/android/libinfo/info.c @@ -7,7 +7,7 @@ const char* GetLibraryList(void); JNIEXPORT jstring JNICALL Java_org_opencv_android_StaticHelper_getLibraryList(JNIEnv *, jclass); #define PACKAGE_NAME "org.opencv.lib_v" CVAUX_STR(CV_MAJOR_VERSION) CVAUX_STR(CV_MINOR_VERSION) "_" ANDROID_PACKAGE_PLATFORM -#define PACKAGE_REVISION CVAUX_STR(CV_SUBMINOR_VERSION) CVAUX_STR(ANDROID_PACKAGE_RELEASE) +#define PACKAGE_REVISION CVAUX_STR(CV_SUBMINOR_VERSION) "." CVAUX_STR(ANDROID_PACKAGE_RELEASE) const char* GetPackageName(void) { diff --git a/android/scripts/cmake_android_service.sh b/android/scripts/cmake_android_service.sh index 3503bb73d..e0d1222cd 100755 --- a/android/scripts/cmake_android_service.sh +++ b/android/scripts/cmake_android_service.sh @@ -4,5 +4,5 @@ cd `dirname $0`/.. mkdir -p build_service cd build_service -cmake -DCMAKE_TOOLCHAIN_FILE=../android.toolchain.cmake -DANDROID_STL=stlport_static -DANDROID_STL_FORCE_FEATURES=OFF -DBUILD_ANDROID_SERVICE=ON -DANDROID_SOURCE_TREE=~/Projects/AndroidSource/ServiceStub/ $@ ../.. +cmake -DCMAKE_TOOLCHAIN_FILE=../android.toolchain.cmake -DANDROID_TOOLCHAIN_NAME="arm-linux-androideabi-4.4.3" -DANDROID_STL=stlport_static -DANDROID_STL_FORCE_FEATURES=OFF -DBUILD_ANDROID_SERVICE=ON -DANDROID_SOURCE_TREE=~/Projects/AndroidSource/ServiceStub/ $@ ../.. diff --git a/android/service/engine/AndroidManifest.xml b/android/service/engine/AndroidManifest.xml index b1d6f691c..fdf6303d9 100644 --- a/android/service/engine/AndroidManifest.xml +++ b/android/service/engine/AndroidManifest.xml @@ -1,8 +1,8 @@ + android:versionCode="22@ANDROID_PLATFORM_VERSION_CODE@" + android:versionName="2.2" > diff --git a/android/service/engine/CMakeLists.txt b/android/service/engine/CMakeLists.txt index 529aef9bd..b0d8425ca 100644 --- a/android/service/engine/CMakeLists.txt +++ b/android/service/engine/CMakeLists.txt @@ -4,6 +4,24 @@ set(JNI_LIB_NAME ${engine} ${engine}_jni) unset(__android_project_chain CACHE) add_android_project(opencv_engine "${CMAKE_CURRENT_SOURCE_DIR}" SDK_TARGET 8 ${ANDROID_SDK_TARGET} IGNORE_JAVA ON) +set(ANDROID_PLATFORM_VERSION_CODE "0") + +if(ARMEABI_V7A) + set(ANDROID_PLATFORM_VERSION_CODE "2") + elseif(ARMEABI_V6) + set(ANDROID_PLATFORM_VERSION_CODE "1") + elseif(ARMEABI) + set(ANDROID_PLATFORM_VERSION_CODE "1") + elseif(X86) + set(ANDROID_PLATFORM_VERSION_CODE "3") + elseif(MIPS) + set(ANDROID_PLATFORM_VERSION_CODE "4") + else() + message(WARNING "Can not automatically determine the value for ANDROID_PLATFORM_VERSION_CODE") + endif() + +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/${ANDROID_MANIFEST_FILE}" "${OpenCV_BINARY_DIR}/android/service/engine/.build/${ANDROID_MANIFEST_FILE}" @ONLY) + link_directories("${ANDROID_SOURCE_TREE}/out/target/product/generic/system/lib" "${ANDROID_SOURCE_TREE}/out/target/product/${ANDROID_PRODUCT}/system/lib" "${ANDROID_SOURCE_TREE}/bin/${ANDROID_ARCH_NAME}") # -D__SUPPORT_ARMEABI_FEATURES key is also available diff --git a/android/service/engine/jni/Android.mk b/android/service/engine/jni/Android.mk index a33466c5c..9ab92a208 100644 --- a/android/service/engine/jni/Android.mk +++ b/android/service/engine/jni/Android.mk @@ -35,7 +35,7 @@ LOCAL_MODULE := libOpenCVEngine LOCAL_LDLIBS += -lz -lbinder -llog -lutils -LOCAL_LDFLAGS += -Wl,-allow-shlib-undefine +LOCAL_LDFLAGS += -Wl,-allow-shlib-undefined include $(BUILD_SHARED_LIBRARY) @@ -74,7 +74,6 @@ LOCAL_CFLAGS += -D__SUPPORT_MIPS LOCAL_MODULE := libOpenCVEngine_jni LOCAL_LDLIBS += -lz -lbinder -llog -lutils -landroid_runtime - LOCAL_SHARED_LIBRARIES = libOpenCVEngine include $(BUILD_SHARED_LIBRARY) @@ -83,4 +82,4 @@ include $(BUILD_SHARED_LIBRARY) # Native test application #--------------------------------------------------------------------- -include $(LOCAL_PATH)/Tests/Tests.mk \ No newline at end of file +#include $(LOCAL_PATH)/Tests/Tests.mk \ No newline at end of file diff --git a/android/service/engine/jni/Application.mk b/android/service/engine/jni/Application.mk index 4230cd26e..5647110fa 100644 --- a/android/service/engine/jni/Application.mk +++ b/android/service/engine/jni/Application.mk @@ -2,4 +2,5 @@ APP_ABI := armeabi x86 mips APP_PLATFORM := android-8 APP_STL := stlport_static APP_CPPFLAGS := -fno-rtti -fno-exceptions +NDK_TOOLCHAIN_VERSION=4.4.3 #APP_OPTIM := debug \ No newline at end of file diff --git a/android/service/engine/jni/Tests/Tests.mk b/android/service/engine/jni/Tests/Tests.mk index a436bc209..4cfe1c16a 100644 --- a/android/service/engine/jni/Tests/Tests.mk +++ b/android/service/engine/jni/Tests/Tests.mk @@ -36,7 +36,7 @@ LOCAL_CFLAGS += -D__SUPPORT_TEGRA3 LOCAL_CFLAGS += -D__SUPPORT_MIPS #LOCAL_CFLAGS += -D__SUPPORT_ARMEABI_FEATURES -LOCAL_LDFLAGS = -Wl,-allow-shlib-undefined +#LOCAL_LDFLAGS = -Wl,-allow-shlib-undefined LOCAL_MODULE := OpenCVEngineTestApp diff --git a/apps/traincascade/CMakeLists.txt b/apps/traincascade/CMakeLists.txt index 350200fc4..b92beb69b 100644 --- a/apps/traincascade/CMakeLists.txt +++ b/apps/traincascade/CMakeLists.txt @@ -2,7 +2,7 @@ if(IOS OR ANDROID) return() endif() -SET(OPENCV_TRAINCASCADE_DEPS opencv_core opencv_ml opencv_imgproc opencv_objdetect opencv_highgui opencv_calib3d opencv_video opencv_features2d opencv_flann opencv_legacy) +set(OPENCV_TRAINCASCADE_DEPS opencv_core opencv_ml opencv_imgproc opencv_objdetect opencv_highgui opencv_calib3d opencv_video opencv_features2d opencv_flann opencv_legacy) ocv_check_dependencies(${OPENCV_TRAINCASCADE_DEPS}) if(NOT OCV_DEPENDENCIES_FOUND) diff --git a/cmake/OpenCVDetectCXXCompiler.cmake b/cmake/OpenCVDetectCXXCompiler.cmake index 65edf72ed..d8c00cfdd 100644 --- a/cmake/OpenCVDetectCXXCompiler.cmake +++ b/cmake/OpenCVDetectCXXCompiler.cmake @@ -54,7 +54,7 @@ endif() # Detect GNU version: # ---------------------------------------------------------------------------- if(CMAKE_COMPILER_IS_GNUCXX) - execute_process(COMMAND ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1} --version + execute_process(COMMAND ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1} -dumpversion OUTPUT_VARIABLE CMAKE_OPENCV_GCC_VERSION_FULL OUTPUT_STRIP_TRAILING_WHITESPACE) diff --git a/cmake/OpenCVGenAndroidMK.cmake b/cmake/OpenCVGenAndroidMK.cmake index 04ebdb759..5b11afc17 100644 --- a/cmake/OpenCVGenAndroidMK.cmake +++ b/cmake/OpenCVGenAndroidMK.cmake @@ -71,6 +71,12 @@ if(ANDROID) endforeach() string(REPLACE "opencv_" "" OPENCV_MODULES_CONFIGMAKE "${OPENCV_MODULES_CONFIGMAKE}") + # prepare 3rd-party component list without TBB for armeabi and mips platforms. TBB is useless there. + set(OPENCV_3RDPARTY_COMPONENTS_CONFIGMAKE_NO_TBB ${OPENCV_3RDPARTY_COMPONENTS_CONFIGMAKE}) + foreach(mod ${OPENCV_3RDPARTY_COMPONENTS_CONFIGMAKE_NO_TBB}) + string(REPLACE "tbb" "" OPENCV_3RDPARTY_COMPONENTS_CONFIGMAKE_NO_TBB "${OPENCV_3RDPARTY_COMPONENTS_CONFIGMAKE_NO_TBB}") + endforeach() + if(BUILD_FAT_JAVA_LIB) set(OPENCV_LIBS_CONFIGMAKE java) else() diff --git a/cmake/templates/OpenCV.mk.in b/cmake/templates/OpenCV.mk.in index 32ab27fb6..d52f75b91 100644 --- a/cmake/templates/OpenCV.mk.in +++ b/cmake/templates/OpenCV.mk.in @@ -29,8 +29,22 @@ ifeq ($(OPENCV_LIB_TYPE),SHARED) OPENCV_3RDPARTY_COMPONENTS:= OPENCV_EXTRA_COMPONENTS:= else - OPENCV_3RDPARTY_COMPONENTS:=@OPENCV_3RDPARTY_COMPONENTS_CONFIGMAKE@ - OPENCV_EXTRA_COMPONENTS:=@OPENCV_EXTRA_COMPONENTS_CONFIGMAKE@ + ifeq ($(TARGET_ARCH_ABI),armeabi-v7a) + OPENCV_3RDPARTY_COMPONENTS:=@OPENCV_3RDPARTY_COMPONENTS_CONFIGMAKE@ + OPENCV_EXTRA_COMPONENTS:=@OPENCV_EXTRA_COMPONENTS_CONFIGMAKE@ + endif + ifeq ($(TARGET_ARCH_ABI),x86) + OPENCV_3RDPARTY_COMPONENTS:=@OPENCV_3RDPARTY_COMPONENTS_CONFIGMAKE@ + OPENCV_EXTRA_COMPONENTS:=@OPENCV_EXTRA_COMPONENTS_CONFIGMAKE@ + endif + ifeq ($(TARGET_ARCH_ABI),armeabi) + OPENCV_3RDPARTY_COMPONENTS:=@OPENCV_3RDPARTY_COMPONENTS_CONFIGMAKE_NO_TBB@ + OPENCV_EXTRA_COMPONENTS:=@OPENCV_EXTRA_COMPONENTS_CONFIGMAKE@ + endif + ifeq ($(TARGET_ARCH_ABI),mips) + OPENCV_3RDPARTY_COMPONENTS:=@OPENCV_3RDPARTY_COMPONENTS_CONFIGMAKE_NO_TBB@ + OPENCV_EXTRA_COMPONENTS:=@OPENCV_EXTRA_COMPONENTS_CONFIGMAKE@ + endif endif ifeq (${OPENCV_CAMERA_MODULES},on) diff --git a/doc/tutorials/introduction/android_binary_package/dev_with_OCV_on_Android.rst b/doc/tutorials/introduction/android_binary_package/dev_with_OCV_on_Android.rst index f7f0c4718..0943b043c 100644 --- a/doc/tutorials/introduction/android_binary_package/dev_with_OCV_on_Android.rst +++ b/doc/tutorials/introduction/android_binary_package/dev_with_OCV_on_Android.rst @@ -260,224 +260,119 @@ To build your own Android application, which uses OpenCV from native part, the f #. Either use :ref:`manual ` ``ndk-build`` invocation or :ref:`setup Eclipse CDT Builder ` to build native JNI lib before Java part [re]build and APK creation. -Hello OpenCV Sample -=================== +"Hello OpenCV" Sample +===================== -Here are basic steps to guide you trough the process of creating a simple OpenCV-centric application. +Here are basic steps to guide you trough the creation process of a simple OpenCV-centric application. It will be capable of accessing camera output, processing it and displaying the result. -#. Open Eclipse IDE, create a new clean workspace, create a new Android project (*File -> New -> Android Project*). +#. Open Eclipse IDE, create a new clean workspace, create a new Android project (:guilabel:`File -> New -> Android Project`). -#. Set name, target, package and minSDKVersion accordingly. +#. Set name, target, package and ``minSDKVersion`` accordingly. -#. Create a new class (*File -> New -> Class*). Name it for example: *HelloOpenCVView*. - - .. image:: images/dev_OCV_new_class.png - :alt: Add a new class. - :align: center - - * It should extend *SurfaceView* class. - * It also should implement *SurfaceHolder.Callback*, *Runnable*. - -#. Edit *HelloOpenCVView* class. - - * Add an *import* line for *android.content.context*. - - * Modify autogenerated stubs: *HelloOpenCVView*, *surfaceCreated*, *surfaceDestroyed* and *surfaceChanged*. - - .. code-block:: java - :linenos: - - package com.hello.opencv.test; - - import android.content.Context; - - public class HelloOpenCVView extends SurfaceView implements Callback, Runnable { - - public HelloOpenCVView(Context context) { - super(context); - getHolder().addCallback(this); - } - - public void surfaceCreated(SurfaceHolder holder) { - (new Thread(this)).start(); - } - - public void surfaceDestroyed(SurfaceHolder holder) { - cameraRelease(); - } - - public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { - cameraSetup(width, height); - } - - //... - - * Add *cameraOpen*, *cameraRelease* and *cameraSetup* voids as shown below. - - * Also, don't forget to add the public void *run()* as follows: - - .. code-block:: java - :linenos: - - public void run() { - // TODO: loop { getFrame(), processFrame(), drawFrame() } - } - - public boolean cameraOpen() { - return false; //TODO: open camera - } - - private void cameraRelease() { - // TODO release camera - } - - private void cameraSetup(int width, int height) { - // TODO setup camera - } - -#. Create a new *Activity* (*New -> Other -> Android -> Android Activity*) and name it, for example: *HelloOpenCVActivity*. For this activity define *onCreate*, *onResume* and *onPause* voids. - - .. code-block:: java - :linenos: - - public void onCreate (Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - mView = new HelloOpenCVView(this); - setContentView (mView); - } - - protected void onPause() { - super.onPause(); - mView.cameraRelease(); - } - - protected void onResume() { - super.onResume(); - if( !mView.cameraOpen() ) { - // MessageBox and exit app - AlertDialog ad = new AlertDialog.Builder(this).create(); - ad.setCancelable(false); // This blocks the "BACK" button - ad.setMessage("Fatal error: can't open camera!"); - ad.setButton("OK", new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - dialog.dismiss(); - finish(); - } - }); - ad.show(); - } - } - -#. Add the following permissions to the AndroidManifest.xml file: +#. Add the following permissions to the ``AndroidManifest.xml`` file: .. code-block:: xml :linenos: - + - - - + + + + -#. Reference OpenCV library within your project properties. +#. Reference the OpenCV library within your project properties. .. image:: images/dev_OCV_reference.png :alt: Reference OpenCV library. :align: center -#. We now need some code to handle the camera. Update the *HelloOpenCVView* class as follows: +#. Create new view layout for your application, lets name it ``hello_opencv.xml``, and add the following to it: + + .. code-block:: xml + :linenos: + + + + + + + +#. Remove default auto generated layout, if exists. + +#. Create a new ``Activity`` (:guilabel:`New -> Other -> Android -> Android Activity`) and name it, for example: ``HelloOpenCVActivity``. + Add ``CvCameraViewListener`` interface to ``implements`` list of ``HelloOpenCVActivity`` class. Add the following code to activity implementation: .. code-block:: java :linenos: - private VideoCapture mCamera; + public class Sample1Java extends Activity implements CvCameraViewListener { - public boolean cameraOpen() { - synchronized (this) { - cameraRelease(); - mCamera = new VideoCapture(Highgui.CV_CAP_ANDROID); - if (!mCamera.isOpened()) { - mCamera.release(); - mCamera = null; - Log.e("HelloOpenCVView", "Failed to open native camera"); - return false; - } - } - return true; - } + private CameraBridgeViewBase mOpenCvCameraView; - public void cameraRelease() { - synchronized(this) { - if (mCamera != null) { - mCamera.release(); - mCamera = null; - } - } - } - - private void cameraSetup(int width, int height) { - synchronized (this) { - if (mCamera != null && mCamera.isOpened()) { - List sizes = mCamera.getSupportedPreviewSizes(); - int mFrameWidth = width; - int mFrameHeight = height; - { // selecting optimal camera preview size - double minDiff = Double.MAX_VALUE; - for (Size size : sizes) { - if (Math.abs(size.height - height) < minDiff) { - mFrameWidth = (int) size.width; - mFrameHeight = (int) size.height; - minDiff = Math.abs(size.height - height); - } - } + private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) { + @Override + public void onManagerConnected(int status) { + switch (status) { + case LoaderCallbackInterface.SUCCESS: { + Log.i(TAG, "OpenCV loaded successfully"); + mOpenCvCameraView.enableView(); + } break; + default: + super.onManagerConnected(status); } - mCamera.set(Highgui.CV_CAP_PROP_FRAME_WIDTH, mFrameWidth); - mCamera.set(Highgui.CV_CAP_PROP_FRAME_HEIGHT, mFrameHeight); - } - } - } + } + }; -#. The last step would be to update the *run()* void in *HelloOpenCVView* class as follows: + /** Called when the activity is first created. */ + @Override + public void onCreate(Bundle savedInstanceState) { + Log.i(TAG, "called onCreate"); + super.onCreate(savedInstanceState); + requestWindowFeature(Window.FEATURE_NO_TITLE); + getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + setContentView(R.layout.hello_opencv); + mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.java_surface_view); + mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE); + mOpenCvCameraView.setCvCameraViewListener(this); + } - .. code-block:: java - :linenos: + @Override + public void onPause() + { + if (mOpenCvCameraView != null) + mOpenCvCameraView.disableView(); + super.onPause(); + } - public void run() { - while (true) { - Bitmap bmp = null; - synchronized (this) { - if (mCamera == null) - break; - if (!mCamera.grab()) - break; + @Override + public void onResume() + { + super.onResume(); + OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_3, this, mLoaderCallback); + } - bmp = processFrame(mCamera); - } - if (bmp != null) { - Canvas canvas = getHolder().lockCanvas(); - if (canvas != null) { - canvas.drawBitmap(bmp, (canvas.getWidth() - bmp.getWidth()) / 2, - (canvas.getHeight() - bmp.getHeight()) / 2, null); - getHolder().unlockCanvasAndPost(canvas); + public void onDestroy() { + super.onDestroy(); + if (mOpenCvCameraView != null) + mOpenCvCameraView.disableView(); + } - } - bmp.recycle(); - } - } - } + public void onCameraViewStarted(int width, int height) { + } - protected Bitmap processFrame(VideoCapture capture) { - Mat mRgba = new Mat(); - capture.retrieve(mRgba, Highgui.CV_CAP_ANDROID_COLOR_FRAME_RGBA); - //process mRgba - Bitmap bmp = Bitmap.createBitmap(mRgba.cols(), mRgba.rows(), Bitmap.Config.ARGB_8888); - try { - Utils.matToBitmap(mRgba, bmp); - } catch(Exception e) { - Log.e("processFrame", "Utils.matToBitmap() throws an exception: " + e.getMessage()); - bmp.recycle(); - bmp = null; - } - return bmp; - } + public void onCameraViewStopped() { + } + + public Mat onCameraFrame(Mat inputFrame) { + return inputFrame; + } + } diff --git a/modules/calib3d/perf/perf_precomp.hpp b/modules/calib3d/perf/perf_precomp.hpp index 891d50e05..6cee5b90e 100644 --- a/modules/calib3d/perf/perf_precomp.hpp +++ b/modules/calib3d/perf/perf_precomp.hpp @@ -1,6 +1,6 @@ #ifdef __GNUC__ # pragma GCC diagnostic ignored "-Wmissing-declarations" -# ifdef __clang__ +# if defined __clang__ || defined __APPLE__ # pragma GCC diagnostic ignored "-Wmissing-prototypes" # pragma GCC diagnostic ignored "-Wextra" # endif diff --git a/modules/calib3d/test/test_precomp.hpp b/modules/calib3d/test/test_precomp.hpp index 2d1f35702..e0fcd486d 100644 --- a/modules/calib3d/test/test_precomp.hpp +++ b/modules/calib3d/test/test_precomp.hpp @@ -1,6 +1,6 @@ #ifdef __GNUC__ # pragma GCC diagnostic ignored "-Wmissing-declarations" -# ifdef __clang__ +# if defined __clang__ || defined __APPLE__ # pragma GCC diagnostic ignored "-Wmissing-prototypes" # pragma GCC diagnostic ignored "-Wextra" # endif diff --git a/modules/contrib/include/opencv2/contrib/contrib.hpp b/modules/contrib/include/opencv2/contrib/contrib.hpp index e600583c8..94f5cb096 100644 --- a/modules/contrib/include/opencv2/contrib/contrib.hpp +++ b/modules/contrib/include/opencv2/contrib/contrib.hpp @@ -583,7 +583,7 @@ namespace cv virtual ~StereoVar(); //! the stereo correspondence operator that computes disparity map for the specified rectified stereo pair - CV_WRAP_AS(compute) virtual void operator()(const Mat& left, const Mat& right, Mat& disp); + CV_WRAP_AS(compute) virtual void operator()(const Mat& left, const Mat& right, CV_OUT Mat& disp); CV_PROP_RW int levels; CV_PROP_RW double pyrScale; diff --git a/modules/contrib/src/detection_based_tracker.cpp b/modules/contrib/src/detection_based_tracker.cpp index 238ac5c3e..11263a8fc 100644 --- a/modules/contrib/src/detection_based_tracker.cpp +++ b/modules/contrib/src/detection_based_tracker.cpp @@ -1,6 +1,8 @@ #if defined(__linux__) || defined(LINUX) || defined(__APPLE__) || defined(ANDROID) #include "opencv2/contrib/detection_based_tracker.hpp" +#include + #if defined(DEBUG) || defined(_DEBUG) #undef DEBUGLOGS #define DEBUGLOGS 1 @@ -12,7 +14,6 @@ #ifdef ANDROID #include -#include #define LOG_TAG "OBJECT_DETECTOR" #define LOGD0(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)) #define LOGI0(...) ((void)__android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)) diff --git a/modules/contrib/src/facerec.cpp b/modules/contrib/src/facerec.cpp index 7a8ab7420..bc41a86a0 100644 --- a/modules/contrib/src/facerec.cpp +++ b/modules/contrib/src/facerec.cpp @@ -300,7 +300,13 @@ public: //------------------------------------------------------------------------------ // FaceRecognizer //------------------------------------------------------------------------------ -void FaceRecognizer::update(InputArrayOfArrays, InputArray) { +void FaceRecognizer::update(InputArrayOfArrays src, InputArray labels ) { + if( dynamic_cast(this) != 0 ) + { + dynamic_cast(this)->update( src, labels ); + return; + } + string error_msg = format("This FaceRecognizer (%s) does not support updating, you have to use FaceRecognizer::train to update it.", this->name().c_str()); CV_Error(CV_StsNotImplemented, error_msg); } diff --git a/modules/contrib/test/test_precomp.hpp b/modules/contrib/test/test_precomp.hpp index 2a7a3d44b..d477eddbb 100644 --- a/modules/contrib/test/test_precomp.hpp +++ b/modules/contrib/test/test_precomp.hpp @@ -1,6 +1,6 @@ #ifdef __GNUC__ # pragma GCC diagnostic ignored "-Wmissing-declarations" -# ifdef __clang__ +# if defined __clang__ || defined __APPLE__ # pragma GCC diagnostic ignored "-Wmissing-prototypes" # pragma GCC diagnostic ignored "-Wextra" # endif diff --git a/modules/core/include/opencv2/core/core.hpp b/modules/core/include/opencv2/core/core.hpp index 206ac9441..60d9d013c 100644 --- a/modules/core/include/opencv2/core/core.hpp +++ b/modules/core/include/opencv2/core/core.hpp @@ -204,11 +204,11 @@ CV_EXPORTS ErrorCallback redirectError( ErrorCallback errCallback, #ifdef __GNUC__ #define CV_Error( code, msg ) cv::error( cv::Exception(code, msg, __func__, __FILE__, __LINE__) ) #define CV_Error_( code, args ) cv::error( cv::Exception(code, cv::format args, __func__, __FILE__, __LINE__) ) -#define CV_Assert( expr ) if((expr)) ; else cv::error( cv::Exception(CV_StsAssert, #expr, __func__, __FILE__, __LINE__) ) +#define CV_Assert( expr ) if(!!(expr)) ; else cv::error( cv::Exception(CV_StsAssert, #expr, __func__, __FILE__, __LINE__) ) #else #define CV_Error( code, msg ) cv::error( cv::Exception(code, msg, "", __FILE__, __LINE__) ) #define CV_Error_( code, args ) cv::error( cv::Exception(code, cv::format args, "", __FILE__, __LINE__) ) -#define CV_Assert( expr ) if((expr)) ; else cv::error( cv::Exception(CV_StsAssert, #expr, "", __FILE__, __LINE__) ) +#define CV_Assert( expr ) if(!!(expr)) ; else cv::error( cv::Exception(CV_StsAssert, #expr, "", __FILE__, __LINE__) ) #endif #ifdef _DEBUG diff --git a/modules/core/include/opencv2/core/operations.hpp b/modules/core/include/opencv2/core/operations.hpp index 4b6e60616..e3ebe6e67 100644 --- a/modules/core/include/opencv2/core/operations.hpp +++ b/modules/core/include/opencv2/core/operations.hpp @@ -56,7 +56,7 @@ #define CV_XADD(addr,delta) _InterlockedExchangeAdd(const_cast(reinterpret_cast(addr)), delta) #elif defined __GNUC__ - #if defined __clang__ && __clang_major__ >= 3 + #if defined __clang__ && __clang_major__ >= 3 && !defined __ANDROID__ #ifdef __ATOMIC_SEQ_CST #define CV_XADD(addr, delta) __c11_atomic_fetch_add((_Atomic(int)*)(addr), (delta), __ATOMIC_SEQ_CST) #else @@ -3873,10 +3873,21 @@ template inline std::ostream& operator<<(std::ostream& out, const template inline std::ostream& operator<<(std::ostream& out, const Vec<_Tp, n>& vec) { out << "["; - for (int i = 0; i < n - 1; ++i) { - out << vec[i] << ", "; + + if(Vec<_Tp, n>::depth < CV_32F) + { + for (int i = 0; i < n - 1; ++i) { + out << (int)vec[i] << ", "; + } + out << (int)vec[n-1] << "]"; + } + else + { + for (int i = 0; i < n - 1; ++i) { + out << vec[i] << ", "; + } + out << vec[n-1] << "]"; } - out << vec[n-1] << "]"; return out; } diff --git a/modules/core/perf/perf_precomp.hpp b/modules/core/perf/perf_precomp.hpp index 9417bc364..4d5d9886e 100644 --- a/modules/core/perf/perf_precomp.hpp +++ b/modules/core/perf/perf_precomp.hpp @@ -1,6 +1,6 @@ #ifdef __GNUC__ # pragma GCC diagnostic ignored "-Wmissing-declarations" -# ifdef __clang__ +# if defined __clang__ || defined __APPLE__ # pragma GCC diagnostic ignored "-Wmissing-prototypes" # pragma GCC diagnostic ignored "-Wextra" # endif diff --git a/modules/core/src/lapack.cpp b/modules/core/src/lapack.cpp index 4d179022e..1abffa8b3 100644 --- a/modules/core/src/lapack.cpp +++ b/modules/core/src/lapack.cpp @@ -954,7 +954,7 @@ double cv::invert( InputArray _src, OutputArray _dst, int method ) size_t esz = CV_ELEM_SIZE(type); int m = src.rows, n = src.cols; - if( method == DECOMP_SVD ) + if( method == DECOMP_SVD ) { int nm = std::min(m, n); @@ -1101,62 +1101,21 @@ double cv::invert( InputArray _src, OutputArray _dst, int method ) result = true; d = 1./d; - #if CV_SSE2 - if(USE_SSE2) - { - __m128 det =_mm_set1_ps((float)d); - __m128 s0 = _mm_loadu_ps((const float*)srcdata);//s0 = Sf(0,0) Sf(0,1) Sf(0,2) *** - __m128 s1 = _mm_loadu_ps((const float*)(srcdata+srcstep));//s1 = Sf(1,0) Sf(1,1) Sf(1,2) *** - __m128 s2 = _mm_set_ps(0.f, Sf(2,2), Sf(2,1), Sf(2,0)); //s2 = Sf(2,0) Sf(2,1) Sf(2,2) *** + t[0] = (float)(((double)Sf(1,1) * Sf(2,2) - (double)Sf(1,2) * Sf(2,1)) * d); + t[1] = (float)(((double)Sf(0,2) * Sf(2,1) - (double)Sf(0,1) * Sf(2,2)) * d); + t[2] = (float)(((double)Sf(0,1) * Sf(1,2) - (double)Sf(0,2) * Sf(1,1)) * d); - __m128 r0 = _mm_shuffle_ps(s1,s1,_MM_SHUFFLE(3,0,2,1)); //r0 = Sf(1,1) Sf(1,2) Sf(1,0) *** - __m128 r1 = _mm_shuffle_ps(s2,s2,_MM_SHUFFLE(3,1,0,2)); //r1 = Sf(2,2) Sf(2,0) Sf(2,1) *** - __m128 r2 = _mm_shuffle_ps(s2,s2,_MM_SHUFFLE(3,0,2,1)); //r2 = Sf(2,1) Sf(2,2) Sf(2,0) *** + t[3] = (float)(((double)Sf(1,2) * Sf(2,0) - (double)Sf(1,0) * Sf(2,2)) * d); + t[4] = (float)(((double)Sf(0,0) * Sf(2,2) - (double)Sf(0,2) * Sf(2,0)) * d); + t[5] = (float)(((double)Sf(0,2) * Sf(1,0) - (double)Sf(0,0) * Sf(1,2)) * d); - __m128 t0 = _mm_mul_ps(s0, r0);//t0 = Sf(0,0)*Sf(1,1) Sf(0,1)*Sf(1,2) Sf(0,2)*Sf(1,0) *** - __m128 t1 = _mm_mul_ps(s0, r1);//t1 = Sf(0,0)*Sf(2,2) Sf(0,1)*Sf(2,0) Sf(0,2)*Sf(2,1) *** - __m128 t2 = _mm_mul_ps(s1, r2);//t2 = Sf(1,0)*Sf(2,1) Sf(1,1)*Sf(2,2) Sf(1,2)*Sf(2,0) *** + t[6] = (float)(((double)Sf(1,0) * Sf(2,1) - (double)Sf(1,1) * Sf(2,0)) * d); + t[7] = (float)(((double)Sf(0,1) * Sf(2,0) - (double)Sf(0,0) * Sf(2,1)) * d); + t[8] = (float)(((double)Sf(0,0) * Sf(1,1) - (double)Sf(0,1) * Sf(1,0)) * d); - __m128 r3 = _mm_shuffle_ps(s0,s0,_MM_SHUFFLE(3,0,2,1));//r3 = Sf(0,1) Sf(0,2) Sf(0,0) *** - __m128 r4 = _mm_shuffle_ps(s0,s0,_MM_SHUFFLE(3,1,0,2));//r4 = Sf(0,2) Sf(0,0) Sf(0,1) *** - - __m128 t00 = _mm_mul_ps(s1, r3);//t00 = Sf(1,0)*Sf(0,1) Sf(1,1)*Sf(0,2) Sf(1,2)*Sf(0,0) *** - __m128 t11 = _mm_mul_ps(s2, r4);//t11 = Sf(2,0)*Sf(0,2) Sf(2,1)*Sf(0,0) Sf(2,2)*Sf(0,1) *** - __m128 t22 = _mm_mul_ps(s2, r0);//t22 = Sf(2,0)*Sf(1,1) Sf(2,1)*Sf(1,2) Sf(2,2)*Sf(1,0) *** - - t0 = _mm_mul_ps(_mm_sub_ps(t0,t00), det);//Sf(0,0)*Sf(1,1) Sf(0,1)*Sf(1,2) Sf(0,2)*Sf(1,0) *** - //-Sf(1,0)*Sf(0,1) -Sf(1,1)*Sf(0,2) -Sf(1,2)*Sf(0,0) - t1 = _mm_mul_ps(_mm_sub_ps(t1,t11), det);//Sf(0,0)*Sf(2,2) Sf(0,1)*Sf(2,0) Sf(0,2)*Sf(2,1) *** - //-Sf(2,0)*Sf(0,2) -Sf(2,1)*Sf(0,0) -Sf(2,2)*Sf(0,1) - t2 = _mm_mul_ps(_mm_sub_ps(t2,t22), det);//Sf(1,0)*Sf(2,1) Sf(1,1)*Sf(2,2) Sf(1,2)*Sf(2,0) *** - //-Sf(2,0)*Sf(1,1) -Sf(2,1)*Sf(1,2) -Sf(2,2)*Sf(1,0) - _mm_store_ps(t, t0); - _mm_store_ps(t+4, t1); - _mm_store_ps(t+8, t2); - - Df(0,0) = t[9]; Df(0,1) = t[6]; Df(0,2) = t[1]; - Df(1,0) = t[10]; Df(1,1) = t[4]; Df(1,2) = t[2]; - Df(2,0) = t[8]; Df(2,1) = t[5]; Df(2,2) = t[0]; - } - else - #endif - { - t[0] = (float)(((double)Sf(1,1) * Sf(2,2) - (double)Sf(1,2) * Sf(2,1)) * d); - t[1] = (float)(((double)Sf(0,2) * Sf(2,1) - (double)Sf(0,1) * Sf(2,2)) * d); - t[2] = (float)(((double)Sf(0,1) * Sf(1,2) - (double)Sf(0,2) * Sf(1,1)) * d); - - t[3] = (float)(((double)Sf(1,2) * Sf(2,0) - (double)Sf(1,0) * Sf(2,2)) * d); - t[4] = (float)(((double)Sf(0,0) * Sf(2,2) - (double)Sf(0,2) * Sf(2,0)) * d); - t[5] = (float)(((double)Sf(0,2) * Sf(1,0) - (double)Sf(0,0) * Sf(1,2)) * d); - - t[6] = (float)(((double)Sf(1,0) * Sf(2,1) - (double)Sf(1,1) * Sf(2,0)) * d); - t[7] = (float)(((double)Sf(0,1) * Sf(2,0) - (double)Sf(0,0) * Sf(2,1)) * d); - t[8] = (float)(((double)Sf(0,0) * Sf(1,1) - (double)Sf(0,1) * Sf(1,0)) * d); - - Df(0,0) = t[0]; Df(0,1) = t[1]; Df(0,2) = t[2]; - Df(1,0) = t[3]; Df(1,1) = t[4]; Df(1,2) = t[5]; - Df(2,0) = t[6]; Df(2,1) = t[7]; Df(2,2) = t[8]; - } + Df(0,0) = t[0]; Df(0,1) = t[1]; Df(0,2) = t[2]; + Df(1,0) = t[3]; Df(1,1) = t[4]; Df(1,2) = t[5]; + Df(2,0) = t[6]; Df(2,1) = t[7]; Df(2,2) = t[8]; } } else diff --git a/modules/core/src/opengl_interop.cpp b/modules/core/src/opengl_interop.cpp index c4d1c9849..12589b7ba 100644 --- a/modules/core/src/opengl_interop.cpp +++ b/modules/core/src/opengl_interop.cpp @@ -45,6 +45,14 @@ #include "opencv2/core/opengl_interop.hpp" #include "opencv2/core/gpumat.hpp" +#if defined WIN32 || defined _WIN32 || defined WINCE +#include +#undef small +#undef min +#undef max +#undef abs +#endif + #ifdef HAVE_OPENGL #ifdef __APPLE__ #include diff --git a/modules/core/test/test_mat.cpp b/modules/core/test/test_mat.cpp index e30da7258..cf045e720 100644 --- a/modules/core/test/test_mat.cpp +++ b/modules/core/test/test_mat.cpp @@ -863,17 +863,17 @@ template int calcDiffElemCountImpl(const vector& mv, const Mat& m) { int diffElemCount = 0; - const size_t mChannels = m.channels(); + const int mChannels = m.channels(); for(int y = 0; y < m.rows; y++) { for(int x = 0; x < m.cols; x++) { const ElemType* mElem = &m.at(y,x*mChannels); - size_t loc = 0; + int loc = 0; for(size_t i = 0; i < mv.size(); i++) { const size_t mvChannel = mv[i].channels(); - const ElemType* mvElem = &mv[i].at(y,x*mvChannel); + const ElemType* mvElem = &mv[i].at(y,x*(int)mvChannel); for(size_t li = 0; li < mvChannel; li++) if(mElem[loc + li] != mvElem[li]) diffElemCount++; @@ -1020,7 +1020,7 @@ public: protected: virtual int run_case(int depth, size_t channels, const Size& size, RNG& rng) { - Mat src(size, CV_MAKETYPE(depth, channels)); + Mat src(size, CV_MAKETYPE(depth, (int)channels)); rng.fill(src, RNG::UNIFORM, 0, 100, true); vector dst; diff --git a/modules/core/test/test_math.cpp b/modules/core/test/test_math.cpp index 5dd845062..0558ab0c2 100644 --- a/modules/core/test/test_math.cpp +++ b/modules/core/test/test_math.cpp @@ -2421,7 +2421,7 @@ protected: } Mat diff = abs(anglesInDegrees - resInDeg); - int errDegCount = diff.total() - countNonZero((diff < maxAngleDiff) | ((360 - diff) < maxAngleDiff)); + size_t errDegCount = diff.total() - countNonZero((diff < maxAngleDiff) | ((360 - diff) < maxAngleDiff)); if(errDegCount > 0) { ts->printf(cvtest::TS::LOG, "There are incorrect result angles (in degrees) (part of them is %f)\n", @@ -2546,6 +2546,21 @@ REGISTER_TYPED_TEST_CASE_P(Core_CheckRange, Negative, Positive, Bounds, Zero); typedef ::testing::Types mat_data_types; INSTANTIATE_TYPED_TEST_CASE_P(Negative_Test, Core_CheckRange, mat_data_types); +TEST(Core_Invert, small) +{ + cv::Mat a = (cv::Mat_(3,3) << 2.42104644730331, 1.81444796521479, -3.98072565304758, 0, 7.08389214348967e-3, 5.55326770986007e-3, 0,0, 7.44556154284261e-3); + //cv::randu(a, -1, 1); + + cv::Mat b = a.t()*a; + cv::Mat c, i = Mat_::eye(3, 3); + cv::invert(b, c, cv::DECOMP_LU); //std::cout << b*c << std::endl; + ASSERT_LT( cv::norm(b*c, i, CV_C), 0.1 ); + cv::invert(b, c, cv::DECOMP_SVD); //std::cout << b*c << std::endl; + ASSERT_LT( cv::norm(b*c, i, CV_C), 0.1 ); + cv::invert(b, c, cv::DECOMP_CHOLESKY); //std::cout << b*c << std::endl; + ASSERT_LT( cv::norm(b*c, i, CV_C), 0.1 ); +} + ///////////////////////////////////////////////////////////////////////////////////////////////////// TEST(Core_CovarMatrix, accuracy) { Core_CovarMatrixTest test; test.safe_run(); } diff --git a/modules/core/test/test_precomp.hpp b/modules/core/test/test_precomp.hpp index 6f1b188cc..5cbe1c8f9 100644 --- a/modules/core/test/test_precomp.hpp +++ b/modules/core/test/test_precomp.hpp @@ -1,6 +1,6 @@ #ifdef __GNUC__ # pragma GCC diagnostic ignored "-Wmissing-declarations" -# ifdef __clang__ +# if defined __clang__ || defined __APPLE__ # pragma GCC diagnostic ignored "-Wmissing-prototypes" # pragma GCC diagnostic ignored "-Wextra" # endif diff --git a/modules/features2d/perf/perf_precomp.hpp b/modules/features2d/perf/perf_precomp.hpp index 1f3ad1fe9..c3f98c217 100644 --- a/modules/features2d/perf/perf_precomp.hpp +++ b/modules/features2d/perf/perf_precomp.hpp @@ -1,6 +1,6 @@ #ifdef __GNUC__ # pragma GCC diagnostic ignored "-Wmissing-declarations" -# ifdef __clang__ +# if defined __clang__ || defined __APPLE__ # pragma GCC diagnostic ignored "-Wmissing-prototypes" # pragma GCC diagnostic ignored "-Wextra" # endif diff --git a/modules/features2d/test/test_precomp.hpp b/modules/features2d/test/test_precomp.hpp index 28985f944..bc2d8be6e 100644 --- a/modules/features2d/test/test_precomp.hpp +++ b/modules/features2d/test/test_precomp.hpp @@ -1,6 +1,6 @@ #ifdef __GNUC__ # pragma GCC diagnostic ignored "-Wmissing-declarations" -# ifdef __clang__ +# if defined __clang__ || defined __APPLE__ # pragma GCC diagnostic ignored "-Wmissing-prototypes" # pragma GCC diagnostic ignored "-Wextra" # endif diff --git a/modules/gpu/CMakeLists.txt b/modules/gpu/CMakeLists.txt index 580e7dfb9..78aafcf92 100644 --- a/modules/gpu/CMakeLists.txt +++ b/modules/gpu/CMakeLists.txt @@ -15,10 +15,10 @@ file(GLOB lib_cuda_hdrs "src/cuda/*.hpp" "src/cuda/*.h") file(GLOB lib_srcs "src/*.cpp") file(GLOB lib_cuda "src/cuda/*.cu*") -source_group("Include" FILES ${lib_hdrs}) -source_group("Src\\Host" FILES ${lib_srcs} ${lib_int_hdrs}) -source_group("Src\\Cuda" FILES ${lib_cuda} ${lib_cuda_hdrs}) -source_group("Device" FILES ${lib_device_hdrs}) +source_group("Include" FILES ${lib_hdrs}) +source_group("Src\\Host" FILES ${lib_srcs} ${lib_int_hdrs}) +source_group("Src\\Cuda" FILES ${lib_cuda} ${lib_cuda_hdrs}) +source_group("Device" FILES ${lib_device_hdrs}) source_group("Device\\Detail" FILES ${lib_device_hdrs_detail}) if (HAVE_CUDA) diff --git a/modules/gpu/perf/perf_precomp.hpp b/modules/gpu/perf/perf_precomp.hpp index 04ccfdef3..4dca93c44 100644 --- a/modules/gpu/perf/perf_precomp.hpp +++ b/modules/gpu/perf/perf_precomp.hpp @@ -1,6 +1,6 @@ #ifdef __GNUC__ # pragma GCC diagnostic ignored "-Wmissing-declarations" -# ifdef __clang__ +# if defined __clang__ || defined __APPLE__ # pragma GCC diagnostic ignored "-Wmissing-prototypes" # pragma GCC diagnostic ignored "-Wextra" # endif diff --git a/modules/gpu/src/cuda/hough.cu b/modules/gpu/src/cuda/hough.cu index ac65b360a..ee4d02591 100644 --- a/modules/gpu/src/cuda/hough.cu +++ b/modules/gpu/src/cuda/hough.cu @@ -236,7 +236,7 @@ namespace cv { namespace gpu { namespace device const int r = blockIdx.x * blockDim.x + threadIdx.x; const int n = blockIdx.y * blockDim.y + threadIdx.y; - if (r >= accum.cols - 2 && n >= accum.rows - 2) + if (r >= accum.cols - 2 || n >= accum.rows - 2) return; const int curVotes = accum(n + 1, r + 1); diff --git a/modules/gpu/test/test_precomp.hpp b/modules/gpu/test/test_precomp.hpp index 3e6abef82..b75f8edd8 100644 --- a/modules/gpu/test/test_precomp.hpp +++ b/modules/gpu/test/test_precomp.hpp @@ -41,7 +41,7 @@ #ifdef __GNUC__ # pragma GCC diagnostic ignored "-Wmissing-declarations" -# ifdef __clang__ +# if defined __clang__ || defined __APPLE__ # pragma GCC diagnostic ignored "-Wmissing-prototypes" # pragma GCC diagnostic ignored "-Wextra" # endif diff --git a/modules/highgui/perf/perf_precomp.hpp b/modules/highgui/perf/perf_precomp.hpp index fc9c3b8b2..2b57ad7ee 100644 --- a/modules/highgui/perf/perf_precomp.hpp +++ b/modules/highgui/perf/perf_precomp.hpp @@ -1,6 +1,6 @@ #ifdef __GNUC__ # pragma GCC diagnostic ignored "-Wmissing-declarations" -# ifdef __clang__ +# if defined __clang__ || defined __APPLE__ # pragma GCC diagnostic ignored "-Wmissing-prototypes" # pragma GCC diagnostic ignored "-Wextra" # endif diff --git a/modules/highgui/src/window.cpp b/modules/highgui/src/window.cpp index 9fe9bc781..e6b3b1f7a 100644 --- a/modules/highgui/src/window.cpp +++ b/modules/highgui/src/window.cpp @@ -571,6 +571,56 @@ int cv::createButton(const string& button_name, ButtonCallback on_change, void* return cvCreateButton(button_name.c_str(), on_change, userdata, button_type , initial_button_state ); } +#else + +CvFont cv::fontQt(const string&, int, Scalar, int, int, int) +{ + CV_Error(CV_StsNotImplemented, "The library is compiled without QT support"); + return CvFont(); +} + +void cv::addText( const Mat&, const string&, Point, CvFont) +{ + CV_Error(CV_StsNotImplemented, "The library is compiled without QT support"); +} + +void cv::displayStatusBar(const string&, const string&, int) +{ + CV_Error(CV_StsNotImplemented, "The library is compiled without QT support"); +} + +void cv::displayOverlay(const string&, const string&, int ) +{ + CV_Error(CV_StsNotImplemented, "The library is compiled without QT support"); +} + +int cv::startLoop(int (*)(int argc, char *argv[]), int , char**) +{ + CV_Error(CV_StsNotImplemented, "The library is compiled without QT support"); + return 0; +} + +void cv::stopLoop() +{ + CV_Error(CV_StsNotImplemented, "The library is compiled without QT support"); +} + +void cv::saveWindowParameters(const string&) +{ + CV_Error(CV_StsNotImplemented, "The library is compiled without QT support"); +} + +void cv::loadWindowParameters(const string&) +{ + CV_Error(CV_StsNotImplemented, "The library is compiled without QT support"); +} + +int cv::createButton(const string&, ButtonCallback, void*, int , bool ) +{ + CV_Error(CV_StsNotImplemented, "The library is compiled without QT support"); + return 0; +} + #endif #if defined WIN32 || defined _WIN32 // see window_w32.cpp diff --git a/modules/highgui/test/test_precomp.hpp b/modules/highgui/test/test_precomp.hpp index 6941a0c6e..3286c0f59 100644 --- a/modules/highgui/test/test_precomp.hpp +++ b/modules/highgui/test/test_precomp.hpp @@ -1,6 +1,6 @@ #ifdef __GNUC__ # pragma GCC diagnostic ignored "-Wmissing-declarations" -# ifdef __clang__ +# if defined __clang__ || defined __APPLE__ # pragma GCC diagnostic ignored "-Wmissing-prototypes" # pragma GCC diagnostic ignored "-Wextra" # endif diff --git a/modules/imgproc/perf/perf_precomp.hpp b/modules/imgproc/perf/perf_precomp.hpp index 9120beec8..304802491 100644 --- a/modules/imgproc/perf/perf_precomp.hpp +++ b/modules/imgproc/perf/perf_precomp.hpp @@ -1,6 +1,6 @@ #ifdef __GNUC__ # pragma GCC diagnostic ignored "-Wmissing-declarations" -# ifdef __clang__ +# if defined __clang__ || defined __APPLE__ # pragma GCC diagnostic ignored "-Wmissing-prototypes" # pragma GCC diagnostic ignored "-Wextra" # endif diff --git a/modules/imgproc/test/test_precomp.hpp b/modules/imgproc/test/test_precomp.hpp index 493a09d36..4c973c1ae 100644 --- a/modules/imgproc/test/test_precomp.hpp +++ b/modules/imgproc/test/test_precomp.hpp @@ -1,6 +1,6 @@ #ifdef __GNUC__ # pragma GCC diagnostic ignored "-Wmissing-declarations" -# ifdef __clang__ +# if defined __clang__ || defined __APPLE__ # pragma GCC diagnostic ignored "-Wmissing-prototypes" # pragma GCC diagnostic ignored "-Wextra" # endif diff --git a/modules/java/android_lib/.settings/org.eclipse.jdt.core.prefs b/modules/java/android_lib/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index 53e049515..000000000 --- a/modules/java/android_lib/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,5 +0,0 @@ -#Wed Jun 29 04:36:40 MSD 2011 -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 -org.eclipse.jdt.core.compiler.compliance=1.5 -org.eclipse.jdt.core.compiler.source=1.5 diff --git a/modules/java/android_test/.settings/org.eclipse.jdt.core.prefs b/modules/java/android_test/.settings/org.eclipse.jdt.core.prefs index 53e049515..b080d2ddc 100644 --- a/modules/java/android_test/.settings/org.eclipse.jdt.core.prefs +++ b/modules/java/android_test/.settings/org.eclipse.jdt.core.prefs @@ -1,5 +1,4 @@ -#Wed Jun 29 04:36:40 MSD 2011 eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 -org.eclipse.jdt.core.compiler.compliance=1.5 -org.eclipse.jdt.core.compiler.source=1.5 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/modules/java/android_test/src/org/opencv/test/OpenCVTestCase.java b/modules/java/android_test/src/org/opencv/test/OpenCVTestCase.java index 102adf195..b24d858ee 100644 --- a/modules/java/android_test/src/org/opencv/test/OpenCVTestCase.java +++ b/modules/java/android_test/src/org/opencv/test/OpenCVTestCase.java @@ -23,15 +23,20 @@ import org.opencv.features2d.DMatch; import org.opencv.features2d.KeyPoint; import org.opencv.highgui.Highgui; -public class OpenCVTestCase extends TestCase { +import android.util.Log; +public class OpenCVTestCase extends TestCase { //change to 'true' to unblock fail on fail("Not yet implemented") public static final boolean passNYI = true; + protected static boolean isTestCaseEnabled = true; + protected static final int matSize = 10; protected static final double EPS = 0.001; protected static final double weakEPS = 0.5; + private static final String TAG = "OpenCVTestCase"; + protected Mat dst; protected Mat truth; @@ -173,6 +178,16 @@ public class OpenCVTestCase extends TestCase { super.tearDown(); } + @Override + protected void runTest() throws Throwable { + // Do nothing if the precondition does not hold. + if (isTestCaseEnabled) { + super.runTest(); + } else { + Log.e(TAG, "Test case \"" + this.getClass().getName() + "\" disabled!"); + } + } + protected Mat getMat(int type, double... vals) { return new Mat(matSize, matSize, type, new Scalar(vals)); diff --git a/modules/java/android_test/src/org/opencv/test/OpenCVTestRunner.java b/modules/java/android_test/src/org/opencv/test/OpenCVTestRunner.java index 3c416c510..2dc4aead8 100644 --- a/modules/java/android_test/src/org/opencv/test/OpenCVTestRunner.java +++ b/modules/java/android_test/src/org/opencv/test/OpenCVTestRunner.java @@ -2,11 +2,11 @@ package org.opencv.test; import java.io.File; import java.io.IOException; -import java.util.Iterator; - -import junit.framework.TestCase; import junit.framework.Assert; +import org.opencv.android.BaseLoaderCallback; +import org.opencv.android.LoaderCallbackInterface; +import org.opencv.android.OpenCVLoader; import org.opencv.android.Utils; import org.opencv.core.Mat; @@ -23,8 +23,7 @@ import android.util.Log; public class OpenCVTestRunner extends InstrumentationTestRunner { - static { System.loadLibrary("opencv_java"); } - + private static final long MANAGER_TIMEOUT = 3000; public static String LENA_PATH; public static String CHESS_PATH; public static String LBPCASCADE_FRONTALFACE_PATH; @@ -33,6 +32,26 @@ public class OpenCVTestRunner extends InstrumentationTestRunner { private AndroidTestRunner androidTestRunner; private static String TAG = "opencv_test_java"; + private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(getContext()) { + + @Override + public void onManagerConnected(int status) { + switch (status) { + case LoaderCallbackInterface.SUCCESS: + { + Log("OpenCV loaded successfully"); + synchronized (this) { + notify(); + } + } break; + default: + { + super.onManagerConnected(status); + } break; + } + } + }; + public static String getTempFileName(String extension) { File cache = context.getCacheDir(); @@ -59,6 +78,25 @@ public class OpenCVTestRunner extends InstrumentationTestRunner { @Override public void onStart() { + // try to load internal libs + if (!OpenCVLoader.initDebug()) { + // There is no internal OpenCV libs + // Using OpenCV Manager for initialization; + + Log("Internal OpenCV library not found. Using OpenCV Manager for initialization"); + OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_3, getContext(), mLoaderCallback); + + synchronized (this) { + try { + wait(MANAGER_TIMEOUT); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } else { + Log("OpenCV library found inside test package. Using it!"); + } + context = getContext(); Assert.assertTrue("Context can't be 'null'", context != null); LENA_PATH = Utils.exportResource(context, R.drawable.lena); @@ -72,17 +110,6 @@ public class OpenCVTestRunner extends InstrumentationTestRunner { //List testCases = androidTestRunner.getTestCases(); //Collections.shuffle(testCases); //shuffle the tests order - if(OpenCVTestCase.passNYI) { - // turn off problematic camera tests - Iterator it = androidTestRunner.getTestCases().iterator(); - while (it.hasNext()) { - String name = it.next().toString(); - if (name.contains("VideoCaptureTest")) - it.remove(); - } - } - - super.onStart(); } diff --git a/modules/java/android_test/src/org/opencv/test/features2d/FASTFeatureDetectorTest.java b/modules/java/android_test/src/org/opencv/test/features2d/FASTFeatureDetectorTest.java index 35ffd6477..4e068e1ac 100644 --- a/modules/java/android_test/src/org/opencv/test/features2d/FASTFeatureDetectorTest.java +++ b/modules/java/android_test/src/org/opencv/test/features2d/FASTFeatureDetectorTest.java @@ -13,6 +13,8 @@ import org.opencv.features2d.KeyPoint; import org.opencv.test.OpenCVTestCase; import org.opencv.test.OpenCVTestRunner; +import android.util.Log; + public class FASTFeatureDetectorTest extends OpenCVTestCase { FeatureDetector detector; @@ -127,9 +129,9 @@ public class FASTFeatureDetectorTest extends OpenCVTestCase { detector.write(filename); - String truth = "\n\nFeature2D.FAST\n1\n10\n\n"; + String truth = "\n\nFeature2D.FAST\n1\n10\n2\n\n"; String data = readFile(filename); - + Log.d("qqq", "\"" + data + "\""); assertEquals(truth, data); } @@ -138,9 +140,10 @@ public class FASTFeatureDetectorTest extends OpenCVTestCase { detector.write(filename); - String truth = "%YAML:1.0\nname: \"Feature2D.FAST\"\nnonmaxSuppression: 1\nthreshold: 10\n"; + String truth = "%YAML:1.0\nname: \"Feature2D.FAST\"\nnonmaxSuppression: 1\nthreshold: 10\ntype: 2\n"; String data = readFile(filename); + Log.d("qqq", "\"" + data + "\""); assertEquals(truth, data); } } diff --git a/modules/java/android_test/src/org/opencv/test/highgui/HighguiTest.java b/modules/java/android_test/src/org/opencv/test/highgui/HighguiTest.java index 9f7872771..b8e7c3b8b 100644 --- a/modules/java/android_test/src/org/opencv/test/highgui/HighguiTest.java +++ b/modules/java/android_test/src/org/opencv/test/highgui/HighguiTest.java @@ -22,10 +22,10 @@ public class HighguiTest extends OpenCVTestCase { public void testImencodeStringMatListOfByteListOfInteger() { MatOfInt params40 = new MatOfInt(Highgui.IMWRITE_JPEG_QUALITY, 40); MatOfInt params90 = new MatOfInt(Highgui.IMWRITE_JPEG_QUALITY, 90); - /* or + /* or MatOfInt params = new MatOfInt(); - params.fromArray(Highgui.IMWRITE_JPEG_QUALITY, 40); - */ + params.fromArray(Highgui.IMWRITE_JPEG_QUALITY, 40); + */ MatOfByte buff40 = new MatOfByte(); MatOfByte buff90 = new MatOfByte(); diff --git a/modules/java/android_test/src/org/opencv/test/highgui/VideoCaptureTest.java b/modules/java/android_test/src/org/opencv/test/highgui/VideoCaptureTest.java index c6901c5e4..ec7211a29 100644 --- a/modules/java/android_test/src/org/opencv/test/highgui/VideoCaptureTest.java +++ b/modules/java/android_test/src/org/opencv/test/highgui/VideoCaptureTest.java @@ -19,13 +19,13 @@ public class VideoCaptureTest extends OpenCVTestCase { super.setUp(); capture = null; + isTestCaseEnabled = false; isSucceed = false; isOpened = false; } public void testGet() { - try - { + try { capture = new VideoCapture(Highgui.CV_CAP_ANDROID); double frameWidth = capture.get(Highgui.CV_CAP_PROP_FRAME_WIDTH); assertTrue(0 != frameWidth); @@ -35,8 +35,7 @@ public class VideoCaptureTest extends OpenCVTestCase { } public void testGetSupportedPreviewSizes() { - try - { + try { capture = new VideoCapture(Highgui.CV_CAP_ANDROID); List sizes = capture.getSupportedPreviewSizes(); assertNotNull(sizes); @@ -68,8 +67,7 @@ public class VideoCaptureTest extends OpenCVTestCase { } public void testIsOpenedRealCamera() { - try - { + try { capture = new VideoCapture(Highgui.CV_CAP_ANDROID); isOpened = capture.isOpened(); assertTrue(isOpened); @@ -79,8 +77,7 @@ public class VideoCaptureTest extends OpenCVTestCase { } public void testOpen() { - try - { + try { capture = new VideoCapture(); capture.open(Highgui.CV_CAP_ANDROID); isOpened = capture.isOpened(); @@ -91,8 +88,7 @@ public class VideoCaptureTest extends OpenCVTestCase { } public void testRead() { - try - { + try { capture = new VideoCapture(Highgui.CV_CAP_ANDROID); isSucceed = capture.read(dst); assertTrue(isSucceed); @@ -104,8 +100,7 @@ public class VideoCaptureTest extends OpenCVTestCase { } public void testRelease() { - try - { + try { capture = new VideoCapture(Highgui.CV_CAP_ANDROID); capture.release(); assertFalse(capture.isOpened()); @@ -116,8 +111,7 @@ public class VideoCaptureTest extends OpenCVTestCase { } public void testRetrieveMat() { - try - { + try { capture = new VideoCapture(Highgui.CV_CAP_ANDROID); capture.grab(); isSucceed = capture.retrieve(dst); @@ -130,8 +124,7 @@ public class VideoCaptureTest extends OpenCVTestCase { } public void testRetrieveMatInt() { - try - { + try { capture = new VideoCapture(Highgui.CV_CAP_ANDROID); capture.grab(); isSucceed = capture.retrieve(dst, Highgui.CV_CAP_ANDROID_GREY_FRAME); @@ -144,8 +137,7 @@ public class VideoCaptureTest extends OpenCVTestCase { } public void testSet() { - try - { + try { capture = new VideoCapture(Highgui.CV_CAP_ANDROID); capture.set(Highgui.CV_CAP_PROP_FRAME_WIDTH, 640); capture.set(Highgui.CV_CAP_PROP_FRAME_HEIGHT, 480); @@ -165,8 +157,7 @@ public class VideoCaptureTest extends OpenCVTestCase { } public void testVideoCaptureInt() { - try - { + try { capture = new VideoCapture(Highgui.CV_CAP_ANDROID); assertNotNull(capture); assertTrue(capture.isOpened()); diff --git a/modules/legacy/test/test_precomp.hpp b/modules/legacy/test/test_precomp.hpp index f40c7d406..b4ac3f574 100644 --- a/modules/legacy/test/test_precomp.hpp +++ b/modules/legacy/test/test_precomp.hpp @@ -1,6 +1,6 @@ #ifdef __GNUC__ # pragma GCC diagnostic ignored "-Wmissing-declarations" -# ifdef __clang__ +# if defined __clang__ || defined __APPLE__ # pragma GCC diagnostic ignored "-Wmissing-prototypes" # pragma GCC diagnostic ignored "-Wextra" # endif diff --git a/modules/ml/test/test_precomp.hpp b/modules/ml/test/test_precomp.hpp index 46334d527..3ccf10a4a 100644 --- a/modules/ml/test/test_precomp.hpp +++ b/modules/ml/test/test_precomp.hpp @@ -1,6 +1,6 @@ #ifdef __GNUC__ # pragma GCC diagnostic ignored "-Wmissing-declarations" -# ifdef __clang__ +# if defined __clang__ || defined __APPLE__ # pragma GCC diagnostic ignored "-Wmissing-prototypes" # pragma GCC diagnostic ignored "-Wextra" # endif diff --git a/modules/nonfree/perf/perf_precomp.hpp b/modules/nonfree/perf/perf_precomp.hpp index 3afb5b4c3..79a368d71 100644 --- a/modules/nonfree/perf/perf_precomp.hpp +++ b/modules/nonfree/perf/perf_precomp.hpp @@ -1,6 +1,6 @@ #ifdef __GNUC__ # pragma GCC diagnostic ignored "-Wmissing-declarations" -# ifdef __clang__ +# if defined __clang__ || defined __APPLE__ # pragma GCC diagnostic ignored "-Wmissing-prototypes" # pragma GCC diagnostic ignored "-Wextra" # endif diff --git a/modules/nonfree/test/test_precomp.hpp b/modules/nonfree/test/test_precomp.hpp index cbf5253ab..062ab7bb1 100644 --- a/modules/nonfree/test/test_precomp.hpp +++ b/modules/nonfree/test/test_precomp.hpp @@ -1,6 +1,6 @@ #ifdef __GNUC__ # pragma GCC diagnostic ignored "-Wmissing-declarations" -# ifdef __clang__ +# if defined __clang__ || defined __APPLE__ # pragma GCC diagnostic ignored "-Wmissing-prototypes" # pragma GCC diagnostic ignored "-Wextra" # endif diff --git a/modules/objdetect/doc/objdetect.rst b/modules/objdetect/doc/objdetect.rst index 4bab781b8..381742e50 100644 --- a/modules/objdetect/doc/objdetect.rst +++ b/modules/objdetect/doc/objdetect.rst @@ -8,4 +8,5 @@ objdetect. Object Detection :maxdepth: 2 cascade_classification + soft_cascade latent_svm diff --git a/modules/objdetect/doc/soft_cascade.rst b/modules/objdetect/doc/soft_cascade.rst new file mode 100644 index 000000000..ac537b3a8 --- /dev/null +++ b/modules/objdetect/doc/soft_cascade.rst @@ -0,0 +1,96 @@ +Soft Cascade Classifier +====================== + +.. highlight:: cpp + +Soft Cascade Classifier for Object Detection +---------------------------------------------------------- + +Cascade detectors have been shown to operate extremely rapidly, with high accuracy, and have important applications in different spheres. The initial goal for this cascade implementation was the fast and accurate pedestrian detector but it also useful in general. Soft cascade is trained with AdaBoost. But instead of training sequence of stages, the soft cascade is trained as a one long stage of T weak classifiers. Soft cascade is formulated as follows: + +.. math:: + \texttt{H}(x) = \sum _{\texttt{t}=1..\texttt{T}} {\texttt{s}_t(x)} + +where :math:`\texttt{s}_t(x) = \alpha_t\texttt{h}_t(x)` are the set of thresholded weak classifiers selected during AdaBoost training scaled by the associated weights. Let + +.. math:: + \texttt{H}_t(x) = \sum _{\texttt{i}=1..\texttt{t}} {\texttt{s}_i(x)} + +be the partial sum of sample responses before :math:`t`-the weak classifier will be applied. The funtcion :math:`\texttt{H}_t(x)` of :math:`t` for sample :math:`x` named *sample trace*. +After each weak classifier evaluation, the sample trace at the point :math:`t` is compared with the rejection threshold :math:`r_t`. The sequence of :math:`r_t` named *rejection trace*. + +The sample has been rejected if it fall rejection threshold. So stageless cascade allows to reject not-object sample as soon as possible. Another meaning of the sample trace is a confidence with that sample recognized as desired object. At each :math:`t` that confidence depend on all previous weak classifier. This feature of soft cascade is resulted in more accurate detection. The original formulation of soft cascade can be found in [BJ05]_. + +.. [BJ05] Lubomir Bourdev and Jonathan Brandt. tRobust Object Detection Via Soft Cascade. IEEE CVPR, 2005. +.. [BMTG12] Rodrigo Benenson, Markus Mathias, Radu Timofte and Luc Van Gool. Pedestrian detection at 100 frames per second. IEEE CVPR, 2012. + + +SCascade +---------------- +.. ocv:class:: SCascade + +Implementation of soft (stageless) cascaded detector. :: + + class CV_EXPORTS SCascade : public Algorithm + { + public: + SCascade(const float minScale = 0.4f, const float maxScale = 5.f, const int scales = 55, const int rejfactor = 1); + virtual ~SCascade(); + cv::AlgorithmInfo* info() const; + virtual bool load(const FileNode& fn); + virtual void detect(InputArray image, InputArray rois, std::vector& objects) const; + virtual void detect(InputArray image, InputArray rois, OutputArray rects, OutputArray confs) const; + }; + + +SCascade::SCascade +-------------------------- +An empty cascade will be created. + +.. ocv:function:: bool SCascade::SCascade(const float minScale = 0.4f, const float maxScale = 5.f, const int scales = 55, const int rejfactor = 1) + + :param minScale: a minimum scale relative to the original size of the image on which cascade will be applyed. + + :param maxScale: a maximum scale relative to the original size of the image on which cascade will be applyed. + + :param scales: a number of scales from minScale to maxScale. + + :param rejfactor: used for non maximum suppression. + + + +SCascade::~SCascade +--------------------------- +Destructor for SCascade. + +.. ocv:function:: SCascade::~SCascade() + + + +SCascade::load +-------------------------- +Load cascade from FileNode. + +.. ocv:function:: bool SCascade::load(const FileNode& fn) + + :param fn: File node from which the soft cascade are read. + + + +SCascade::detect +-------------------------- +Apply cascade to an input frame and return the vector of Decection objcts. + +.. ocv:function:: void SCascade::detect(InputArray image, InputArray rois, std::vector& objects) const + +.. ocv:function:: void SCascade::detect(InputArray image, InputArray rois, OutputArray rects, OutputArray confs) const + + :param image: a frame on which detector will be applied. + + :param rois: a vector of regions of interest. Only the objects that fall into one of the regions will be returned. + + :param objects: an output array of Detections. + + :param rects: an output array of bounding rectangles for detected objects. + + :param confs: an output array of confidence for detected objects. i-th bounding rectangle corresponds i-th configence. \ No newline at end of file diff --git a/modules/objdetect/include/opencv2/objdetect/objdetect.hpp b/modules/objdetect/include/opencv2/objdetect/objdetect.hpp index c9f740764..a78bef56f 100644 --- a/modules/objdetect/include/opencv2/objdetect/objdetect.hpp +++ b/modules/objdetect/include/opencv2/objdetect/objdetect.hpp @@ -489,6 +489,93 @@ protected: }; +// Implementation of soft (stageless) cascaded detector. +class CV_EXPORTS_W SCascade : public Algorithm +{ +public: + + // Representation of detectors result. + struct CV_EXPORTS Detection + { + // Default object type. + enum {PEDESTRIAN = 1}; + + // Creates Detection from an object bounding box and confidence. + // Param b is a bounding box + // Param c is a confidence that object belongs to class k + // Paral k is an object class + Detection(const cv::Rect& b, const float c, int k = PEDESTRIAN) : bb(b), confidence(c), kind(k) {} + + cv::Rect bb; + float confidence; + int kind; + }; + + // Create channel integrals for Soft Cascade detector. + class CV_EXPORTS Channels + { + public: + // constrictor form resizing factor. + // Param shr is a resizing factor. Resize is applied before the computing integral sum + Channels(const int shrinkage); + + // Appends specified number of HOG first-order features integrals into given vector. + // Param gray is an input 1-channel gray image. + // Param integrals is a vector of integrals. Hog-channels will be appended to it. + // Param bins is a number of hog-bins + void appendHogBins(const cv::Mat& gray, std::vector& integrals, int bins) const; + + // Converts 3-channel BGR input frame in Luv and appends each channel to the integrals. + // Param frame is an input 3-channel BGR colored image. + // Param integrals is a vector of integrals. Computed from the frame luv-channels will be appended to it. + void appendLuvBins(const cv::Mat& frame, std::vector& integrals) const; + + private: + int shrinkage; + }; + + // An empty cascade will be created. + // Param minScale is a minimum scale relative to the original size of the image on which cascade will be applyed. + // Param minScale is a maximum scale relative to the original size of the image on which cascade will be applyed. + // Param scales is a number of scales from minScale to maxScale. + // Param rejfactor is used for NMS. + CV_WRAP SCascade(const double minScale = 0.4, const double maxScale = 5., const int scales = 55, const int rejfactor = 1); + + CV_WRAP virtual ~SCascade(); + + cv::AlgorithmInfo* info() const; + + // Load cascade from FileNode. + // Param fn is a root node for cascade. Should be . + CV_WRAP virtual bool load(const FileNode& fn); + + // Load cascade config. + CV_WRAP virtual void read(const FileNode& fn); + + // Return the vector of Decection objcts. + // Param image is a frame on which detector will be applied. + // Param rois is a vector of regions of interest. Only the objects that fall into one of the regions will be returned. + // Param objects is an output array of Detections + virtual void detect(InputArray image, InputArray rois, std::vector& objects) const; + // Param rects is an output array of bounding rectangles for detected objects. + // Param confs is an output array of confidence for detected objects. i-th bounding rectangle corresponds i-th configence. + CV_WRAP virtual void detect(InputArray image, InputArray rois, OutputArray rects, OutputArray confs) const; + +private: + void detectNoRoi(const Mat& image, std::vector& objects) const; + + struct Fields; + Fields* fields; + + double minScale; + double maxScale; + + int scales; + int rejfactor; +}; + +CV_EXPORTS bool initModule_objdetect(void); + //////////////// HOG (Histogram-of-Oriented-Gradients) Descriptor and Object Detector ////////////// // struct for detection region of interest (ROI) diff --git a/modules/objdetect/perf/perf_cascadeclassifier.cpp b/modules/objdetect/perf/perf_cascadeclassifier.cpp index 98007e45d..f52bd59af 100644 --- a/modules/objdetect/perf/perf_cascadeclassifier.cpp +++ b/modules/objdetect/perf/perf_cascadeclassifier.cpp @@ -52,3 +52,45 @@ PERF_TEST_P(ImageName_MinSize, CascadeClassifierLBPFrontalFace, std::sort(faces.begin(), faces.end(), comparators::RectLess()); SANITY_CHECK(faces, 3.001 * faces.size()); } + +typedef std::tr1::tuple fixture; +typedef perf::TestBaseWithParam detect; + + +namespace { + typedef cv::SCascade::Detection detection_t; + + void extractRacts(std::vector objectBoxes, vector rects) + { + rects.clear(); + for (int i = 0; i < (int)objectBoxes.size(); ++i) + rects.push_back(objectBoxes[i].bb); + } +} + +PERF_TEST_P(detect, SCascade, + testing::Combine(testing::Values(std::string("cv/cascadeandhog/sc_cvpr_2012_to_opencv.xml")), + testing::Values(std::string("cv/cascadeandhog/bahnhof/image_00000000_0.png")))) +{ + typedef cv::SCascade::Detection Detection; + cv::Mat colored = imread(getDataPath(get<1>(GetParam()))); + ASSERT_FALSE(colored.empty()); + + cv::SCascade cascade; + cv::FileStorage fs(getDataPath(get<0>(GetParam())), cv::FileStorage::READ); + ASSERT_TRUE(fs.isOpened()); + ASSERT_TRUE(cascade.load(fs.getFirstTopLevelNode())); + + std::vector objectBoxes; + cascade.detect(colored, cv::noArray(), objectBoxes); + + TEST_CYCLE() + { + cascade.detect(colored, cv::noArray(), objectBoxes); + } + + vector rects; + extractRacts(objectBoxes, rects); + std::sort(rects.begin(), rects.end(), comparators::RectLess()); + SANITY_CHECK(rects); +} diff --git a/modules/objdetect/perf/perf_precomp.hpp b/modules/objdetect/perf/perf_precomp.hpp index c5ae36cf9..d1a7e444c 100644 --- a/modules/objdetect/perf/perf_precomp.hpp +++ b/modules/objdetect/perf/perf_precomp.hpp @@ -1,6 +1,6 @@ #ifdef __GNUC__ # pragma GCC diagnostic ignored "-Wmissing-declarations" -# ifdef __clang__ +# if defined __clang__ || defined __APPLE__ # pragma GCC diagnostic ignored "-Wmissing-prototypes" # pragma GCC diagnostic ignored "-Wextra" # endif diff --git a/modules/objdetect/src/icf.cpp b/modules/objdetect/src/icf.cpp new file mode 100644 index 000000000..416e5ffff --- /dev/null +++ b/modules/objdetect/src/icf.cpp @@ -0,0 +1,113 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2008-2012, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#include + +cv::SCascade::Channels::Channels(int shr) : shrinkage(shr) {} + +void cv::SCascade::Channels::appendHogBins(const cv::Mat& gray, std::vector& integrals, int bins) const +{ + CV_Assert(gray.type() == CV_8UC1); + int h = gray.rows; + int w = gray.cols; + CV_Assert(!(w % shrinkage) && !(h % shrinkage)); + + cv::Mat df_dx, df_dy, mag, angle; + cv::Sobel(gray, df_dx, CV_32F, 1, 0); + cv::Sobel(gray, df_dy, CV_32F, 0, 1); + + cv::cartToPolar(df_dx, df_dy, mag, angle, true); + mag *= (1.f / (8 * sqrt(2.f))); + + cv::Mat nmag; + mag.convertTo(nmag, CV_8UC1); + + angle *= bins/360.f; + + std::vector hist; + for (int bin = 0; bin < bins; ++bin) + hist.push_back(cv::Mat::zeros(h, w, CV_8UC1)); + + for (int y = 0; y < h; ++y) + { + uchar* magnitude = nmag.ptr(y); + float* ang = angle.ptr(y); + + for (int x = 0; x < w; ++x) + { + hist[ (int)ang[x] ].ptr(y)[x] = magnitude[x]; + } + } + + for(int i = 0; i < bins; ++i) + { + cv::Mat shrunk, sum; + cv::resize(hist[i], shrunk, cv::Size(), 1.0 / shrinkage, 1.0 / shrinkage, CV_INTER_AREA); + cv::integral(shrunk, sum, cv::noArray(), CV_32S); + integrals.push_back(sum); + } + + cv::Mat shrMag; + cv::resize(nmag, shrMag, cv::Size(), 1.0 / shrinkage, 1.0 / shrinkage, CV_INTER_AREA); + cv::integral(shrMag, mag, cv::noArray(), CV_32S); + integrals.push_back(mag); +} + +void cv::SCascade::Channels::appendLuvBins(const cv::Mat& frame, std::vector& integrals) const +{ + CV_Assert(frame.type() == CV_8UC3); + CV_Assert(!(frame.cols % shrinkage) && !(frame.rows % shrinkage)); + + cv::Mat luv, shrunk; + cv::cvtColor(frame, luv, CV_BGR2Luv); + cv::resize(luv, shrunk, cv::Size(), 1.0 / shrinkage, 1.0 / shrinkage, CV_INTER_AREA); + + std::vector splited; + split(shrunk, splited); + + for (size_t i = 0; i < splited.size(); ++i) + { + cv::Mat sum; + cv::integral(splited[i], sum, cv::noArray(), CV_32S); + integrals.push_back(sum); + } +} \ No newline at end of file diff --git a/modules/objdetect/src/objdetect_init.cpp b/modules/objdetect/src/objdetect_init.cpp index 317867a59..d53c9480d 100644 --- a/modules/objdetect/src/objdetect_init.cpp +++ b/modules/objdetect/src/objdetect_init.cpp @@ -7,11 +7,11 @@ // copy or use the software. // // -// License Agreement +// License Agreement // For Open Source Computer Vision Library // // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. -// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2008-2012, Willow Garage Inc., all rights reserved. // Third party copyrights are property of their respective owners. // // Redistribution and use in source and binary forms, with or without modification, @@ -40,4 +40,21 @@ // //M*/ -#include "precomp.hpp" +#include + +namespace cv +{ + +CV_INIT_ALGORITHM(SCascade, "CascadeDetector.SCascade", + obj.info()->addParam(obj, "minScale", obj.minScale); + obj.info()->addParam(obj, "maxScale", obj.maxScale); + obj.info()->addParam(obj, "scales", obj.scales); + obj.info()->addParam(obj, "rejfactor", obj.rejfactor)); + +bool initModule_objdetect(void) +{ + Ptr sc = createSCascade(); + return sc->info() != 0; +} + +} \ No newline at end of file diff --git a/modules/objdetect/src/softcascade.cpp b/modules/objdetect/src/softcascade.cpp new file mode 100644 index 000000000..0ee7c0fd4 --- /dev/null +++ b/modules/objdetect/src/softcascade.cpp @@ -0,0 +1,532 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2008-2012, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#include + +namespace { + +struct Octave +{ + Octave(const int i, const cv::Size& origObjSize, const cv::FileNode& fn) + : index(i), scale((float)fn[SC_OCT_SCALE]), stages((int)fn[SC_OCT_STAGES]), + size(cvRound(origObjSize.width * scale), cvRound(origObjSize.height * scale)), + shrinkage((int)fn[SC_OCT_SHRINKAGE]) {} + + int index; + float scale; + int stages; + cv::Size size; + int shrinkage; + + static const char *const SC_OCT_SCALE; + static const char *const SC_OCT_STAGES; + static const char *const SC_OCT_SHRINKAGE; +}; + + +struct Weak +{ + Weak(){} + Weak(const cv::FileNode& fn) : threshold((float)fn[SC_STAGE_THRESHOLD]){} + + float threshold; + + static const char *const SC_STAGE_THRESHOLD; +}; + + +struct Node +{ + Node(){} + Node(const int offset, cv::FileNodeIterator& fIt) + : feature((int)(*(fIt +=2)++) + offset), threshold((float)(*(fIt++))){} + + int feature; + float threshold; +}; + +struct Feature +{ + Feature() {} + Feature(const cv::FileNode& fn) : channel((int)fn[SC_F_CHANNEL]) + { + cv::FileNode rn = fn[SC_F_RECT]; + cv::FileNodeIterator r_it = rn.begin(); + + int x = *r_it++; + int y = *r_it++; + int w = *r_it++; + int h = *r_it++; + rect = cv::Rect(x, y, w, h); + + // 1 / area + rarea = 1.f / ((rect.width - rect.x) * (rect.height - rect.y)); + } + + int channel; + cv::Rect rect; + float rarea; + + static const char *const SC_F_CHANNEL; + static const char *const SC_F_RECT; + +}; + +const char *const Octave::SC_OCT_SCALE = "scale"; +const char *const Octave::SC_OCT_STAGES = "stageNum"; +const char *const Octave::SC_OCT_SHRINKAGE = "shrinkingFactor"; +const char *const Weak::SC_STAGE_THRESHOLD = "stageThreshold"; +const char *const Feature::SC_F_CHANNEL = "channel"; +const char *const Feature::SC_F_RECT = "rect"; + +struct Level +{ + const Octave* octave; + + float origScale; + float relScale; + int scaleshift; + + cv::Size workRect; + cv::Size objSize; + + float scaling[2]; // 0-th for channels <= 6, 1-st otherwise + typedef cv::SCascade::Detection Detection; + + Level(const Octave& oct, const float scale, const int shrinkage, const int w, const int h) + : octave(&oct), origScale(scale), relScale(scale / oct.scale), + workRect(cv::Size(cvRound(w / (float)shrinkage),cvRound(h / (float)shrinkage))), + objSize(cv::Size(cvRound(oct.size.width * relScale), cvRound(oct.size.height * relScale))) + { + scaling[0] = ((relScale >= 1.f)? 1.f : (0.89f * pow(relScale, 1.099f / log(2.f)))) / (relScale * relScale); + scaling[1] = 1.f; + scaleshift = static_cast(relScale * (1 << 16)); + } + + void addDetection(const int x, const int y, float confidence, std::vector& detections) const + { + int shrinkage = (*octave).shrinkage; + cv::Rect rect(cvRound(x * shrinkage), cvRound(y * shrinkage), objSize.width, objSize.height); + + detections.push_back(Detection(rect, confidence)); + } + + float rescale(cv::Rect& scaledRect, const float threshold, int idx) const + { +#define SSHIFT(a) ((a) + (1 << 15)) >> 16 + // rescale + scaledRect.x = SSHIFT(scaleshift * scaledRect.x); + scaledRect.y = SSHIFT(scaleshift * scaledRect.y); + scaledRect.width = SSHIFT(scaleshift * scaledRect.width); + scaledRect.height = SSHIFT(scaleshift * scaledRect.height); +#undef SSHIFT + float sarea = static_cast((scaledRect.width - scaledRect.x) * (scaledRect.height - scaledRect.y)); + + // compensation areas rounding + return (sarea == 0.0f)? threshold : (threshold * scaling[idx] * sarea); + } +}; + +struct ChannelStorage +{ + std::vector hog; + int shrinkage; + int offset; + int step; + + enum {HOG_BINS = 6, HOG_LUV_BINS = 10}; + + ChannelStorage(const cv::Mat& colored, int shr) : shrinkage(shr) + { + hog.clear(); + hog.reserve(10); + cv::SCascade::Channels ints(shr); + + // convert to grey + cv::Mat grey; + cv::cvtColor(colored, grey, CV_BGR2GRAY); + + ints.appendHogBins(grey, hog, 6); + ints.appendLuvBins(colored, hog); + + step = hog[0].cols; + } + + float get(const int channel, const cv::Rect& area) const + { + // CV_Assert(channel < HOG_LUV_BINS); + const cv::Mat& m = hog[channel]; + int *ptr = ((int*)(m.data)) + offset; + + int a = ptr[area.y * step + area.x]; + int b = ptr[area.y * step + area.width]; + int c = ptr[area.height * step + area.width]; + int d = ptr[area.height * step + area.x]; + + return static_cast(a - b + c - d); + } +}; + +} + +struct cv::SCascade::Fields +{ + float minScale; + float maxScale; + int scales; + + int origObjWidth; + int origObjHeight; + + int shrinkage; + + std::vector octaves; + std::vector stages; + std::vector nodes; + std::vector leaves; + std::vector features; + + std::vector levels; + + cv::Size frameSize; + + typedef std::vector::iterator octIt_t; + + void detectAt(const int dx, const int dy, const Level& level, const ChannelStorage& storage, + std::vector& detections) const + { + float detectionScore = 0.f; + + const Octave& octave = *(level.octave); + int stBegin = octave.index * octave.stages, stEnd = stBegin + octave.stages; + + int st = stBegin; + for(; st < stEnd; ++st) + { + const Weak& stage = stages[st]; + { + int nId = st * 3; + + // work with root node + const Node& node = nodes[nId]; + const Feature& feature = features[node.feature]; + cv::Rect scaledRect(feature.rect); + + float threshold = level.rescale(scaledRect, node.threshold,(int)(feature.channel > 6)) * feature.rarea; + + float sum = storage.get(feature.channel, scaledRect); + + int next = (sum >= threshold)? 2 : 1; + + // leaves + const Node& leaf = nodes[nId + next]; + const Feature& fLeaf = features[leaf.feature]; + + scaledRect = fLeaf.rect; + threshold = level.rescale(scaledRect, leaf.threshold, (int)(fLeaf.channel > 6)) * fLeaf.rarea; + + sum = storage.get(fLeaf.channel, scaledRect); + + int lShift = (next - 1) * 2 + ((sum >= threshold) ? 1 : 0); + float impact = leaves[(st * 4) + lShift]; + + detectionScore += impact; + } + + if (detectionScore <= stage.threshold) return; + } + + if (detectionScore > 0) + level.addDetection(dx, dy, detectionScore, detections); + } + + octIt_t fitOctave(const float& logFactor) + { + float minAbsLog = FLT_MAX; + octIt_t res = octaves.begin(); + for (octIt_t oct = octaves.begin(); oct < octaves.end(); ++oct) + { + const Octave& octave =*oct; + float logOctave = log(octave.scale); + float logAbsScale = fabs(logFactor - logOctave); + + if(logAbsScale < minAbsLog) + { + res = oct; + minAbsLog = logAbsScale; + } + } + return res; + } + + // compute levels of full pyramid + void calcLevels(const cv::Size& curr, float mins, float maxs, int total) + { + if (frameSize == curr && maxs == maxScale && mins == minScale && total == scales) return; + + frameSize = curr; + maxScale = maxs; minScale = mins; scales = total; + CV_Assert(scales > 1); + + levels.clear(); + float logFactor = (log(maxScale) - log(minScale)) / (scales -1); + + float scale = minScale; + for (int sc = 0; sc < scales; ++sc) + { + int width = static_cast(std::max(0.0f, frameSize.width - (origObjWidth * scale))); + int height = static_cast(std::max(0.0f, frameSize.height - (origObjHeight * scale))); + + float logScale = log(scale); + octIt_t fit = fitOctave(logScale); + + + Level level(*fit, scale, shrinkage, width, height); + + if (!width || !height) + break; + else + levels.push_back(level); + + if (fabs(scale - maxScale) < FLT_EPSILON) break; + scale = std::min(maxScale, expf(log(scale) + logFactor)); + } + } + + bool fill(const FileNode &root) + { + // cascade properties + static const char *const SC_STAGE_TYPE = "stageType"; + static const char *const SC_BOOST = "BOOST"; + + static const char *const SC_FEATURE_TYPE = "featureType"; + static const char *const SC_ICF = "ICF"; + + static const char *const SC_ORIG_W = "width"; + static const char *const SC_ORIG_H = "height"; + + static const char *const SC_OCTAVES = "octaves"; + static const char *const SC_STAGES = "stages"; + static const char *const SC_FEATURES = "features"; + + static const char *const SC_WEEK = "weakClassifiers"; + static const char *const SC_INTERNAL = "internalNodes"; + static const char *const SC_LEAF = "leafValues"; + + + // only Ada Boost supported + std::string stageTypeStr = (string)root[SC_STAGE_TYPE]; + CV_Assert(stageTypeStr == SC_BOOST); + + // only HOG-like integral channel features cupported + string featureTypeStr = (string)root[SC_FEATURE_TYPE]; + CV_Assert(featureTypeStr == SC_ICF); + + origObjWidth = (int)root[SC_ORIG_W]; + origObjHeight = (int)root[SC_ORIG_H]; + + // for each octave (~ one cascade in classic OpenCV xml) + FileNode fn = root[SC_OCTAVES]; + if (fn.empty()) return false; + + // octaves.reserve(noctaves); + FileNodeIterator it = fn.begin(), it_end = fn.end(); + int feature_offset = 0; + int octIndex = 0; + for (; it != it_end; ++it) + { + FileNode fns = *it; + Octave octave(octIndex, cv::Size(origObjWidth, origObjHeight), fns); + CV_Assert(octave.stages > 0); + octaves.push_back(octave); + + FileNode ffs = fns[SC_FEATURES]; + if (ffs.empty()) return false; + + fns = fns[SC_STAGES]; + if (fn.empty()) return false; + + // for each stage (~ decision tree with H = 2) + FileNodeIterator st = fns.begin(), st_end = fns.end(); + for (; st != st_end; ++st ) + { + fns = *st; + stages.push_back(Weak(fns)); + + fns = fns[SC_WEEK]; + FileNodeIterator ftr = fns.begin(), ft_end = fns.end(); + for (; ftr != ft_end; ++ftr) + { + fns = (*ftr)[SC_INTERNAL]; + FileNodeIterator inIt = fns.begin(), inIt_end = fns.end(); + for (; inIt != inIt_end;) + nodes.push_back(Node(feature_offset, inIt)); + + fns = (*ftr)[SC_LEAF]; + inIt = fns.begin(), inIt_end = fns.end(); + for (; inIt != inIt_end; ++inIt) + leaves.push_back((float)(*inIt)); + } + } + + st = ffs.begin(), st_end = ffs.end(); + for (; st != st_end; ++st ) + features.push_back(Feature(*st)); + + feature_offset += octave.stages * 3; + ++octIndex; + } + + shrinkage = octaves[0].shrinkage; + return true; + } +}; + +cv::SCascade::SCascade(const double mins, const double maxs, const int nsc, const int rej) +: fields(0), minScale(mins), maxScale(maxs), scales(nsc), rejfactor(rej) {} + +cv::SCascade::~SCascade() { delete fields;} + +void cv::SCascade::read(const FileNode& fn) +{ + Algorithm::read(fn); +} + +bool cv::SCascade::load(const FileNode& fn) +{ + if (fields) delete fields; + + fields = new Fields; + return fields->fill(fn); +} + +void cv::SCascade::detectNoRoi(const cv::Mat& image, std::vector& objects) const +{ + Fields& fld = *fields; + // create integrals + ChannelStorage storage(image, fld.shrinkage); + + typedef std::vector::const_iterator lIt; + for (lIt it = fld.levels.begin(); it != fld.levels.end(); ++it) + { + const Level& level = *it; + + for (int dy = 0; dy < level.workRect.height; ++dy) + { + for (int dx = 0; dx < level.workRect.width; ++dx) + { + storage.offset = dy * storage.step + dx; + fld.detectAt(dx, dy, level, storage, objects); + } + } + } +} + +void cv::SCascade::detect(cv::InputArray _image, cv::InputArray _rois, std::vector& objects) const +{ + // only color images are supperted + cv::Mat image = _image.getMat(); + CV_Assert(image.type() == CV_8UC3); + + Fields& fld = *fields; + fld.calcLevels(image.size(),(float) minScale, (float)maxScale, scales); + + objects.clear(); + + if (_rois.kind() == cv::_InputArray::NONE) + return detectNoRoi(image, objects); + + int shr = fld.shrinkage; + + cv::Mat roi = _rois.getMat(); + cv::Mat mask(image.rows / shr, image.cols / shr, CV_8UC1); + + mask.setTo(cv::Scalar::all(0)); + cv::Rect* r = roi.ptr(0); + for (int i = 0; i < (int)roi.cols; ++i) + cv::Mat(mask, cv::Rect(r[i].x / shr, r[i].y / shr, r[i].width / shr , r[i].height / shr)).setTo(cv::Scalar::all(1)); + + // create integrals + ChannelStorage storage(image, shr); + + typedef std::vector::const_iterator lIt; + for (lIt it = fld.levels.begin(); it != fld.levels.end(); ++it) + { + const Level& level = *it; + + for (int dy = 0; dy < level.workRect.height; ++dy) + { + uchar* m = mask.ptr(dy); + for (int dx = 0; dx < level.workRect.width; ++dx) + { + if (m[dx]) + { + storage.offset = dy * storage.step + dx; + fld.detectAt(dx, dy, level, storage, objects); + } + } + } + } +} + +void cv::SCascade::detect(InputArray _image, InputArray _rois, OutputArray _rects, OutputArray _confs) const +{ + std::vector objects; + detect( _image, _rois, objects); + + _rects.create(1, objects.size(), CV_32SC4); + cv::Mat_ rects = (cv::Mat_)_rects.getMat(); + cv::Rect* rectPtr = rects.ptr(0); + + _confs.create(1, objects.size(), CV_32F); + cv::Mat confs = _confs.getMat(); + float* confPtr = rects.ptr(0); + + typedef std::vector::const_iterator IDet; + + int i = 0; + for (IDet it = objects.begin(); it != objects.end(); ++it, ++i) + { + rectPtr[i] = (*it).bb; + confPtr[i] = (*it).confidence; + } +} \ No newline at end of file diff --git a/modules/objdetect/test/test_precomp.hpp b/modules/objdetect/test/test_precomp.hpp index cb7ac0f15..9100ab04c 100644 --- a/modules/objdetect/test/test_precomp.hpp +++ b/modules/objdetect/test/test_precomp.hpp @@ -1,6 +1,6 @@ #ifdef __GNUC__ # pragma GCC diagnostic ignored "-Wmissing-declarations" -# ifdef __clang__ +# if defined __clang__ || defined __APPLE__ # pragma GCC diagnostic ignored "-Wmissing-prototypes" # pragma GCC diagnostic ignored "-Wextra" # endif diff --git a/modules/objdetect/test/test_softcascade.cpp b/modules/objdetect/test/test_softcascade.cpp new file mode 100644 index 000000000..f9141c2a9 --- /dev/null +++ b/modules/objdetect/test/test_softcascade.cpp @@ -0,0 +1,125 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2008-2012, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#include "test_precomp.hpp" + +TEST(SCascade, readCascade) +{ + std::string xml = cvtest::TS::ptr()->get_data_path() + "cascadeandhog/icf-template.xml"; + cv::SCascade cascade; + cv::FileStorage fs(xml, cv::FileStorage::READ); + ASSERT_TRUE(fs.isOpened()); + ASSERT_TRUE(cascade.load(fs.getFirstTopLevelNode())); + +} + +TEST(SCascade, detect) +{ + typedef cv::SCascade::Detection Detection; + std::string xml = cvtest::TS::ptr()->get_data_path() + "cascadeandhog/sc_cvpr_2012_to_opencv.xml"; + cv::SCascade cascade; + cv::FileStorage fs(xml, cv::FileStorage::READ); + ASSERT_TRUE(cascade.load(fs.getFirstTopLevelNode())); + + cv::Mat colored = cv::imread(cvtest::TS::ptr()->get_data_path() + "cascadeandhog/bahnhof/image_00000000_0.png"); + ASSERT_FALSE(colored.empty()); + + std::vector objects; + + cascade.detect(colored, cv::noArray(), objects); + ASSERT_EQ(1459, (int)objects.size()); +} + +TEST(SCascade, detectSeparate) +{ + typedef cv::SCascade::Detection Detection; + std::string xml = cvtest::TS::ptr()->get_data_path() + "cascadeandhog/sc_cvpr_2012_to_opencv.xml"; + cv::SCascade cascade; + cv::FileStorage fs(xml, cv::FileStorage::READ); + ASSERT_TRUE(cascade.load(fs.getFirstTopLevelNode())); + + cv::Mat colored = cv::imread(cvtest::TS::ptr()->get_data_path() + "cascadeandhog/bahnhof/image_00000000_0.png"); + ASSERT_FALSE(colored.empty()); + + cv::Mat rects, confs; + + cascade.detect(colored, cv::noArray(), rects, confs); + ASSERT_EQ(1459, confs.cols); +} + +TEST(SCascade, detectRoi) +{ + typedef cv::SCascade::Detection Detection; + std::string xml = cvtest::TS::ptr()->get_data_path() + "cascadeandhog/sc_cvpr_2012_to_opencv.xml"; + cv::SCascade cascade; + cv::FileStorage fs(xml, cv::FileStorage::READ); + ASSERT_TRUE(cascade.load(fs.getFirstTopLevelNode())); + + cv::Mat colored = cv::imread(cvtest::TS::ptr()->get_data_path() + "cascadeandhog/bahnhof/image_00000000_0.png"); + ASSERT_FALSE(colored.empty()); + + std::vector objects; + std::vector rois; + rois.push_back(cv::Rect(0, 0, 640, 480)); + + cascade.detect(colored, rois, objects); + ASSERT_EQ(1459, (int)objects.size()); +} + +TEST(SCascade, detectNoRoi) +{ + typedef cv::SCascade::Detection Detection; + std::string xml = cvtest::TS::ptr()->get_data_path() + "cascadeandhog/sc_cvpr_2012_to_opencv.xml"; + cv::SCascade cascade; + cv::FileStorage fs(xml, cv::FileStorage::READ); + ASSERT_TRUE(cascade.load(fs.getFirstTopLevelNode())); + + cv::Mat colored = cv::imread(cvtest::TS::ptr()->get_data_path() + "cascadeandhog/bahnhof/image_00000000_0.png"); + ASSERT_FALSE(colored.empty()); + + std::vector objects; + std::vector rois; + + cascade.detect(colored, rois, objects); + + ASSERT_EQ(0, (int)objects.size()); +} \ No newline at end of file diff --git a/modules/ocl/perf/main.cpp b/modules/ocl/perf/main.cpp index fb8013635..663bc197a 100644 --- a/modules/ocl/perf/main.cpp +++ b/modules/ocl/perf/main.cpp @@ -79,77 +79,47 @@ int main(int argc, char **argv) TS::ptr()->init("ocl"); InitGoogleTest(&argc, argv); const char *keys = - - "{ h | help | false | print help message }" - - "{ w | workdir | ../../../samples/c/| set working directory }" - - "{ t | type | gpu | set device type:cpu or gpu}" - - "{ p | platform | 0 | set platform id }" - - "{ d | device | 0 | set device id }"; - - + "{ h | false | print help message }" + "{ w | ../../../samples/c/| set working directory i.e. -w=C:\\}" + "{ t | gpu | set device type:i.e. -t=cpu or gpu}" + "{ p | 0 | set platform id i.e. -p=0}" + "{ d | 0 | set device id i.e. -d=0}"; CommandLineParser cmd(argc, argv, keys); - - if (cmd.get("help")) - + if (cmd.get("h")=="true") { - cout << "Avaible options besides goole test option:" << endl; - - cmd.printParams(); + cmd.printMessage(); + return 0; } - - workdir = cmd.get("workdir"); - - string type = cmd.get("type"); - - unsigned int pid = cmd.get("platform"); - - int device = cmd.get("device"); - - + workdir = cmd.get("w"); + string type = cmd.get("t"); + unsigned int pid = cmd.get("p"); + int device = cmd.get("d"); print_info(); int flag = CVCL_DEVICE_TYPE_GPU; if(type == "cpu") - { - flag = CVCL_DEVICE_TYPE_CPU; - } std::vector oclinfo; int devnums = getDevice(oclinfo); if(devnums <= device || device < 0) - { - std::cout << "device invalid\n"; - return -1; - } if(pid >= oclinfo.size()) - { - std::cout << "platform invalid\n"; - return -1; - } if(pid != 0 || device != 0) - { - setDevice(oclinfo[pid], device); - } cout << "Device type:" << type << endl << "Device name:" << oclinfo[pid].DeviceName[device] << endl; diff --git a/modules/ocl/test/main.cpp b/modules/ocl/test/main.cpp index 856828d6a..d3273f7fe 100644 --- a/modules/ocl/test/main.cpp +++ b/modules/ocl/test/main.cpp @@ -79,23 +79,23 @@ int main(int argc, char **argv) TS::ptr()->init("ocl"); InitGoogleTest(&argc, argv); const char *keys = - "{ h | help | false | print help message }" - "{ w | workdir | ../../../samples/c/| set working directory }" - "{ t | type | gpu | set device type:cpu or gpu}" - "{ p | platform | 0 | set platform id }" - "{ d | device | 0 | set device id }"; + "{ h | false | print help message }" + "{ w | ../../../samples/c/| set working directory i.e. -w=C:\\}" + "{ t | gpu | set device type:i.e. -t=cpu or gpu}" + "{ p | 0 | set platform id i.e. -p=0}" + "{ d | 0 | set device id i.e. -d=0}"; CommandLineParser cmd(argc, argv, keys); - if (cmd.get("help")) + if (cmd.get("h")=="true") { cout << "Avaible options besides goole test option:" << endl; - cmd.printParams(); + cmd.printMessage(); return 0; } - workdir = cmd.get("workdir"); - string type = cmd.get("type"); - unsigned int pid = cmd.get("platform"); - int device = cmd.get("device"); + workdir = cmd.get("w"); + string type = cmd.get("t"); + unsigned int pid = cmd.get("p"); + int device = cmd.get("d"); print_info(); int flag = CVCL_DEVICE_TYPE_GPU; diff --git a/modules/photo/perf/perf_precomp.hpp b/modules/photo/perf/perf_precomp.hpp index 3c40b2921..117233333 100644 --- a/modules/photo/perf/perf_precomp.hpp +++ b/modules/photo/perf/perf_precomp.hpp @@ -1,6 +1,6 @@ #ifdef __GNUC__ # pragma GCC diagnostic ignored "-Wmissing-declarations" -# ifdef __clang__ +# if defined __clang__ || defined __APPLE__ # pragma GCC diagnostic ignored "-Wmissing-prototypes" # pragma GCC diagnostic ignored "-Wextra" # endif diff --git a/modules/photo/test/test_precomp.hpp b/modules/photo/test/test_precomp.hpp index 877f21532..d1f3dcab2 100644 --- a/modules/photo/test/test_precomp.hpp +++ b/modules/photo/test/test_precomp.hpp @@ -1,6 +1,6 @@ #ifdef __GNUC__ # pragma GCC diagnostic ignored "-Wmissing-declarations" -# ifdef __clang__ +# if defined __clang__ || defined __APPLE__ # pragma GCC diagnostic ignored "-Wmissing-prototypes" # pragma GCC diagnostic ignored "-Wextra" # endif diff --git a/modules/stitching/perf/perf_precomp.hpp b/modules/stitching/perf/perf_precomp.hpp index f6cdae81e..559891fe3 100644 --- a/modules/stitching/perf/perf_precomp.hpp +++ b/modules/stitching/perf/perf_precomp.hpp @@ -1,6 +1,6 @@ #ifdef __GNUC__ # pragma GCC diagnostic ignored "-Wmissing-declarations" -# ifdef __clang__ +# if defined __clang__ || defined __APPLE__ # pragma GCC diagnostic ignored "-Wmissing-prototypes" # pragma GCC diagnostic ignored "-Wextra" # endif diff --git a/modules/stitching/test/test_precomp.hpp b/modules/stitching/test/test_precomp.hpp index e703850bf..5509d1c86 100644 --- a/modules/stitching/test/test_precomp.hpp +++ b/modules/stitching/test/test_precomp.hpp @@ -1,6 +1,6 @@ #ifdef __GNUC__ # pragma GCC diagnostic ignored "-Wmissing-declarations" -# ifdef __clang__ +# if defined __clang__ || defined __APPLE__ # pragma GCC diagnostic ignored "-Wmissing-prototypes" # pragma GCC diagnostic ignored "-Wextra" # endif diff --git a/modules/video/doc/motion_analysis_and_object_tracking.rst b/modules/video/doc/motion_analysis_and_object_tracking.rst index 3b1662c84..873e7fdc4 100644 --- a/modules/video/doc/motion_analysis_and_object_tracking.rst +++ b/modules/video/doc/motion_analysis_and_object_tracking.rst @@ -601,17 +601,15 @@ calcOpticalFlowSF ----------------- Calculate an optical flow using "SimpleFlow" algorithm. -.. ocv:function:: void calcOpticalFlowSF( Mat& from, Mat& to, Mat& flow, int layers, int averaging_block_size, int max_flow ) +.. ocv:function:: void calcOpticalFlowSF( InputArray from, InputArray to, OutputArray flow, int layers, int averaging_block_size, int max_flow ) -.. ocv:function:: calcOpticalFlowSF( Mat& from, Mat& to, Mat& flow, int layers, int averaging_block_size, int max_flow, double sigma_dist, double sigma_color, int postprocess_window, double sigma_dist_fix, double sigma_color_fix, double occ_thr, int upscale_averaging_radius, double upscale_sigma_dist, double upscale_sigma_color, double speed_up_thr ) +.. ocv:function:: calcOpticalFlowSF( InputArray from, InputArray to, OutputArray flow, int layers, int averaging_block_size, int max_flow, double sigma_dist, double sigma_color, int postprocess_window, double sigma_dist_fix, double sigma_color_fix, double occ_thr, int upscale_averaging_radius, double upscale_sigma_dist, double upscale_sigma_color, double speed_up_thr ) :param prev: First 8-bit 3-channel image. - :param next: Second 8-bit 3-channel image + :param next: Second 8-bit 3-channel image of the same size as ``prev`` - :param flowX: X-coordinate of estimated flow - - :param flowY: Y-coordinate of estimated flow + :param flow: computed flow image that has the same size as ``prev`` and type ``CV_32FC2`` :param layers: Number of layers @@ -631,7 +629,7 @@ Calculate an optical flow using "SimpleFlow" algorithm. :param occ_thr: threshold for detecting occlusions - :param upscale_averaging_radiud: window size for bilateral upscale operation + :param upscale_averaging_radius: window size for bilateral upscale operation :param upscale_sigma_dist: spatial sigma for bilateral upscale operation diff --git a/modules/video/include/opencv2/video/tracking.hpp b/modules/video/include/opencv2/video/tracking.hpp index deef20b42..be9407aca 100644 --- a/modules/video/include/opencv2/video/tracking.hpp +++ b/modules/video/include/opencv2/video/tracking.hpp @@ -328,16 +328,16 @@ CV_EXPORTS_W Mat estimateRigidTransform( InputArray src, InputArray dst, bool fullAffine); //! computes dense optical flow using Simple Flow algorithm -CV_EXPORTS_W void calcOpticalFlowSF(Mat& from, - Mat& to, - Mat& flow, +CV_EXPORTS_W void calcOpticalFlowSF(InputArray from, + InputArray to, + OutputArray flow, int layers, int averaging_block_size, int max_flow); -CV_EXPORTS_W void calcOpticalFlowSF(Mat& from, - Mat& to, - Mat& flow, +CV_EXPORTS_W void calcOpticalFlowSF(InputArray from, + InputArray to, + OutputArray flow, int layers, int averaging_block_size, int max_flow, diff --git a/modules/video/perf/perf_precomp.hpp b/modules/video/perf/perf_precomp.hpp index bbee05eb7..e1c2b566b 100644 --- a/modules/video/perf/perf_precomp.hpp +++ b/modules/video/perf/perf_precomp.hpp @@ -1,6 +1,6 @@ #ifdef __GNUC__ # pragma GCC diagnostic ignored "-Wmissing-declarations" -# ifdef __clang__ +# if defined __clang__ || defined __APPLE__ # pragma GCC diagnostic ignored "-Wmissing-prototypes" # pragma GCC diagnostic ignored "-Wextra" # endif diff --git a/modules/video/src/simpleflow.cpp b/modules/video/src/simpleflow.cpp index 1de8084c5..81886eb2c 100644 --- a/modules/video/src/simpleflow.cpp +++ b/modules/video/src/simpleflow.cpp @@ -447,7 +447,7 @@ static void extrapolateFlow(Mat& flow, } } -static void buildPyramidWithResizeMethod(Mat& src, +static void buildPyramidWithResizeMethod(const Mat& src, vector& pyramid, int layers, int interpolation_type) { @@ -464,9 +464,9 @@ static void buildPyramidWithResizeMethod(Mat& src, } } -CV_EXPORTS_W void calcOpticalFlowSF(Mat& from, - Mat& to, - Mat& resulted_flow, +CV_EXPORTS_W void calcOpticalFlowSF(InputArray _from, + InputArray _to, + OutputArray _resulted_flow, int layers, int averaging_radius, int max_flow, @@ -479,7 +479,11 @@ CV_EXPORTS_W void calcOpticalFlowSF(Mat& from, int upscale_averaging_radius, double upscale_sigma_dist, double upscale_sigma_color, - double speed_up_thr) { + double speed_up_thr) +{ + Mat from = _from.getMat(); + Mat to = _to.getMat(); + vector pyr_from_images; vector pyr_to_images; @@ -632,14 +636,15 @@ CV_EXPORTS_W void calcOpticalFlowSF(Mat& from, GaussianBlur(flow, flow, Size(3, 3), 5); - resulted_flow = Mat(flow.size(), CV_32FC2); + _resulted_flow.create(flow.size(), CV_32FC2); + Mat resulted_flow = _resulted_flow.getMat(); int from_to[] = {0,1 , 1,0}; mixChannels(&flow, 1, &resulted_flow, 1, from_to, 2); } -CV_EXPORTS_W void calcOpticalFlowSF(Mat& from, - Mat& to, - Mat& flow, +CV_EXPORTS_W void calcOpticalFlowSF(InputArray from, + InputArray to, + OutputArray flow, int layers, int averaging_block_size, int max_flow) { diff --git a/modules/video/test/test_precomp.hpp b/modules/video/test/test_precomp.hpp index 6b528bb5a..a4b869a52 100644 --- a/modules/video/test/test_precomp.hpp +++ b/modules/video/test/test_precomp.hpp @@ -1,6 +1,6 @@ #ifdef __GNUC__ # pragma GCC diagnostic ignored "-Wmissing-declarations" -# ifdef __clang__ +# if defined __clang__ || defined __APPLE__ # pragma GCC diagnostic ignored "-Wmissing-prototypes" # pragma GCC diagnostic ignored "-Wextra" # endif diff --git a/samples/android/15-puzzle/.project b/samples/android/15-puzzle/.project index d9387703f..e7ad66040 100644 --- a/samples/android/15-puzzle/.project +++ b/samples/android/15-puzzle/.project @@ -1,6 +1,6 @@ - 15-puzzle + OpenCV Sample - 15 puzzle diff --git a/samples/android/15-puzzle/.settings/org.eclipse.jdt.core.prefs b/samples/android/15-puzzle/.settings/org.eclipse.jdt.core.prefs index f77b31c2d..b080d2ddc 100644 --- a/samples/android/15-puzzle/.settings/org.eclipse.jdt.core.prefs +++ b/samples/android/15-puzzle/.settings/org.eclipse.jdt.core.prefs @@ -1,4 +1,4 @@ eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 -org.eclipse.jdt.core.compiler.compliance=1.5 -org.eclipse.jdt.core.compiler.source=1.5 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/samples/android/color-blob-detection/.settings/org.eclipse.jdt.core.prefs b/samples/android/color-blob-detection/.settings/org.eclipse.jdt.core.prefs index 53e049515..b080d2ddc 100644 --- a/samples/android/color-blob-detection/.settings/org.eclipse.jdt.core.prefs +++ b/samples/android/color-blob-detection/.settings/org.eclipse.jdt.core.prefs @@ -1,5 +1,4 @@ -#Wed Jun 29 04:36:40 MSD 2011 eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 -org.eclipse.jdt.core.compiler.compliance=1.5 -org.eclipse.jdt.core.compiler.source=1.5 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/samples/android/face-detection/.cproject b/samples/android/face-detection/.cproject index 4b8f95d19..f57ae9006 100644 --- a/samples/android/face-detection/.cproject +++ b/samples/android/face-detection/.cproject @@ -28,8 +28,8 @@