diff --git a/CMakeLists.txt b/CMakeLists.txt index ec5086c1e3..eb173592a6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -127,8 +127,8 @@ OCV_OPTION(WITH_FFMPEG "Include FFMPEG support" ON OCV_OPTION(WITH_GSTREAMER "Include Gstreamer support" ON IF (UNIX AND NOT APPLE AND NOT ANDROID) ) OCV_OPTION(WITH_GSTREAMER_0_10 "Enable Gstreamer 0.10 support (instead of 1.x)" OFF ) OCV_OPTION(WITH_GTK "Include GTK support" ON IF (UNIX AND NOT APPLE AND NOT ANDROID) ) -OCV_OPTION(WITH_GTK_2_X "Use GTK version 2" OFF IF (UNIX AND NOT APPLE AND NOT ANDROID) ) -OCV_OPTION(WITH_IPP "Include Intel IPP support" OFF IF (MSVC OR X86 OR X86_64) ) +OCV_OPTION(WITH_ICV "Include Intel IPP ICV support" ON IF (NOT IOS) ) +OCV_OPTION(WITH_IPP "Include Intel IPP support" OFF IF (NOT IOS) ) OCV_OPTION(WITH_JASPER "Include JPEG2K support" ON IF (NOT IOS) ) OCV_OPTION(WITH_JPEG "Include JPEG support" ON) OCV_OPTION(WITH_WEBP "Include WebP support" ON IF (NOT IOS) ) @@ -749,7 +749,6 @@ else() endif() else() status(" GTK+ 2.x:" HAVE_GTK THEN "YES (ver ${ALIASOF_gtk+-2.0_VERSION})" ELSE NO) - status(" GTK+ 3.x:" HAVE_GTK3 THEN "YES (ver ${ALIASOF_gtk+-3.0_VERSION})" ELSE NO) status(" GThread :" HAVE_GTHREAD THEN "YES (ver ${ALIASOF_gthread-2.0_VERSION})" ELSE NO) status(" GtkGlExt:" HAVE_GTKGLEXT THEN "YES (ver ${ALIASOF_gtkglext-1.0_VERSION})" ELSE NO) endif() diff --git a/cmake/OpenCVFindIPP.cmake b/cmake/OpenCVFindIPP.cmake index db02e6acbf..780ee51b87 100644 --- a/cmake/OpenCVFindIPP.cmake +++ b/cmake/OpenCVFindIPP.cmake @@ -2,35 +2,41 @@ # The script to detect Intel(R) Integrated Performance Primitives (IPP) # installation/package # -# This will try to find Intel IPP libraries, and include path by automatic -# search through typical install locations and if failed it will -# examine IPPROOT environment variable. -# Note, IPPROOT is not set by IPP installer, it should be set manually. +# Windows host: +# Run script like this before cmake: +# call "\bin\ippvars.bat" intel64 +# for example: +# call "C:\Program Files (x86)\Intel\Composer XE\ipp\bin\ippvars.bat" intel64 +# +# Linux host: +# Run script like this before cmake: +# source /opt/intel/ipp/bin/ippvars.sh [ia32|intel64] # # On return this will define: # -# IPP_FOUND - True if Intel IPP found -# IPP_ROOT_DIR - root of IPP installation -# IPP_INCLUDE_DIRS - IPP include folder -# IPP_LIBRARY_DIRS - IPP libraries folder -# IPP_LIBRARIES - IPP libraries names that are used by OpenCV -# IPP_LATEST_VERSION_STR - string with the newest detected IPP version -# IPP_LATEST_VERSION_MAJOR - numbers of IPP version (MAJOR.MINOR.BUILD) -# IPP_LATEST_VERSION_MINOR -# IPP_LATEST_VERSION_BUILD +# HAVE_IPP - True if Intel IPP found +# HAVE_IPP_ICV_ONLY - True if Intel IPP ICV version is available +# IPP_ROOT_DIR - root of IPP installation +# IPP_INCLUDE_DIRS - IPP include folder +# IPP_LIBRARIES - IPP libraries that are used by OpenCV +# IPP_VERSION_STR - string with the newest detected IPP version +# IPP_VERSION_MAJOR - numbers of IPP version (MAJOR.MINOR.BUILD) +# IPP_VERSION_MINOR +# IPP_VERSION_BUILD # # Created: 30 Dec 2010 by Vladimir Dudnik (vladimir.dudnik@intel.com) # -set(IPP_FOUND) -set(IPP_VERSION_STR "5.3.0.0") # will not detect earlier versions -set(IPP_VERSION_MAJOR 0) -set(IPP_VERSION_MINOR 0) -set(IPP_VERSION_BUILD 0) -set(IPP_ROOT_DIR) -set(IPP_INCLUDE_DIRS) -set(IPP_LIBRARY_DIRS) -set(IPP_LIBRARIES) +unset(HAVE_IPP CACHE) +unset(HAVE_IPP_ICV_ONLY) +unset(IPP_ROOT_DIR) +unset(IPP_INCLUDE_DIRS) +unset(IPP_LIBRARIES) +unset(IPP_VERSION_STR) +unset(IPP_VERSION_MAJOR) +unset(IPP_VERSION_MINOR) +unset(IPP_VERSION_BUILD) + set(IPP_LIB_PREFIX ${CMAKE_STATIC_LIBRARY_PREFIX}) set(IPP_LIB_SUFFIX ${CMAKE_STATIC_LIBRARY_SUFFIX}) set(IPP_PREFIX "ipp") @@ -42,322 +48,184 @@ set(IPPCC "cc") # color conversion set(IPPCV "cv") # computer vision set(IPPVM "vm") # vector math - set(IPP_X64 0) -if (CMAKE_CXX_SIZEOF_DATA_PTR EQUAL 8) +if(CMAKE_CXX_SIZEOF_DATA_PTR EQUAL 8) set(IPP_X64 1) endif() -if (CMAKE_CL_64) +if(CMAKE_CL_64) set(IPP_X64 1) endif() -# ------------------------------------------------------------------------ -# This function detect IPP version by analyzing ippversion.h file -# Note, ippversion.h file was inroduced since IPP 5.3 -# ------------------------------------------------------------------------ -function(get_ipp_version _ROOT_DIR) - set(_VERSION_STR) - set(_MAJOR) - set(_MINOR) - set(_BUILD) +# This function detects IPP version by analyzing ippversion.h file +macro(ipp_get_version _ROOT_DIR) + unset(_VERSION_STR) + unset(_MAJOR) + unset(_MINOR) + unset(_BUILD) - # read IPP version info from file - file(STRINGS ${_ROOT_DIR}/include/ippversion.h STR1 REGEX "IPP_VERSION_MAJOR") - file(STRINGS ${_ROOT_DIR}/include/ippversion.h STR2 REGEX "IPP_VERSION_MINOR") - file(STRINGS ${_ROOT_DIR}/include/ippversion.h STR3 REGEX "IPP_VERSION_BUILD") - if("${STR3}" STREQUAL "") - file(STRINGS ${_ROOT_DIR}/include/ippversion.h STR3 REGEX "IPP_VERSION_UPDATE") - endif() - file(STRINGS ${_ROOT_DIR}/include/ippversion.h STR4 REGEX "IPP_VERSION_STR") + # read IPP version info from file + file(STRINGS ${_ROOT_DIR}/include/ippversion.h STR1 REGEX "IPP_VERSION_MAJOR") + file(STRINGS ${_ROOT_DIR}/include/ippversion.h STR2 REGEX "IPP_VERSION_MINOR") + file(STRINGS ${_ROOT_DIR}/include/ippversion.h STR3 REGEX "IPP_VERSION_BUILD") + if("${STR3}" STREQUAL "") + file(STRINGS ${_ROOT_DIR}/include/ippversion.h STR3 REGEX "IPP_VERSION_UPDATE") + endif() + file(STRINGS ${_ROOT_DIR}/include/ippversion.h STR4 REGEX "IPP_VERSION_STR") - # extract info and assign to variables - string(REGEX MATCHALL "[0-9]+" _MAJOR ${STR1}) - string(REGEX MATCHALL "[0-9]+" _MINOR ${STR2}) - string(REGEX MATCHALL "[0-9]+" _BUILD ${STR3}) - string(REGEX MATCHALL "[0-9]+[.]+[0-9]+[^\"]+|[0-9]+[.]+[0-9]+" _VERSION_STR ${STR4}) + # extract info and assign to variables + string(REGEX MATCHALL "[0-9]+" _MAJOR ${STR1}) + string(REGEX MATCHALL "[0-9]+" _MINOR ${STR2}) + string(REGEX MATCHALL "[0-9]+" _BUILD ${STR3}) + string(REGEX MATCHALL "[0-9]+[.]+[0-9]+[^\"]+|[0-9]+[.]+[0-9]+" _VERSION_STR ${STR4}) - # export info to parent scope - set(IPP_VERSION_STR ${_VERSION_STR} PARENT_SCOPE) - set(IPP_VERSION_MAJOR ${_MAJOR} PARENT_SCOPE) - set(IPP_VERSION_MINOR ${_MINOR} PARENT_SCOPE) - set(IPP_VERSION_BUILD ${_BUILD} PARENT_SCOPE) + # export info to parent scope + set(IPP_VERSION_STR ${_VERSION_STR}) + set(IPP_VERSION_MAJOR ${_MAJOR}) + set(IPP_VERSION_MINOR ${_MINOR}) + set(IPP_VERSION_BUILD ${_BUILD}) - message(STATUS "found IPP: ${_MAJOR}.${_MINOR}.${_BUILD} [${_VERSION_STR}]") - message(STATUS "at: ${_ROOT_DIR}") + set(__msg) + if(EXISTS ${_ROOT_DIR}/include/ippicv.h) + ocv_assert(WITH_ICV AND NOT WITH_IPP) + set(__msg " ICV version") + set(HAVE_IPP_ICV_ONLY 1) + endif() + message(STATUS "found IPP: ${_MAJOR}.${_MINOR}.${_BUILD} [${_VERSION_STR}]${__msg}") + message(STATUS "at: ${_ROOT_DIR}") +endmacro() + + +# This function sets IPP_INCLUDE_DIRS and IPP_LIBRARIES variables +macro(ipp_set_variables _LATEST_VERSION) + if(${_LATEST_VERSION} VERSION_LESS "7.0") + message(SEND_ERROR "IPP ${_LATEST_VERSION} is not supported") + unset(HAVE_IPP) return() + endif() -endfunction() + # set INCLUDE and LIB folders + set(IPP_INCLUDE_DIRS ${IPP_ROOT_DIR}/include) - -# ------------------------------------------------------------------------ -# This is auxiliary function called from set_ipp_variables() -# to set IPP_LIBRARIES variable in IPP 6.x style (IPP 5.3 should also work) -# ------------------------------------------------------------------------ -function(set_ipp_old_libraries) - set(IPP_PREFIX "ipp") - set(IPP_SUFFIX) # old style static core libs suffix - set(IPP_ARCH) # architecture suffix - set(IPP_DISP "emerged") # old style dipatcher and cpu-specific - set(IPP_MRGD "merged") # static libraries - set(IPPCORE "core") # core functionality - set(IPPSP "s") # signal processing - set(IPPIP "i") # image processing - set(IPPCC "cc") # color conversion - set(IPPCV "cv") # computer vision - set(IPPVM "vm") # vector math - - if (IPP_X64) - set(IPP_ARCH "em64t") + if(NOT HAVE_IPP_ICV_ONLY) + if(APPLE) + set(IPP_LIBRARY_DIR ${IPP_ROOT_DIR}/lib) + elseif(IPP_X64) + if(NOT EXISTS ${IPP_ROOT_DIR}/lib/intel64) + message(SEND_ERROR "IPP EM64T libraries not found") + endif() + set(IPP_LIBRARY_DIR ${IPP_ROOT_DIR}/lib/intel64) + else() + if(NOT EXISTS ${IPP_ROOT_DIR}/lib/ia32) + message(SEND_ERROR "IPP IA32 libraries not found") + endif() + set(IPP_LIBRARY_DIR ${IPP_ROOT_DIR}/lib/ia32) endif() + else() + if(APPLE) + set(IPP_LIBRARY_DIR ${IPP_ROOT_DIR}/libs/macosx) + elseif(WIN32 AND NOT ARM) + set(IPP_LIBRARY_DIR ${IPP_ROOT_DIR}/libs/windows) + elseif(UNIX) + set(IPP_LIBRARY_DIR ${IPP_ROOT_DIR}/libs/linux) + else() + message(MESSAGE "IPP ${_LATEST_VERSION} at ${IPP_ROOT_DIR} is not supported") + unset(HAVE_IPP) + return() + endif() + if(X86_64) + set(IPP_LIBRARY_DIR ${IPP_LIBRARY_DIR}/intel64) + else() + set(IPP_LIBRARY_DIR ${IPP_LIBRARY_DIR}/ia32) + endif() + endif() + set(IPP_PREFIX "ipp") + if(${_LATEST_VERSION} VERSION_LESS "8.0") + set(IPP_SUFFIX "_l") # static not threaded libs suffix IPP 7.x + else() if(WIN32) - set(IPP_SUFFIX "l") - endif() - - set(IPP_LIBRARIES - ${IPP_LIB_PREFIX}${IPP_PREFIX}${IPPVM}${IPP_MRGD}${IPP_ARCH}${IPP_LIB_SUFFIX} - ${IPP_LIB_PREFIX}${IPP_PREFIX}${IPPVM}${IPP_DISP}${IPP_ARCH}${IPP_LIB_SUFFIX} - ${IPP_LIB_PREFIX}${IPP_PREFIX}${IPPCC}${IPP_MRGD}${IPP_ARCH}${IPP_LIB_SUFFIX} - ${IPP_LIB_PREFIX}${IPP_PREFIX}${IPPCC}${IPP_DISP}${IPP_ARCH}${IPP_LIB_SUFFIX} - ${IPP_LIB_PREFIX}${IPP_PREFIX}${IPPCV}${IPP_MRGD}${IPP_ARCH}${IPP_LIB_SUFFIX} - ${IPP_LIB_PREFIX}${IPP_PREFIX}${IPPCV}${IPP_DISP}${IPP_ARCH}${IPP_LIB_SUFFIX} - ${IPP_LIB_PREFIX}${IPP_PREFIX}${IPPIP}${IPP_MRGD}${IPP_ARCH}${IPP_LIB_SUFFIX} - ${IPP_LIB_PREFIX}${IPP_PREFIX}${IPPIP}${IPP_DISP}${IPP_ARCH}${IPP_LIB_SUFFIX} - ${IPP_LIB_PREFIX}${IPP_PREFIX}${IPPSP}${IPP_MRGD}${IPP_ARCH}${IPP_LIB_SUFFIX} - ${IPP_LIB_PREFIX}${IPP_PREFIX}${IPPSP}${IPP_DISP}${IPP_ARCH}${IPP_LIB_SUFFIX} - ${IPP_LIB_PREFIX}${IPP_PREFIX}${IPPCORE}${IPP_ARCH}${IPP_SUFFIX}${IPP_LIB_SUFFIX} - PARENT_SCOPE) - - return() - -endfunction() - - -# ------------------------------------------------------------------------ -# This is auxiliary function called from set_ipp_variables() -# to set IPP_LIBRARIES variable in IPP 7.x and 8.x style -# ------------------------------------------------------------------------ -function(set_ipp_new_libraries _LATEST_VERSION) - set(IPP_PREFIX "ipp") - - if(${_LATEST_VERSION} VERSION_LESS "8.0") - set(IPP_SUFFIX "_l") # static not threaded libs suffix IPP 7.x + set(IPP_SUFFIX "mt") # static not threaded libs suffix IPP 8.x for Windows else() - if(WIN32) - set(IPP_SUFFIX "mt") # static not threaded libs suffix IPP 8.x for Windows - else() - set(IPP_SUFFIX "") # static not threaded libs suffix IPP 8.x for Linux/OS X - endif() + set(IPP_SUFFIX "") # static not threaded libs suffix IPP 8.x for Linux/OS X endif() - set(IPPCORE "core") # core functionality - set(IPPSP "s") # signal processing - set(IPPIP "i") # image processing - set(IPPCC "cc") # color conversion - set(IPPCV "cv") # computer vision - set(IPPVM "vm") # vector math + endif() + set(IPPCORE "core") # core functionality + set(IPPSP "s") # signal processing + set(IPPIP "i") # image processing + set(IPPCC "cc") # color conversion + set(IPPCV "cv") # computer vision + set(IPPVM "vm") # vector math - set(IPP_LIBRARIES - ${IPP_LIB_PREFIX}${IPP_PREFIX}${IPPVM}${IPP_SUFFIX}${IPP_LIB_SUFFIX} - ${IPP_LIB_PREFIX}${IPP_PREFIX}${IPPCC}${IPP_SUFFIX}${IPP_LIB_SUFFIX} - ${IPP_LIB_PREFIX}${IPP_PREFIX}${IPPCV}${IPP_SUFFIX}${IPP_LIB_SUFFIX} - ${IPP_LIB_PREFIX}${IPP_PREFIX}${IPPI}${IPP_SUFFIX}${IPP_LIB_SUFFIX} - ${IPP_LIB_PREFIX}${IPP_PREFIX}${IPPS}${IPP_SUFFIX}${IPP_LIB_SUFFIX} - ${IPP_LIB_PREFIX}${IPP_PREFIX}${IPPCORE}${IPP_SUFFIX}${IPP_LIB_SUFFIX}) - - if (UNIX) - set(IPP_LIBRARIES - ${IPP_LIBRARIES} - ${IPP_LIB_PREFIX}irc${CMAKE_SHARED_LIBRARY_SUFFIX} - ${IPP_LIB_PREFIX}imf${CMAKE_SHARED_LIBRARY_SUFFIX} - ${IPP_LIB_PREFIX}svml${CMAKE_SHARED_LIBRARY_SUFFIX}) - endif() - set(IPP_LIBRARIES ${IPP_LIBRARIES} PARENT_SCOPE) - return() - -endfunction() - - -# ------------------------------------------------------------------------ -# This function will set -# IPP_INCLUDE_DIRS, IPP_LIBRARY_DIRS and IPP_LIBRARIES variables depending -# on IPP version parameter. -# Since IPP 7.0 version library names and install folder structure -# was changed -# ------------------------------------------------------------------------ -function(set_ipp_variables _LATEST_VERSION) - if(${_LATEST_VERSION} VERSION_LESS "7.0") -# message(STATUS "old") - - # set INCLUDE and LIB folders - set(IPP_INCLUDE_DIRS ${IPP_ROOT_DIR}/include PARENT_SCOPE) - set(IPP_LIBRARY_DIRS ${IPP_ROOT_DIR}/lib PARENT_SCOPE) - - if (IPP_X64) - if(NOT EXISTS ${IPP_ROOT_DIR}/../em64t) - message(SEND_ERROR "IPP EM64T libraries not found") - endif() - else() - if(NOT EXISTS ${IPP_ROOT_DIR}/../ia32) - message(SEND_ERROR "IPP IA32 libraries not found") - endif() - endif() - - # set IPP_LIBRARIES variable (6.x lib names) - set_ipp_old_libraries() - set(IPP_LIBRARIES ${IPP_LIBRARIES} PARENT_SCOPE) - message(STATUS "IPP libs: ${IPP_LIBRARIES}") + list(APPEND IPP_LIBRARIES ${IPP_LIBRARY_DIR}/${IPP_LIB_PREFIX}${IPP_PREFIX}${IPPVM}${IPP_SUFFIX}${IPP_LIB_SUFFIX}) + list(APPEND IPP_LIBRARIES ${IPP_LIBRARY_DIR}/${IPP_LIB_PREFIX}${IPP_PREFIX}${IPPCC}${IPP_SUFFIX}${IPP_LIB_SUFFIX}) + list(APPEND IPP_LIBRARIES ${IPP_LIBRARY_DIR}/${IPP_LIB_PREFIX}${IPP_PREFIX}${IPPCV}${IPP_SUFFIX}${IPP_LIB_SUFFIX}) + list(APPEND IPP_LIBRARIES ${IPP_LIBRARY_DIR}/${IPP_LIB_PREFIX}${IPP_PREFIX}${IPPI}${IPP_SUFFIX}${IPP_LIB_SUFFIX}) + list(APPEND IPP_LIBRARIES ${IPP_LIBRARY_DIR}/${IPP_LIB_PREFIX}${IPP_PREFIX}${IPPS}${IPP_SUFFIX}${IPP_LIB_SUFFIX}) + list(APPEND IPP_LIBRARIES ${IPP_LIBRARY_DIR}/${IPP_LIB_PREFIX}${IPP_PREFIX}${IPPCORE}${IPP_SUFFIX}${IPP_LIB_SUFFIX}) +# FIXIT +# if(UNIX AND NOT HAVE_IPP_ICV_ONLY) +# get_filename_component(INTEL_COMPILER_LIBRARY_DIR ${IPP_ROOT_DIR}/../lib REALPATH) + if(UNIX) + if(NOT HAVE_IPP_ICV_ONLY) + get_filename_component(INTEL_COMPILER_LIBRARY_DIR ${IPP_ROOT_DIR}/../lib REALPATH) else() -# message(STATUS "new") - - # set INCLUDE and LIB folders - set(IPP_INCLUDE_DIRS ${IPP_ROOT_DIR}/include PARENT_SCOPE) - - if (APPLE) - set(IPP_LIBRARY_DIRS ${IPP_ROOT_DIR}/lib) - elseif (IPP_X64) - if(NOT EXISTS ${IPP_ROOT_DIR}/lib/intel64) - message(SEND_ERROR "IPP EM64T libraries not found") - endif() - set(IPP_LIBRARY_DIRS ${IPP_ROOT_DIR}/lib/intel64) - else() - if(NOT EXISTS ${IPP_ROOT_DIR}/lib/ia32) - message(SEND_ERROR "IPP IA32 libraries not found") - endif() - set(IPP_LIBRARY_DIRS ${IPP_ROOT_DIR}/lib/ia32) - endif() - - if (UNIX) - get_filename_component(INTEL_COMPILER_LIBRARY_DIR ${IPP_ROOT_DIR}/../lib REALPATH) - if (IPP_X64) - if(NOT EXISTS ${INTEL_COMPILER_LIBRARY_DIR}/intel64) - message(SEND_ERROR "Intel compiler EM64T libraries not found") - endif() - set(IPP_LIBRARY_DIRS - ${IPP_LIBRARY_DIRS} - ${INTEL_COMPILER_LIBRARY_DIR}/intel64) - else() - if(NOT EXISTS ${INTEL_COMPILER_LIBRARY_DIR}/ia32) - message(SEND_ERROR "Intel compiler IA32 libraries not found") - endif() - set(IPP_LIBRARY_DIRS - ${IPP_LIBRARY_DIRS} - ${INTEL_COMPILER_LIBRARY_DIR}/ia32) - endif() - endif() - set(IPP_LIBRARY_DIRS ${IPP_LIBRARY_DIRS} PARENT_SCOPE) - - # set IPP_LIBRARIES variable (7.x or 8.x lib names) - set_ipp_new_libraries(${_LATEST_VERSION}) - set(IPP_LIBRARIES ${IPP_LIBRARIES} PARENT_SCOPE) - message(STATUS "IPP libs: ${IPP_LIBRARIES}") - + set(INTEL_COMPILER_LIBRARY_DIR "/opt/intel/lib") endif() + if(IPP_X64) + if(NOT EXISTS ${INTEL_COMPILER_LIBRARY_DIR}/intel64) + message(SEND_ERROR "Intel compiler EM64T libraries not found") + endif() + set(INTEL_COMPILER_LIBRARY_DIR ${INTEL_COMPILER_LIBRARY_DIR}/intel64) + else() + if(NOT EXISTS ${INTEL_COMPILER_LIBRARY_DIR}/ia32) + message(SEND_ERROR "Intel compiler IA32 libraries not found") + endif() + set(INTEL_COMPILER_LIBRARY_DIR ${INTEL_COMPILER_LIBRARY_DIR}/ia32) + endif() + list(APPEND IPP_LIBRARIES ${INTEL_COMPILER_LIBRARY_DIR}/${IPP_LIB_PREFIX}irc${CMAKE_SHARED_LIBRARY_SUFFIX}) + list(APPEND IPP_LIBRARIES ${INTEL_COMPILER_LIBRARY_DIR}/${IPP_LIB_PREFIX}imf${CMAKE_SHARED_LIBRARY_SUFFIX}) + list(APPEND IPP_LIBRARIES ${INTEL_COMPILER_LIBRARY_DIR}/${IPP_LIB_PREFIX}svml${CMAKE_SHARED_LIBRARY_SUFFIX}) + endif() - return() + #message(STATUS "IPP libs: ${IPP_LIBRARIES}") +endmacro() -endfunction() +if(WITH_IPP) + set(IPPPATH $ENV{IPPROOT}) + if(UNIX) + list(APPEND IPPPATH /opt/intel/ipp) + endif() +elseif(WITH_ICV) + if(DEFINED ENV{IPPICVROOT}) + set(IPPPATH $ENV{IPPICVROOT}) + else() + set(IPPPATH ${OpenCV_SOURCE_DIR}/3rdparty/ippicv) + endif() +endif() -# ------------------------------------------------------------------------ -# This section will look for IPP through IPPROOT env variable -# Note, IPPROOT is not set by IPP installer, you may need to set it manually -# ------------------------------------------------------------------------ find_path( IPP_H_PATH NAMES ippversion.h - PATHS $ENV{IPPROOT} + PATHS ${IPPPATH} PATH_SUFFIXES include DOC "The path to Intel(R) IPP header files" NO_DEFAULT_PATH NO_CMAKE_PATH) if(IPP_H_PATH) - set(IPP_FOUND 1) + set(HAVE_IPP 1) - # traverse up to IPPROOT level get_filename_component(IPP_ROOT_DIR ${IPP_H_PATH} PATH) - # extract IPP version info - get_ipp_version(${IPP_ROOT_DIR}) - - # keep info in the same vars for auto search and search by IPPROOT - set(IPP_LATEST_VERSION_STR ${IPP_VERSION_STR}) - set(IPP_LATEST_VERSION_MAJOR ${IPP_VERSION_MAJOR}) - set(IPP_LATEST_VERSION_MINOR ${IPP_VERSION_MINOR}) - set(IPP_LATEST_VERSION_BUILD ${IPP_VERSION_BUILD}) - - # set IPP INCLUDE, LIB dirs and library names - set_ipp_variables(${IPP_LATEST_VERSION_STR}) + ipp_get_version(${IPP_ROOT_DIR}) + ipp_set_variables(${IPP_VERSION_STR}) endif() -if(NOT IPP_FOUND) - # reset var from previous search - set(IPP_H_PATH) - - - # ------------------------------------------------------------------------ - # This section will look for IPP through system program folders - # Note, if several IPP installations found the newest version will be - # selected - # ------------------------------------------------------------------------ - foreach(curdir ${CMAKE_SYSTEM_PREFIX_PATH}) - set(curdir ${curdir}/intel) - file(TO_CMAKE_PATH ${curdir} CURDIR) - - if(EXISTS ${curdir}) - file(GLOB_RECURSE IPP_H_DIR ${curdir}/ippversion.h) - - if(IPP_H_DIR) - set(IPP_FOUND 1) - endif() - - # init IPP_LATEST_VERSION version with oldest detectable version (5.3.0.0) - # IPP prior 5.3 did not have ippversion.h file - set(IPP_LATEST_VERSION_STR ${IPP_VERSION_STR}) - - # look through all dirs where ippversion.h was found - foreach(item ${IPP_H_DIR}) - - # traverse up to IPPROOT level - get_filename_component(_FILE_PATH ${item} PATH) - get_filename_component(_ROOT_DIR ${_FILE_PATH} PATH) - - # extract IPP version info - get_ipp_version(${_ROOT_DIR}) - - # remember the latest version (if many found) - if(${IPP_LATEST_VERSION_STR} VERSION_LESS ${IPP_VERSION_STR}) - set(IPP_LATEST_VERSION_STR ${IPP_VERSION_STR}) - set(IPP_LATEST_VERSION_MAJOR ${IPP_VERSION_MAJOR}) - set(IPP_LATEST_VERSION_MINOR ${IPP_VERSION_MINOR}) - set(IPP_LATEST_VERSION_BUILD ${IPP_VERSION_BUILD}) - set(IPP_ROOT_DIR ${_ROOT_DIR}) - endif() - endforeach() - endif() - endforeach() -endif() - -if(IPP_FOUND) - # set IPP INCLUDE, LIB dirs and library names - set_ipp_variables(${IPP_LATEST_VERSION_STR}) - - # set CACHE variable IPP_H_PATH, - # path to IPP header files for the latest version - find_path( - IPP_H_PATH - NAMES ippversion.h - PATHS ${IPP_ROOT_DIR} - PATH_SUFFIXES include - DOC "The path to Intel(R) IPP header files" - NO_DEFAULT_PATH - NO_CMAKE_PATH) -endif() - -if(WIN32 AND MINGW AND NOT IPP_LATEST_VERSION_MAJOR LESS 7) +if(WIN32 AND MINGW AND NOT IPP_VERSION_MAJOR LESS 7) # Since IPP built with Microsoft compiler and /GS option # ====================================================== # From Windows SDK 7.1 diff --git a/cmake/OpenCVFindIPPAsync.cmake b/cmake/OpenCVFindIPPAsync.cmake new file mode 100644 index 0000000000..6f4765cbc9 --- /dev/null +++ b/cmake/OpenCVFindIPPAsync.cmake @@ -0,0 +1,45 @@ +# Main variables: +# IPP_A_LIBRARIES and IPP_A_INCLUDE to use IPP Async +# HAVE_IPP_A for conditional compilation OpenCV with/without IPP Async + +# IPP_ASYNC_ROOT - root of IPP Async installation + +if(X86_64) + find_path( + IPP_A_INCLUDE_DIR + NAMES ipp_async_defs.h + PATHS $ENV{IPP_ASYNC_ROOT} + PATH_SUFFIXES include + DOC "Path to Intel IPP Async interface headers") + + find_file( + IPP_A_LIBRARIES + NAMES ipp_async_preview.lib + PATHS $ENV{IPP_ASYNC_ROOT} + PATH_SUFFIXES lib/intel64 + DOC "Path to Intel IPP Async interface libraries") + +else() + find_path( + IPP_A_INCLUDE_DIR + NAMES ipp_async_defs.h + PATHS $ENV{IPP_ASYNC_ROOT} + PATH_SUFFIXES include + DOC "Path to Intel IPP Async interface headers") + + find_file( + IPP_A_LIBRARIES + NAMES ipp_async_preview.lib + PATHS $ENV{IPP_ASYNC_ROOT} + PATH_SUFFIXES lib/ia32 + DOC "Path to Intel IPP Async interface libraries") +endif() + +if(IPP_A_INCLUDE_DIR AND IPP_A_LIBRARIES) + set(HAVE_IPP_A TRUE) +else() + set(HAVE_IPP_A FALSE) + message(WARNING "Intel IPP Async library directory (set by IPP_A_LIBRARIES_DIR variable) is not found or does not have Intel IPP Async libraries.") +endif() + +mark_as_advanced(FORCE IPP_A_LIBRARIES IPP_A_INCLUDE_DIR) \ No newline at end of file diff --git a/cmake/OpenCVFindLibsPerf.cmake b/cmake/OpenCVFindLibsPerf.cmake index 4b80b1f786..7198326351 100644 --- a/cmake/OpenCVFindLibsPerf.cmake +++ b/cmake/OpenCVFindLibsPerf.cmake @@ -8,16 +8,24 @@ if(WITH_TBB) endif(WITH_TBB) # --- IPP --- -ocv_clear_vars(IPP_FOUND) -if(WITH_IPP) +if(WITH_IPP OR WITH_ICV) include("${OpenCV_SOURCE_DIR}/cmake/OpenCVFindIPP.cmake") - if(IPP_FOUND) - add_definitions(-DHAVE_IPP) + if(HAVE_IPP) ocv_include_directories(${IPP_INCLUDE_DIRS}) - link_directories(${IPP_LIBRARY_DIRS}) - set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} ${IPP_LIBRARIES}) + list(APPEND OPENCV_LINKER_LIBS ${IPP_LIBRARIES}) endif() -endif(WITH_IPP) +endif() + +# --- IPP Async --- + +if(WITH_IPP_A) + include("${OpenCV_SOURCE_DIR}/cmake/OpenCVFindIPPAsync.cmake") + if(IPP_A_INCLUDE_DIR AND IPP_A_LIBRARIES) + ocv_include_directories(${IPP_A_INCLUDE_DIR}) + link_directories(${IPP_A_LIBRARIES}) + set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} ${IPP_A_LIBRARIES}) + endif() +endif(WITH_IPP_A) # --- CUDA --- if(WITH_CUDA) diff --git a/cmake/templates/cvconfig.h.in b/cmake/templates/cvconfig.h.in index 0a916682c5..588e138548 100644 --- a/cmake/templates/cvconfig.h.in +++ b/cmake/templates/cvconfig.h.in @@ -96,6 +96,10 @@ /* Intel Integrated Performance Primitives */ #cmakedefine HAVE_IPP +#cmakedefine HAVE_IPP_ICV_ONLY + +/* Intel IPP Async */ +#cmakedefine HAVE_IPP_A /* JPEG-2000 codec */ #cmakedefine HAVE_JASPER diff --git a/doc/conf.py b/doc/conf.py index c1e85cb826..a0c231c3b5 100755 --- a/doc/conf.py +++ b/doc/conf.py @@ -418,5 +418,7 @@ extlinks = { 'background_subtractor' : ('http://docs.opencv.org/modules/video/doc/motion_analysis_and_object_tracking.html?highlight=backgroundsubtractor#backgroundsubtractor%s', None), 'background_subtractor_mog' : ('http://docs.opencv.org/modules/video/doc/motion_analysis_and_object_tracking.html?highlight=backgroundsubtractorMOG#backgroundsubtractormog%s', None), 'background_subtractor_mog_two' : ('http://docs.opencv.org/modules/video/doc/motion_analysis_and_object_tracking.html?highlight=backgroundsubtractorMOG2#backgroundsubtractormog2%s', None), - 'video_capture' : ('http://docs.opencv.org/modules/highgui/doc/reading_and_writing_images_and_video.html?highlight=videocapture#videocapture%s', None) + 'video_capture' : ('http://docs.opencv.org/modules/highgui/doc/reading_and_writing_images_and_video.html?highlight=videocapture#videocapture%s', None), + 'ippa_convert': ('http://docs.opencv.org/modules/core/doc/ipp_async_converters.html#%s', None), + 'ptr':('http://docs.opencv.org/modules/core/doc/basic_structures.html?highlight=Ptr#Ptr%s', None) } diff --git a/doc/tutorials/core/how_to_use_ippa_conversion/how_to_use_ippa_conversion.rst b/doc/tutorials/core/how_to_use_ippa_conversion/how_to_use_ippa_conversion.rst new file mode 100644 index 0000000000..43f1f22d30 --- /dev/null +++ b/doc/tutorials/core/how_to_use_ippa_conversion/how_to_use_ippa_conversion.rst @@ -0,0 +1,164 @@ +.. _howToUseIPPAconversion: + +Intel® IPP Asynchronous C/C++ library in OpenCV +*********************************************** + +Goal +==== + +.. _hppiSobel: http://software.intel.com/en-us/node/474701 +.. _hppiMatrix: http://software.intel.com/en-us/node/501660 + +The tutorial demonstrates the `Intel® IPP Asynchronous C/C++ `_ library usage with OpenCV. +The code example below illustrates implementation of the Sobel operation, accelerated with Intel® IPP Asynchronous C/C++ functions. +In this code example, :ippa_convert:`hpp::getMat <>` and :ippa_convert:`hpp::getHpp <>` functions are used for data conversion between hppiMatrix_ and ``Mat`` matrices. + +Code +==== + +You may also find the source code in the :file:`samples/cpp/tutorial_code/core/ippasync/ippasync_sample.cpp` +file of the OpenCV source library or :download:`download it from here +<../../../../samples/cpp/tutorial_code/core/ippasync/ippasync_sample.cpp>`. + +.. literalinclude:: ../../../../samples/cpp/tutorial_code/core/ippasync/ippasync_sample.cpp + :language: cpp + :linenos: + :tab-width: 4 + +Explanation +=========== + +#. Create parameters for OpenCV: + + .. code-block:: cpp + + VideoCapture cap; + Mat image, gray, result; + + and IPP Async: + + .. code-block:: cpp + + hppiMatrix* src,* dst; + hppAccel accel = 0; + hppAccelType accelType; + hppStatus sts; + hppiVirtualMatrix * virtMatrix; + +#. Load input image or video. How to open and read video stream you can see in the :ref:`videoInputPSNRMSSIM` tutorial. + + .. code-block:: cpp + + if( useCamera ) + { + printf("used camera\n"); + cap.open(0); + } + else + { + printf("used image %s\n", file.c_str()); + cap.open(file.c_str()); + } + + if( !cap.isOpened() ) + { + printf("can not open camera or video file\n"); + return -1; + } + +#. Create accelerator instance using `hppCreateInstance `_: + + .. code-block:: cpp + + accelType = sAccel == "cpu" ? HPP_ACCEL_TYPE_CPU: + sAccel == "gpu" ? HPP_ACCEL_TYPE_GPU: + HPP_ACCEL_TYPE_ANY; + + //Create accelerator instance + sts = hppCreateInstance(accelType, 0, &accel); + CHECK_STATUS(sts, "hppCreateInstance"); + +#. Create an array of virtual matrices using `hppiCreateVirtualMatrices `_ function. + + .. code-block:: cpp + + virtMatrix = hppiCreateVirtualMatrices(accel, 1); + +#. Prepare a matrix for input and output data: + + .. code-block:: cpp + + cap >> image; + if(image.empty()) + break; + + cvtColor( image, gray, COLOR_BGR2GRAY ); + + result.create( image.rows, image.cols, CV_8U); + +#. Convert ``Mat`` to hppiMatrix_ using :ippa_convert:`getHpp <>` and call hppiSobel_ function. + + .. code-block:: cpp + + //convert Mat to hppiMatrix + src = getHpp(gray, accel); + dst = getHpp(result, accel); + + sts = hppiSobel(accel,src, HPP_MASK_SIZE_3X3,HPP_NORM_L1,virtMatrix[0]); + CHECK_STATUS(sts,"hppiSobel"); + + sts = hppiConvert(accel, virtMatrix[0], 0, HPP_RND_MODE_NEAR, dst, HPP_DATA_TYPE_8U); + CHECK_STATUS(sts,"hppiConvert"); + + // Wait for tasks to complete + sts = hppWait(accel, HPP_TIME_OUT_INFINITE); + CHECK_STATUS(sts, "hppWait"); + + We use `hppiConvert `_ because hppiSobel_ returns destination + matrix with ``HPP_DATA_TYPE_16S`` data type for source matrix with ``HPP_DATA_TYPE_8U`` type. + You should check ``hppStatus`` after each call IPP Async function. + +#. Create windows and show the images, the usual way. + + .. code-block:: cpp + + imshow("image", image); + imshow("rez", result); + + waitKey(15); + +#. Delete hpp matrices. + + .. code-block:: cpp + + sts = hppiFreeMatrix(src); + CHECK_DEL_STATUS(sts,"hppiFreeMatrix"); + + sts = hppiFreeMatrix(dst); + CHECK_DEL_STATUS(sts,"hppiFreeMatrix"); + +#. Delete virtual matrices and accelerator instance. + + .. code-block:: cpp + + if (virtMatrix) + { + sts = hppiDeleteVirtualMatrices(accel, virtMatrix); + CHECK_DEL_STATUS(sts,"hppiDeleteVirtualMatrices"); + } + + if (accel) + { + sts = hppDeleteInstance(accel); + CHECK_DEL_STATUS(sts, "hppDeleteInstance"); + } + +Result +======= + +After compiling the code above we can execute it giving an image or video path and accelerator type as an argument. +For this tutorial we use baboon.png image as input. The result is below. + + .. image:: images/How_To_Use_IPPA_Result.jpg + :alt: Final Result + :align: center \ No newline at end of file diff --git a/doc/tutorials/core/how_to_use_ippa_conversion/images/How_To_Use_IPPA_Result.jpg b/doc/tutorials/core/how_to_use_ippa_conversion/images/How_To_Use_IPPA_Result.jpg new file mode 100644 index 0000000000..2bdeb830cb Binary files /dev/null and b/doc/tutorials/core/how_to_use_ippa_conversion/images/How_To_Use_IPPA_Result.jpg differ diff --git a/doc/tutorials/core/table_of_content_core/images/How_To_Use_IPPA.jpg b/doc/tutorials/core/table_of_content_core/images/How_To_Use_IPPA.jpg new file mode 100644 index 0000000000..8bba605302 Binary files /dev/null and b/doc/tutorials/core/table_of_content_core/images/How_To_Use_IPPA.jpg differ diff --git a/doc/tutorials/core/table_of_content_core/table_of_content_core.rst b/doc/tutorials/core/table_of_content_core/table_of_content_core.rst index 4150265d10..1fcf4ee2b1 100644 --- a/doc/tutorials/core/table_of_content_core/table_of_content_core.rst +++ b/doc/tutorials/core/table_of_content_core/table_of_content_core.rst @@ -200,7 +200,28 @@ Here you will learn the about the basic building blocks of the library. A must r :height: 90pt :width: 90pt + =============== ====================================================== ++ + .. tabularcolumns:: m{100pt} m{300pt} + .. cssclass:: toctableopencv + =============== ====================================================== + |IPPIma| **Title:** :ref:`howToUseIPPAconversion` + + *Compatibility:* > OpenCV 2.0 + + *Author:* |Author_ElenaG| + + You will see how to use the IPP Async with OpenCV. + + =============== ====================================================== + + .. |IPPIma| image:: images/How_To_Use_IPPA.jpg + :height: 90pt + :width: 90pt + .. |Author_ElenaG| unicode:: Elena U+0020 Gvozdeva + + =============== ====================================================== .. raw:: latex @@ -219,3 +240,4 @@ Here you will learn the about the basic building blocks of the library. A must r ../discrete_fourier_transform/discrete_fourier_transform ../file_input_output_with_xml_yml/file_input_output_with_xml_yml ../interoperability_with_OpenCV_1/interoperability_with_OpenCV_1 + ../how_to_use_ippa_conversion/how_to_use_ippa_conversion diff --git a/doc/tutorials/introduction/android_binary_package/O4A_SDK.rst b/doc/tutorials/introduction/android_binary_package/O4A_SDK.rst index ef9337aae2..a70a98d52a 100644 --- a/doc/tutorials/introduction/android_binary_package/O4A_SDK.rst +++ b/doc/tutorials/introduction/android_binary_package/O4A_SDK.rst @@ -48,10 +48,10 @@ The structure of package contents looks as follows: :: - OpenCV-2.4.8-android-sdk + OpenCV-2.4.9-android-sdk |_ apk - | |_ OpenCV_2.4.8_binary_pack_armv7a.apk - | |_ OpenCV_2.4.8_Manager_2.16_XXX.apk + | |_ OpenCV_2.4.9_binary_pack_armv7a.apk + | |_ OpenCV_2.4.9_Manager_2.18_XXX.apk | |_ doc |_ samples @@ -157,10 +157,10 @@ Get the OpenCV4Android SDK .. code-block:: bash - unzip ~/Downloads/OpenCV-2.4.8-android-sdk.zip + unzip ~/Downloads/OpenCV-2.4.9-android-sdk.zip -.. |opencv_android_bin_pack| replace:: :file:`OpenCV-2.4.8-android-sdk.zip` -.. _opencv_android_bin_pack_url: http://sourceforge.net/projects/opencvlibrary/files/opencv-android/2.4.8/OpenCV-2.4.8-android-sdk.zip/download +.. |opencv_android_bin_pack| replace:: :file:`OpenCV-2.4.9-android-sdk.zip` +.. _opencv_android_bin_pack_url: http://sourceforge.net/projects/opencvlibrary/files/opencv-android/2.4.9/OpenCV-2.4.9-android-sdk.zip/download .. |opencv_android_bin_pack_url| replace:: |opencv_android_bin_pack| .. |seven_zip| replace:: 7-Zip .. _seven_zip: http://www.7-zip.org/ @@ -295,7 +295,7 @@ Well, running samples from Eclipse is very simple: .. code-block:: sh :linenos: - /platform-tools/adb install /apk/OpenCV_2.4.8_Manager_2.16_armv7a-neon.apk + /platform-tools/adb install /apk/OpenCV_2.4.9_Manager_2.18_armv7a-neon.apk .. note:: ``armeabi``, ``armv7a-neon``, ``arm7a-neon-android8``, ``mips`` and ``x86`` stand for platform targets: 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 bc9ff7a4a8..6fe8f6b941 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 @@ -55,14 +55,14 @@ Manager to access OpenCV libraries externally installed in the target system. :guilabel:`File -> Import -> Existing project in your workspace`. Press :guilabel:`Browse` button and locate OpenCV4Android SDK - (:file:`OpenCV-2.4.8-android-sdk/sdk`). + (:file:`OpenCV-2.4.9-android-sdk/sdk`). .. image:: images/eclipse_opencv_dependency0.png :alt: Add dependency from OpenCV library :align: center #. In application project add a reference to the OpenCV Java SDK in - :guilabel:`Project -> Properties -> Android -> Library -> Add` select ``OpenCV Library - 2.4.8``. + :guilabel:`Project -> Properties -> Android -> Library -> Add` select ``OpenCV Library - 2.4.9``. .. image:: images/eclipse_opencv_dependency1.png :alt: Add dependency from OpenCV library @@ -128,27 +128,27 @@ described above. #. Add the OpenCV library project to your workspace the same way as for the async initialization above. Use menu :guilabel:`File -> Import -> Existing project in your workspace`, press :guilabel:`Browse` button and select OpenCV SDK path - (:file:`OpenCV-2.4.8-android-sdk/sdk`). + (:file:`OpenCV-2.4.9-android-sdk/sdk`). .. image:: images/eclipse_opencv_dependency0.png :alt: Add dependency from OpenCV library :align: center #. In the application project add a reference to the OpenCV4Android SDK in - :guilabel:`Project -> Properties -> Android -> Library -> Add` select ``OpenCV Library - 2.4.8``; + :guilabel:`Project -> Properties -> Android -> Library -> Add` select ``OpenCV Library - 2.4.9``; .. image:: images/eclipse_opencv_dependency1.png :alt: Add dependency from OpenCV library :align: center #. If your application project **doesn't have a JNI part**, just copy the corresponding OpenCV - native libs from :file:`/sdk/native/libs/` to your + native libs from :file:`/sdk/native/libs/` to your project directory to folder :file:`libs/`. In case of the application project **with a JNI part**, instead of manual libraries copying you need to modify your ``Android.mk`` file: add the following two code lines after the ``"include $(CLEAR_VARS)"`` and before - ``"include path_to_OpenCV-2.4.8-android-sdk/sdk/native/jni/OpenCV.mk"`` + ``"include path_to_OpenCV-2.4.9-android-sdk/sdk/native/jni/OpenCV.mk"`` .. code-block:: make :linenos: @@ -221,7 +221,7 @@ taken: .. code-block:: make - include C:\Work\OpenCV4Android\OpenCV-2.4.8-android-sdk\sdk\native\jni\OpenCV.mk + include C:\Work\OpenCV4Android\OpenCV-2.4.9-android-sdk\sdk\native\jni\OpenCV.mk Should be inserted into the :file:`jni/Android.mk` file **after** this line: diff --git a/doc/tutorials/introduction/windows_install/windows_install.rst b/doc/tutorials/introduction/windows_install/windows_install.rst index dd91027ba3..f4e9767e77 100644 --- a/doc/tutorials/introduction/windows_install/windows_install.rst +++ b/doc/tutorials/introduction/windows_install/windows_install.rst @@ -62,6 +62,8 @@ Building the OpenCV library from scratch requires a couple of tools installed be .. _IntelTBB: http://threadingbuildingblocks.org/file.php?fid=77 .. |IntelIIP| replace:: Intel |copy| Integrated Performance Primitives (*IPP*) .. _IntelIIP: http://software.intel.com/en-us/articles/intel-ipp/ +.. |IntelIIPA| replace:: Intel |copy| IPP Asynchronous C/C++ +.. _IntelIIPA: http://software.intel.com/en-us/intel-ipp-preview .. |qtframework| replace:: Qt framework .. _qtframework: http://qt.nokia.com/downloads .. |Eigen| replace:: Eigen @@ -97,6 +99,8 @@ OpenCV may come in multiple flavors. There is a "core" section that will work on + |IntelIIP|_ may be used to improve the performance of color conversion, Haar training and DFT functions of the OpenCV library. Watch out, since this isn't a free service. + + |IntelIIPA|_ is currently focused delivering Intel |copy| Graphics support for advanced image processing and computer vision functions. + + OpenCV offers a somewhat fancier and more useful graphical user interface, than the default one by using the |qtframework|_. For a quick overview of what this has to offer look into the documentations *highgui* module, under the *Qt New Functions* section. Version 4.6 or later of the framework is required. + |Eigen|_ is a C++ template library for linear algebra. @@ -168,6 +172,8 @@ Building the library :alt: The Miktex Install Screen :align: center + #) For the |IntelIIPA|_ download the source files and set environment variable **IPP_ASYNC_ROOT**. It should point to :file:`/Intel/IPP Preview */ipp directory`. Here ``*`` denotes the particular preview name. + #) In case of the |Eigen|_ library it is again a case of download and extract to the :file:`D:/OpenCV/dep` directory. #) Same as above with |OpenEXR|_. diff --git a/doc/tutorials/tutorials.rst b/doc/tutorials/tutorials.rst index cd58c44e9e..50b28dd19b 100644 --- a/doc/tutorials/tutorials.rst +++ b/doc/tutorials/tutorials.rst @@ -102,7 +102,7 @@ As always, we would be happy to hear your comments and receive your contribution .. cssclass:: toctableopencv =========== ======================================================= - |Video| Look here in order to find use on your video stream algoritms like: motion extraction, feature tracking and foreground extractions. + |Video| Look here in order to find use on your video stream algorithms like: motion extraction, feature tracking and foreground extractions. =========== ======================================================= diff --git a/doc/tutorials/video/table_of_content_video/table_of_content_video.rst b/doc/tutorials/video/table_of_content_video/table_of_content_video.rst index dcebcd7e24..8ec170f408 100644 --- a/doc/tutorials/video/table_of_content_video/table_of_content_video.rst +++ b/doc/tutorials/video/table_of_content_video/table_of_content_video.rst @@ -3,7 +3,7 @@ *video* module. Video analysis ----------------------------------------------------------- -Look here in order to find use on your video stream algoritms like: motion extraction, feature tracking and foreground extractions. +Look here in order to find use on your video stream algorithms like: motion extraction, feature tracking and foreground extractions. .. include:: ../../definitions/tocDefinitions.rst diff --git a/modules/calib3d/test/test_affine3.cpp b/modules/calib3d/test/test_affine3.cpp index cc94d99c19..03fe869c63 100644 --- a/modules/calib3d/test/test_affine3.cpp +++ b/modules/calib3d/test/test_affine3.cpp @@ -54,8 +54,8 @@ TEST(Calib3d_Affine3f, accuracy) cv::Rodrigues(rvec, expected); - ASSERT_EQ(0, norm(cv::Mat(affine.matrix, false).colRange(0, 3).rowRange(0, 3) != expected)); - ASSERT_EQ(0, norm(cv::Mat(affine.linear()) != expected)); + ASSERT_EQ(0, cvtest::norm(cv::Mat(affine.matrix, false).colRange(0, 3).rowRange(0, 3) != expected, cv::NORM_L2)); + ASSERT_EQ(0, cvtest::norm(cv::Mat(affine.linear()) != expected, cv::NORM_L2)); cv::Matx33d R = cv::Matx33d::eye(); @@ -77,7 +77,7 @@ TEST(Calib3d_Affine3f, accuracy) cv::Mat diff; cv::absdiff(expected, result.matrix, diff); - ASSERT_LT(cv::norm(diff, cv::NORM_INF), 1e-15); + ASSERT_LT(cvtest::norm(diff, cv::NORM_INF), 1e-15); } TEST(Calib3d_Affine3f, accuracy_rvec) @@ -103,6 +103,6 @@ TEST(Calib3d_Affine3f, accuracy_rvec) cv::Rodrigues(R, vo); //std::cout << "O:" <<(cv::getTickCount() - s)*1000/cv::getTickFrequency() << std::endl; - ASSERT_LT(cv::norm(va - vo), 1e-9); + ASSERT_LT(cvtest::norm(va, vo, cv::NORM_L2), 1e-9); } } diff --git a/modules/calib3d/test/test_affine3d_estimator.cpp b/modules/calib3d/test/test_affine3d_estimator.cpp index f31e2e7324..c677275c95 100644 --- a/modules/calib3d/test/test_affine3d_estimator.cpp +++ b/modules/calib3d/test/test_affine3d_estimator.cpp @@ -108,9 +108,9 @@ bool CV_Affine3D_EstTest::test4Points() estimateAffine3D(fpts, tpts, aff_est, outliers); const double thres = 1e-3; - if (norm(aff_est, aff, NORM_INF) > thres) + if (cvtest::norm(aff_est, aff, NORM_INF) > thres) { - //cout << norm(aff_est, aff, NORM_INF) << endl; + //cout << cvtest::norm(aff_est, aff, NORM_INF) << endl; ts->set_failed_test_info(cvtest::TS::FAIL_MISMATCH); return false; } @@ -161,7 +161,7 @@ bool CV_Affine3D_EstTest::testNPoints() } const double thres = 1e-4; - if (norm(aff_est, aff, NORM_INF) > thres) + if (cvtest::norm(aff_est, aff, NORM_INF) > thres) { cout << "aff est: " << aff_est << endl; cout << "aff ref: " << aff << endl; diff --git a/modules/calib3d/test/test_cameracalibration.cpp b/modules/calib3d/test/test_cameracalibration.cpp index 7d0bdaeb10..da9b931f53 100644 --- a/modules/calib3d/test/test_cameracalibration.cpp +++ b/modules/calib3d/test/test_cameracalibration.cpp @@ -215,7 +215,7 @@ void CV_ProjectPointsTest::prepare_to_validation( int /*test_case_idx*/ ) cvTsProjectPoints( m, vec2, m2v_jac ); cvTsCopy( vec, vec2 ); - theta0 = cvNorm( vec2, 0, CV_L2 ); + theta0 = cvtest::norm( cvarrtomat(vec2), 0, CV_L2 ); theta1 = fmod( theta0, CV_PI*2 ); if( theta1 > CV_PI ) @@ -225,7 +225,7 @@ void CV_ProjectPointsTest::prepare_to_validation( int /*test_case_idx*/ ) if( calc_jacobians ) { //cvInvert( v2m_jac, m2v_jac, CV_SVD ); - if( cvNorm(&test_mat[OUTPUT][3],0,CV_C) < 1000 ) + if( cvtest::norm(cvarrtomat(&test_mat[OUTPUT][3]), 0, CV_C) < 1000 ) { cvTsGEMM( &test_mat[OUTPUT][1], &test_mat[OUTPUT][3], 1, 0, 0, &test_mat[OUTPUT][4], @@ -1112,7 +1112,7 @@ void CV_ProjectPointsTest::run(int) rightImgPoints[i], valDpdrot, valDpdt, valDpdf, valDpdc, valDpddist, 0 ); } calcdfdx( leftImgPoints, rightImgPoints, dEps, valDpdrot ); - err = norm( dpdrot, valDpdrot, NORM_INF ); + err = cvtest::norm( dpdrot, valDpdrot, NORM_INF ); if( err > 3 ) { ts->printf( cvtest::TS::LOG, "bad dpdrot: too big difference = %g\n", err ); @@ -1130,7 +1130,7 @@ void CV_ProjectPointsTest::run(int) rightImgPoints[i], valDpdrot, valDpdt, valDpdf, valDpdc, valDpddist, 0 ); } calcdfdx( leftImgPoints, rightImgPoints, dEps, valDpdt ); - if( norm( dpdt, valDpdt, NORM_INF ) > 0.2 ) + if( cvtest::norm( dpdt, valDpdt, NORM_INF ) > 0.2 ) { ts->printf( cvtest::TS::LOG, "bad dpdtvec\n" ); code = cvtest::TS::FAIL_BAD_ACCURACY; @@ -1153,7 +1153,7 @@ void CV_ProjectPointsTest::run(int) project( objPoints, rvec, tvec, rightCameraMatrix, distCoeffs, rightImgPoints[1], valDpdrot, valDpdt, valDpdf, valDpdc, valDpddist, 0 ); calcdfdx( leftImgPoints, rightImgPoints, dEps, valDpdf ); - if ( norm( dpdf, valDpdf ) > 0.2 ) + if ( cvtest::norm( dpdf, valDpdf, NORM_L2 ) > 0.2 ) { ts->printf( cvtest::TS::LOG, "bad dpdf\n" ); code = cvtest::TS::FAIL_BAD_ACCURACY; @@ -1174,7 +1174,7 @@ void CV_ProjectPointsTest::run(int) project( objPoints, rvec, tvec, rightCameraMatrix, distCoeffs, rightImgPoints[1], valDpdrot, valDpdt, valDpdf, valDpdc, valDpddist, 0 ); calcdfdx( leftImgPoints, rightImgPoints, dEps, valDpdc ); - if ( norm( dpdc, valDpdc ) > 0.2 ) + if ( cvtest::norm( dpdc, valDpdc, NORM_L2 ) > 0.2 ) { ts->printf( cvtest::TS::LOG, "bad dpdc\n" ); code = cvtest::TS::FAIL_BAD_ACCURACY; @@ -1193,7 +1193,7 @@ void CV_ProjectPointsTest::run(int) rightImgPoints[i], valDpdrot, valDpdt, valDpdf, valDpdc, valDpddist, 0 ); } calcdfdx( leftImgPoints, rightImgPoints, dEps, valDpddist ); - if( norm( dpddist, valDpddist ) > 0.3 ) + if( cvtest::norm( dpddist, valDpddist, NORM_L2 ) > 0.3 ) { ts->printf( cvtest::TS::LOG, "bad dpddist\n" ); code = cvtest::TS::FAIL_BAD_ACCURACY; @@ -1481,8 +1481,8 @@ void CV_StereoCalibrationTest::run( int ) Mat eye33 = Mat::eye(3,3,CV_64F); Mat R1t = R1.t(), R2t = R2.t(); - if( norm(R1t*R1 - eye33) > 0.01 || - norm(R2t*R2 - eye33) > 0.01 || + if( cvtest::norm(R1t*R1 - eye33, NORM_L2) > 0.01 || + cvtest::norm(R2t*R2 - eye33, NORM_L2) > 0.01 || abs(determinant(F)) > 0.01) { ts->printf( cvtest::TS::LOG, "The computed (by rectify) R1 and R2 are not orthogonal," @@ -1505,7 +1505,7 @@ void CV_StereoCalibrationTest::run( int ) //check that Tx after rectification is equal to distance between cameras double tx = fabs(P2.at(0, 3) / P2.at(0, 0)); - if (fabs(tx - norm(T)) > 1e-5) + if (fabs(tx - cvtest::norm(T, NORM_L2)) > 1e-5) { ts->set_failed_test_info( cvtest::TS::FAIL_BAD_ACCURACY ); return; @@ -1556,7 +1556,7 @@ void CV_StereoCalibrationTest::run( int ) Mat reprojectedPoints; perspectiveTransform(sparsePoints, reprojectedPoints, Q); - if (norm(triangulatedPoints - reprojectedPoints) / sqrt((double)pointsCount) > requiredAccuracy) + if (cvtest::norm(triangulatedPoints, reprojectedPoints, NORM_L2) / sqrt((double)pointsCount) > requiredAccuracy) { ts->printf( cvtest::TS::LOG, "Points reprojected with a matrix Q and points reconstructed by triangulation are different, testcase %d\n", testcase); ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT ); @@ -1581,7 +1581,7 @@ void CV_StereoCalibrationTest::run( int ) { Mat error = newHomogeneousPoints2.row(i) * typedF * newHomogeneousPoints1.row(i).t(); CV_Assert(error.rows == 1 && error.cols == 1); - if (norm(error) > constraintAccuracy) + if (cvtest::norm(error, NORM_L2) > constraintAccuracy) { ts->printf( cvtest::TS::LOG, "Epipolar constraint is violated after correctMatches, testcase %d\n", testcase); ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT ); diff --git a/modules/calib3d/test/test_cameracalibration_artificial.cpp b/modules/calib3d/test/test_cameracalibration_artificial.cpp index 07e5894b96..94f70e7ccf 100644 --- a/modules/calib3d/test/test_cameracalibration_artificial.cpp +++ b/modules/calib3d/test/test_cameracalibration_artificial.cpp @@ -204,7 +204,7 @@ protected: Rodrigues(rvecs[i], rmat); Rodrigues(rvecs_est[i], rmat_est); - if (norm(rmat_est, rmat) > eps* (norm(rmat) + dlt)) + if (cvtest::norm(rmat_est, rmat, NORM_L2) > eps* (cvtest::norm(rmat, NORM_L2) + dlt)) { if (err_count++ < errMsgNum) { @@ -213,7 +213,8 @@ protected: else { ts->printf( cvtest::TS::LOG, "%d) Bad accuracy in returned rvecs (rotation matrs). Index = %d\n", r, i); - ts->printf( cvtest::TS::LOG, "%d) norm(rot_mat_est - rot_mat_exp) = %f, norm(rot_mat_exp) = %f \n", r, norm(rmat_est, rmat), norm(rmat)); + ts->printf( cvtest::TS::LOG, "%d) norm(rot_mat_est - rot_mat_exp) = %f, norm(rot_mat_exp) = %f \n", r, + cvtest::norm(rmat_est, rmat, NORM_L2), cvtest::norm(rmat, NORM_L2)); } } diff --git a/modules/calib3d/test/test_fundam.cpp b/modules/calib3d/test/test_fundam.cpp index 749faf1257..e2245c12b0 100644 --- a/modules/calib3d/test/test_fundam.cpp +++ b/modules/calib3d/test/test_fundam.cpp @@ -738,7 +738,7 @@ void CV_RodriguesTest::prepare_to_validation( int /*test_case_idx*/ ) if( calc_jacobians ) { //cvInvert( v2m_jac, m2v_jac, CV_SVD ); - double nrm = norm(test_mat[REF_OUTPUT][3],CV_C); + double nrm = cvtest::norm(test_mat[REF_OUTPUT][3], CV_C); if( FLT_EPSILON < nrm && nrm < 1000 ) { gemm( test_mat[OUTPUT][1], test_mat[OUTPUT][3], @@ -1409,8 +1409,8 @@ void CV_EssentialMatTest::prepare_to_validation( int test_case_idx ) double* pose_prop1 = (double*)test_mat[REF_OUTPUT][2].data; double* pose_prop2 = (double*)test_mat[OUTPUT][2].data; - double terr1 = norm(Rt0.col(3) / norm(Rt0.col(3)) + test_mat[TEMP][3]); - double terr2 = norm(Rt0.col(3) / norm(Rt0.col(3)) - test_mat[TEMP][3]); + double terr1 = cvtest::norm(Rt0.col(3) / norm(Rt0.col(3)) + test_mat[TEMP][3], NORM_L2); + double terr2 = cvtest::norm(Rt0.col(3) / norm(Rt0.col(3)) - test_mat[TEMP][3], NORM_L2); Mat rvec; Rodrigues(Rt0.colRange(0, 3), rvec); pose_prop1[0] = 0; diff --git a/modules/calib3d/test/test_homography.cpp b/modules/calib3d/test/test_homography.cpp index 5bb50bb265..59d92905a4 100644 --- a/modules/calib3d/test/test_homography.cpp +++ b/modules/calib3d/test/test_homography.cpp @@ -119,7 +119,7 @@ bool CV_HomographyTest::check_matrix_size(const cv::Mat& H) bool CV_HomographyTest::check_matrix_diff(const cv::Mat& original, const cv::Mat& found, const int norm_type, double &diff) { - diff = cv::norm(original, found, norm_type); + diff = cvtest::norm(original, found, norm_type); return diff <= max_diff; } diff --git a/modules/calib3d/test/test_solvepnp_ransac.cpp b/modules/calib3d/test/test_solvepnp_ransac.cpp index e6f25466d8..37e0959d16 100644 --- a/modules/calib3d/test/test_solvepnp_ransac.cpp +++ b/modules/calib3d/test/test_solvepnp_ransac.cpp @@ -299,8 +299,8 @@ TEST(DISABLED_Calib3d_SolvePnPRansac, concurrency) solvePnPRansac(object, image, camera_mat, dist_coef, rvec2, tvec2); } - double rnorm = cv::norm(rvec1, rvec2, NORM_INF); - double tnorm = cv::norm(tvec1, tvec2, NORM_INF); + double rnorm = cvtest::norm(rvec1, rvec2, NORM_INF); + double tnorm = cvtest::norm(tvec1, tvec2, NORM_INF); EXPECT_LT(rnorm, 1e-6); EXPECT_LT(tnorm, 1e-6); diff --git a/modules/calib3d/test/test_stereomatching.cpp b/modules/calib3d/test/test_stereomatching.cpp index 8beb9f905e..8c377de0c1 100644 --- a/modules/calib3d/test/test_stereomatching.cpp +++ b/modules/calib3d/test/test_stereomatching.cpp @@ -279,7 +279,7 @@ float dispRMS( const Mat& computedDisp, const Mat& groundTruthDisp, const Mat& m checkTypeAndSizeOfMask( mask, sz ); pointsCount = countNonZero(mask); } - return 1.f/sqrt((float)pointsCount) * (float)norm(computedDisp, groundTruthDisp, NORM_L2, mask); + return 1.f/sqrt((float)pointsCount) * (float)cvtest::norm(computedDisp, groundTruthDisp, NORM_L2, mask); } /* diff --git a/modules/calib3d/test/test_undistort_points.cpp b/modules/calib3d/test/test_undistort_points.cpp index 5dabd213db..0eb3552272 100644 --- a/modules/calib3d/test/test_undistort_points.cpp +++ b/modules/calib3d/test/test_undistort_points.cpp @@ -84,7 +84,7 @@ void CV_UndistortTest::run(int /* start_from */) Mat p; perspectiveTransform(undistortedPoints, p, intrinsics); undistortedPoints = p; - double diff = norm(Mat(realUndistortedPoints), undistortedPoints); + double diff = cvtest::norm(Mat(realUndistortedPoints), undistortedPoints, NORM_L2); if (diff > thresh) { ts->set_failed_test_info(cvtest::TS::FAIL_BAD_ACCURACY); diff --git a/modules/contrib/doc/facerec/facerec_api.rst b/modules/contrib/doc/facerec/facerec_api.rst index c2c7f56d0c..d8fdde63ec 100644 --- a/modules/contrib/doc/facerec/facerec_api.rst +++ b/modules/contrib/doc/facerec/facerec_api.rst @@ -75,7 +75,7 @@ Moreover every :ocv:class:`FaceRecognizer` supports the: Setting the Thresholds +++++++++++++++++++++++ -Sometimes you run into the situation, when you want to apply a threshold on the prediction. A common scenario in face recognition is to tell, wether a face belongs to the training dataset or if it is unknown. You might wonder, why there's no public API in :ocv:class:`FaceRecognizer` to set the threshold for the prediction, but rest assured: It's supported. It just means there's no generic way in an abstract class to provide an interface for setting/getting the thresholds of *every possible* :ocv:class:`FaceRecognizer` algorithm. The appropriate place to set the thresholds is in the constructor of the specific :ocv:class:`FaceRecognizer` and since every :ocv:class:`FaceRecognizer` is a :ocv:class:`Algorithm` (see above), you can get/set the thresholds at runtime! +Sometimes you run into the situation, when you want to apply a threshold on the prediction. A common scenario in face recognition is to tell, whether a face belongs to the training dataset or if it is unknown. You might wonder, why there's no public API in :ocv:class:`FaceRecognizer` to set the threshold for the prediction, but rest assured: It's supported. It just means there's no generic way in an abstract class to provide an interface for setting/getting the thresholds of *every possible* :ocv:class:`FaceRecognizer` algorithm. The appropriate place to set the thresholds is in the constructor of the specific :ocv:class:`FaceRecognizer` and since every :ocv:class:`FaceRecognizer` is a :ocv:class:`Algorithm` (see above), you can get/set the thresholds at runtime! Here is an example of setting a threshold for the Eigenfaces method, when creating the model: diff --git a/modules/contrib/doc/facerec/tutorial/facerec_gender_classification.rst b/modules/contrib/doc/facerec/tutorial/facerec_gender_classification.rst index 770083170d..95c821298e 100644 --- a/modules/contrib/doc/facerec/tutorial/facerec_gender_classification.rst +++ b/modules/contrib/doc/facerec/tutorial/facerec_gender_classification.rst @@ -71,7 +71,7 @@ You really don't want to create the CSV file by hand. And you really don't want Fisherfaces for Gender Classification -------------------------------------- -If you want to decide wether a person is *male* or *female*, you have to learn the discriminative features of both classes. The Eigenfaces method is based on the Principal Component Analysis, which is an unsupervised statistical model and not suitable for this task. Please see the Face Recognition tutorial for insights into the algorithms. The Fisherfaces instead yields a class-specific linear projection, so it is much better suited for the gender classification task. `http://www.bytefish.de/blog/gender_classification `_ shows the recognition rate of the Fisherfaces method for gender classification. +If you want to decide whether a person is *male* or *female*, you have to learn the discriminative features of both classes. The Eigenfaces method is based on the Principal Component Analysis, which is an unsupervised statistical model and not suitable for this task. Please see the Face Recognition tutorial for insights into the algorithms. The Fisherfaces instead yields a class-specific linear projection, so it is much better suited for the gender classification task. `http://www.bytefish.de/blog/gender_classification `_ shows the recognition rate of the Fisherfaces method for gender classification. The Fisherfaces method achieves a 98% recognition rate in a subject-independent cross-validation. A subject-independent cross-validation means *images of the person under test are never used for learning the model*. And could you believe it: you can simply use the facerec_fisherfaces demo, that's inlcuded in OpenCV. diff --git a/modules/core/doc/core.rst b/modules/core/doc/core.rst index 73bfc35367..669fddd46a 100644 --- a/modules/core/doc/core.rst +++ b/modules/core/doc/core.rst @@ -16,3 +16,4 @@ core. The Core Functionality clustering utility_and_system_functions_and_macros opengl_interop + ipp_async_converters diff --git a/modules/core/doc/ipp_async_converters.rst b/modules/core/doc/ipp_async_converters.rst new file mode 100644 index 0000000000..1be93d5584 --- /dev/null +++ b/modules/core/doc/ipp_async_converters.rst @@ -0,0 +1,72 @@ +Intel® IPP Asynchronous C/C++ Converters +======================================== + +.. highlight:: cpp + +General Information +------------------- + +This section describes conversion between OpenCV and `Intel® IPP Asynchronous C/C++ `_ library. +`Getting Started Guide `_ help you to install the library, configure header and library build paths. + +hpp::getHpp +----------- +Create ``hppiMatrix`` from ``Mat``. + +.. ocv:function:: hppiMatrix* hpp::getHpp(const Mat& src, hppAccel accel) + + :param src: input matrix. + :param accel: accelerator instance. Supports type: + + * **HPP_ACCEL_TYPE_CPU** - accelerated by optimized CPU instructions. + + * **HPP_ACCEL_TYPE_GPU** - accelerated by GPU programmable units or fixed-function accelerators. + + * **HPP_ACCEL_TYPE_ANY** - any acceleration or no acceleration available. + +This function allocates and initializes the ``hppiMatrix`` that has the same size and type as input matrix, returns the ``hppiMatrix*``. + +If you want to use zero-copy for GPU you should to have 4KB aligned matrix data. See details `hppiCreateSharedMatrix `_. + +Supports ``CV_8U``, ``CV_16U``, ``CV_16S``, ``CV_32S``, ``CV_32F``, ``CV_64F``. + +.. note:: The ``hppiMatrix`` pointer to the image buffer in system memory refers to the ``src.data``. Control the lifetime of the matrix and don't change its data, if there is no special need. +.. seealso:: :ref:`howToUseIPPAconversion`, :ocv:func:`hpp::getMat` + + +hpp::getMat +----------- +Create ``Mat`` from ``hppiMatrix``. + +.. ocv:function:: Mat hpp::getMat(hppiMatrix* src, hppAccel accel, int cn) + + :param src: input hppiMatrix. + + :param accel: accelerator instance (see :ocv:func:`hpp::getHpp` for the list of acceleration framework types). + + :param cn: number of channels. + +This function allocates and initializes the ``Mat`` that has the same size and type as input matrix. +Supports ``CV_8U``, ``CV_16U``, ``CV_16S``, ``CV_32S``, ``CV_32F``, ``CV_64F``. + +.. seealso:: :ref:`howToUseIPPAconversion`, :ocv:func:`hpp::copyHppToMat`, :ocv:func:`hpp::getHpp`. + + +hpp::copyHppToMat +----------------- +Convert ``hppiMatrix`` to ``Mat``. + +.. ocv:function:: void hpp::copyHppToMat(hppiMatrix* src, Mat& dst, hppAccel accel, int cn) + + :param src: input hppiMatrix. + + :param dst: output matrix. + + :param accel: accelerator instance (see :ocv:func:`hpp::getHpp` for the list of acceleration framework types). + + :param cn: number of channels. + +This function allocates and initializes new matrix (if needed) that has the same size and type as input matrix. +Supports ``CV_8U``, ``CV_16U``, ``CV_16S``, ``CV_32S``, ``CV_32F``, ``CV_64F``. + +.. seealso:: :ref:`howToUseIPPAconversion`, :ocv:func:`hpp::getMat`, :ocv:func:`hpp::getHpp`. \ No newline at end of file diff --git a/modules/core/include/opencv2/core/ippasync.hpp b/modules/core/include/opencv2/core/ippasync.hpp new file mode 100644 index 0000000000..e40a0aa2f1 --- /dev/null +++ b/modules/core/include/opencv2/core/ippasync.hpp @@ -0,0 +1,105 @@ +#ifndef __OPENCV_CORE_IPPASYNC_HPP__ +#define __OPENCV_CORE_IPPASYNC_HPP__ + +#ifdef HAVE_IPP_A + +#include "opencv2/core.hpp" +#include +#include + +namespace cv +{ + +namespace hpp +{ + //convert OpenCV data type to hppDataType + inline int toHppType(const int cvType) + { + int depth = CV_MAT_DEPTH(cvType); + int hppType = depth == CV_8U ? HPP_DATA_TYPE_8U : + depth == CV_16U ? HPP_DATA_TYPE_16U : + depth == CV_16S ? HPP_DATA_TYPE_16S : + depth == CV_32S ? HPP_DATA_TYPE_32S : + depth == CV_32F ? HPP_DATA_TYPE_32F : + depth == CV_64F ? HPP_DATA_TYPE_64F : -1; + CV_Assert( hppType >= 0 ); + return hppType; + } + + //convert hppDataType to OpenCV data type + inline int toCvType(const int hppType) + { + int cvType = hppType == HPP_DATA_TYPE_8U ? CV_8U : + hppType == HPP_DATA_TYPE_16U ? CV_16U : + hppType == HPP_DATA_TYPE_16S ? CV_16S : + hppType == HPP_DATA_TYPE_32S ? CV_32S : + hppType == HPP_DATA_TYPE_32F ? CV_32F : + hppType == HPP_DATA_TYPE_64F ? CV_64F : -1; + CV_Assert( cvType >= 0 ); + return cvType; + } + + inline void copyHppToMat(hppiMatrix* src, Mat& dst, hppAccel accel, int cn) + { + hppDataType type; + hpp32u width, height; + hppStatus sts; + + if (src == NULL) + return dst.release(); + + sts = hppiInquireMatrix(src, &type, &width, &height); + + CV_Assert( sts == HPP_STATUS_NO_ERROR); + + int matType = CV_MAKETYPE(toCvType(type), cn); + + CV_Assert(width%cn == 0); + + width /= cn; + + dst.create((int)height, (int)width, (int)matType); + + size_t newSize = (size_t)(height*(hpp32u)(dst.step)); + + sts = hppiGetMatrixData(accel,src,(hpp32u)(dst.step),dst.data,&newSize); + + CV_Assert( sts == HPP_STATUS_NO_ERROR); + } + + //create cv::Mat from hppiMatrix + inline Mat getMat(hppiMatrix* src, hppAccel accel, int cn) + { + Mat dst; + copyHppToMat(src, dst, accel, cn); + return dst; + } + + //create hppiMatrix from cv::Mat + inline hppiMatrix* getHpp(const Mat& src, hppAccel accel) + { + int htype = toHppType(src.type()); + int cn = src.channels(); + + CV_Assert(src.data); + hppAccelType accelType = hppQueryAccelType(accel); + + if (accelType!=HPP_ACCEL_TYPE_CPU) + { + hpp32u pitch, size; + hppQueryMatrixAllocParams(accel, src.cols*cn, src.rows, htype, &pitch, &size); + if (pitch!=0 && size!=0) + if ((int)(src.data)%4096==0 && pitch==(hpp32u)(src.step)) + { + return hppiCreateSharedMatrix(htype, src.cols*cn, src.rows, src.data, pitch, size); + } + } + + return hppiCreateMatrix(htype, src.cols*cn, src.rows, src.data, (hpp32s)(src.step));; + } + +}} + +#endif + +#endif \ No newline at end of file diff --git a/modules/core/include/opencv2/core/private.hpp b/modules/core/include/opencv2/core/private.hpp index a1cc0e5c89..45351d1a86 100644 --- a/modules/core/include/opencv2/core/private.hpp +++ b/modules/core/include/opencv2/core/private.hpp @@ -210,13 +210,21 @@ CV_EXPORTS void scalarToRawData(const cv::Scalar& s, void* buf, int type, int un \****************************************************************************************/ #ifdef HAVE_IPP -# include "ipp.h" +# ifdef HAVE_IPP_ICV_ONLY +# include "ippicv.h" +# include "ippicv_fn_map.h" +# else +# include "ipp.h" +# endif +# define IPP_VERSION_X100 (IPP_VERSION_MAJOR * 100 + IPP_VERSION_MINOR) static inline IppiSize ippiSize(int width, int height) { IppiSize size = { width, height }; return size; } +#else +# define IPP_VERSION_X100 0 #endif #ifndef IPPI_CALL diff --git a/modules/core/perf/perf_dft.cpp b/modules/core/perf/perf_dft.cpp index 05ae4bc509..a33bcf51e1 100644 --- a/modules/core/perf/perf_dft.cpp +++ b/modules/core/perf/perf_dft.cpp @@ -22,5 +22,5 @@ PERF_TEST_P(Size_MatType, dft, TEST_MATS_DFT) TEST_CYCLE() dft(src, dst); - SANITY_CHECK(dst, 1e-5); + SANITY_CHECK(dst, 1e-5, ERROR_RELATIVE); } diff --git a/modules/core/perf/perf_stat.cpp b/modules/core/perf/perf_stat.cpp index 6b5f0ff524..25bad4f527 100644 --- a/modules/core/perf/perf_stat.cpp +++ b/modules/core/perf/perf_stat.cpp @@ -65,8 +65,8 @@ PERF_TEST_P(Size_MatType, meanStdDev, TYPICAL_MATS) TEST_CYCLE() meanStdDev(src, mean, dev); - SANITY_CHECK(mean, 1e-6); - SANITY_CHECK(dev, 1e-6); + SANITY_CHECK(mean, 1e-5, ERROR_RELATIVE); + SANITY_CHECK(dev, 1e-5, ERROR_RELATIVE); } PERF_TEST_P(Size_MatType, meanStdDev_mask, TYPICAL_MATS) diff --git a/modules/core/src/arithm.cpp b/modules/core/src/arithm.cpp index 58442e559b..ecc2ca0648 100644 --- a/modules/core/src/arithm.cpp +++ b/modules/core/src/arithm.cpp @@ -52,18 +52,6 @@ namespace cv { -#if ARITHM_USE_IPP -struct IPPArithmInitializer -{ - IPPArithmInitializer(void) - { - ippStaticInit(); - } -}; - -IPPArithmInitializer ippArithmInitializer; -#endif - struct NOP {}; #if CV_SSE2 @@ -470,9 +458,12 @@ static void add8u( const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, Size sz, void* ) { - IF_IPP(fixSteps(sz, sizeof(dst[0]), step1, step2, step); - ippiAdd_8u_C1RSfs(src1, (int)step1, src2, (int)step2, dst, (int)step, (IppiSize&)sz, 0), - (vBinOp, IF_SIMD(VAdd)>(src1, step1, src2, step2, dst, step, sz))); +#if (ARITHM_USE_IPP == 1) + fixSteps(sz, sizeof(dst[0]), step1, step2, step); + if (0 <= ippiAdd_8u_C1RSfs(src1, (int)step1, src2, (int)step2, dst, (int)step, (IppiSize&)sz, 0)) + return; +#endif + (vBinOp, IF_SIMD(VAdd)>(src1, step1, src2, step2, dst, step, sz)); } static void add8s( const schar* src1, size_t step1, @@ -486,18 +477,24 @@ static void add16u( const ushort* src1, size_t step1, const ushort* src2, size_t step2, ushort* dst, size_t step, Size sz, void* ) { - IF_IPP(fixSteps(sz, sizeof(dst[0]), step1, step2, step); - ippiAdd_16u_C1RSfs(src1, (int)step1, src2, (int)step2, dst, (int)step, (IppiSize&)sz, 0), - (vBinOp, IF_SIMD(VAdd)>(src1, step1, src2, step2, dst, step, sz))); +#if (ARITHM_USE_IPP == 1) + fixSteps(sz, sizeof(dst[0]), step1, step2, step); + if (0 <= ippiAdd_16u_C1RSfs(src1, (int)step1, src2, (int)step2, dst, (int)step, (IppiSize&)sz, 0)) + return; +#endif + (vBinOp, IF_SIMD(VAdd)>(src1, step1, src2, step2, dst, step, sz)); } static void add16s( const short* src1, size_t step1, const short* src2, size_t step2, short* dst, size_t step, Size sz, void* ) { - IF_IPP(fixSteps(sz, sizeof(dst[0]), step1, step2, step); - ippiAdd_16s_C1RSfs(src1, (int)step1, src2, (int)step2, dst, (int)step, (IppiSize&)sz, 0), - (vBinOp, IF_SIMD(VAdd)>(src1, step1, src2, step2, dst, step, sz))); +#if (ARITHM_USE_IPP == 1) + fixSteps(sz, sizeof(dst[0]), step1, step2, step); + if (0 <= ippiAdd_16s_C1RSfs(src1, (int)step1, src2, (int)step2, dst, (int)step, (IppiSize&)sz, 0)) + return; +#endif + (vBinOp, IF_SIMD(VAdd)>(src1, step1, src2, step2, dst, step, sz)); } static void add32s( const int* src1, size_t step1, @@ -511,9 +508,12 @@ static void add32f( const float* src1, size_t step1, const float* src2, size_t step2, float* dst, size_t step, Size sz, void* ) { - IF_IPP(fixSteps(sz, sizeof(dst[0]), step1, step2, step); - ippiAdd_32f_C1R(src1, (int)step1, src2, (int)step2, dst, (int)step, (IppiSize&)sz), - (vBinOp32, IF_SIMD(VAdd)>(src1, step1, src2, step2, dst, step, sz))); +#if (ARITHM_USE_IPP == 1) + fixSteps(sz, sizeof(dst[0]), step1, step2, step); + if (0 <= ippiAdd_32f_C1R(src1, (int)step1, src2, (int)step2, dst, (int)step, (IppiSize&)sz)) + return; +#endif + (vBinOp32, IF_SIMD(VAdd)>(src1, step1, src2, step2, dst, step, sz)); } static void add64f( const double* src1, size_t step1, @@ -527,9 +527,12 @@ static void sub8u( const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, Size sz, void* ) { - IF_IPP(fixSteps(sz, sizeof(dst[0]), step1, step2, step); - ippiSub_8u_C1RSfs(src2, (int)step2, src1, (int)step1, dst, (int)step, (IppiSize&)sz, 0), - (vBinOp, IF_SIMD(VSub)>(src1, step1, src2, step2, dst, step, sz))); +#if (ARITHM_USE_IPP == 1) + fixSteps(sz, sizeof(dst[0]), step1, step2, step); + if (0 <= ippiSub_8u_C1RSfs(src2, (int)step2, src1, (int)step1, dst, (int)step, (IppiSize&)sz, 0)) + return; +#endif + (vBinOp, IF_SIMD(VSub)>(src1, step1, src2, step2, dst, step, sz)); } static void sub8s( const schar* src1, size_t step1, @@ -543,18 +546,24 @@ static void sub16u( const ushort* src1, size_t step1, const ushort* src2, size_t step2, ushort* dst, size_t step, Size sz, void* ) { - IF_IPP(fixSteps(sz, sizeof(dst[0]), step1, step2, step); - ippiSub_16u_C1RSfs(src2, (int)step2, src1, (int)step1, dst, (int)step, (IppiSize&)sz, 0), - (vBinOp, IF_SIMD(VSub)>(src1, step1, src2, step2, dst, step, sz))); +#if (ARITHM_USE_IPP == 1) + fixSteps(sz, sizeof(dst[0]), step1, step2, step); + if (0 <= ippiSub_16u_C1RSfs(src2, (int)step2, src1, (int)step1, dst, (int)step, (IppiSize&)sz, 0)) + return; +#endif + (vBinOp, IF_SIMD(VSub)>(src1, step1, src2, step2, dst, step, sz)); } static void sub16s( const short* src1, size_t step1, const short* src2, size_t step2, short* dst, size_t step, Size sz, void* ) { - IF_IPP(fixSteps(sz, sizeof(dst[0]), step1, step2, step); - ippiSub_16s_C1RSfs(src2, (int)step2, src1, (int)step1, dst, (int)step, (IppiSize&)sz, 0), - (vBinOp, IF_SIMD(VSub)>(src1, step1, src2, step2, dst, step, sz))); +#if (ARITHM_USE_IPP == 1) + fixSteps(sz, sizeof(dst[0]), step1, step2, step); + if (0 <= ippiSub_16s_C1RSfs(src2, (int)step2, src1, (int)step1, dst, (int)step, (IppiSize&)sz, 0)) + return; +#endif + (vBinOp, IF_SIMD(VSub)>(src1, step1, src2, step2, dst, step, sz)); } static void sub32s( const int* src1, size_t step1, @@ -568,9 +577,12 @@ static void sub32f( const float* src1, size_t step1, const float* src2, size_t step2, float* dst, size_t step, Size sz, void* ) { - IF_IPP(fixSteps(sz, sizeof(dst[0]), step1, step2, step); - ippiSub_32f_C1R(src2, (int)step2, src1, (int)step1, dst, (int)step, (IppiSize&)sz), - (vBinOp32, IF_SIMD(VSub)>(src1, step1, src2, step2, dst, step, sz))); +#if (ARITHM_USE_IPP == 1) + fixSteps(sz, sizeof(dst[0]), step1, step2, step); + if (0 <= ippiSub_32f_C1R(src2, (int)step2, src1, (int)step1, dst, (int)step, (IppiSize&)sz)) + return; +#endif + (vBinOp32, IF_SIMD(VSub)>(src1, step1, src2, step2, dst, step, sz)); } static void sub64f( const double* src1, size_t step1, @@ -588,26 +600,23 @@ static void max8u( const uchar* src1, size_t step1, uchar* dst, size_t step, Size sz, void* ) { #if (ARITHM_USE_IPP == 1) - { uchar* s1 = (uchar*)src1; uchar* s2 = (uchar*)src2; uchar* d = dst; fixSteps(sz, sizeof(dst[0]), step1, step2, step); - for(int i = 0; i < sz.height; i++) + int i = 0; + for(; i < sz.height; i++) { - ippsMaxEvery_8u(s1, s2, d, sz.width); - s1 += step1; - s2 += step2; - d += step; + if (0 > ippsMaxEvery_8u(s1, s2, d, sz.width)) + break; + s1 += step1; + s2 += step2; + d += step; } - } -#else - vBinOp, IF_SIMD(VMax)>(src1, step1, src2, step2, dst, step, sz); + if (i == sz.height) + return; #endif - -// IF_IPP(fixSteps(sz, sizeof(dst[0]), step1, step2, step); -// ippiMaxEvery_8u_C1R(src1, (int)step1, src2, (int)step2, dst, (IppiSize&)sz), -// (vBinOp8, IF_SIMD(_VMax8u)>(src1, step1, src2, step2, dst, step, sz))); + vBinOp, IF_SIMD(VMax)>(src1, step1, src2, step2, dst, step, sz); } static void max8s( const schar* src1, size_t step1, @@ -622,26 +631,23 @@ static void max16u( const ushort* src1, size_t step1, ushort* dst, size_t step, Size sz, void* ) { #if (ARITHM_USE_IPP == 1) - { ushort* s1 = (ushort*)src1; ushort* s2 = (ushort*)src2; ushort* d = dst; fixSteps(sz, sizeof(dst[0]), step1, step2, step); - for(int i = 0; i < sz.height; i++) + int i = 0; + for(; i < sz.height; i++) { - ippsMaxEvery_16u(s1, s2, d, sz.width); - s1 = (ushort*)((uchar*)s1 + step1); - s2 = (ushort*)((uchar*)s2 + step2); - d = (ushort*)((uchar*)d + step); + if (0 > ippsMaxEvery_16u(s1, s2, d, sz.width)) + break; + s1 = (ushort*)((uchar*)s1 + step1); + s2 = (ushort*)((uchar*)s2 + step2); + d = (ushort*)((uchar*)d + step); } - } -#else - vBinOp, IF_SIMD(VMax)>(src1, step1, src2, step2, dst, step, sz); + if (i == sz.height) + return; #endif - -// IF_IPP(fixSteps(sz, sizeof(dst[0]), step1, step2, step); -// ippiMaxEvery_16u_C1R(src1, (int)step1, src2, (int)step2, dst, (IppiSize&)sz), -// (vBinOp16, IF_SIMD(_VMax16u)>(src1, step1, src2, step2, dst, step, sz))); + vBinOp, IF_SIMD(VMax)>(src1, step1, src2, step2, dst, step, sz); } static void max16s( const short* src1, size_t step1, @@ -663,25 +669,23 @@ static void max32f( const float* src1, size_t step1, float* dst, size_t step, Size sz, void* ) { #if (ARITHM_USE_IPP == 1) - { float* s1 = (float*)src1; float* s2 = (float*)src2; float* d = dst; fixSteps(sz, sizeof(dst[0]), step1, step2, step); - for(int i = 0; i < sz.height; i++) + int i = 0; + for(; i < sz.height; i++) { - ippsMaxEvery_32f(s1, s2, d, sz.width); - s1 = (float*)((uchar*)s1 + step1); - s2 = (float*)((uchar*)s2 + step2); - d = (float*)((uchar*)d + step); + if (0 > ippsMaxEvery_32f(s1, s2, d, sz.width)) + break; + s1 = (float*)((uchar*)s1 + step1); + s2 = (float*)((uchar*)s2 + step2); + d = (float*)((uchar*)d + step); } - } -#else - vBinOp32, IF_SIMD(VMax)>(src1, step1, src2, step2, dst, step, sz); + if (i == sz.height) + return; #endif -// IF_IPP(fixSteps(sz, sizeof(dst[0]), step1, step2, step); -// ippiMaxEvery_32f_C1R(src1, (int)step1, src2, (int)step2, dst, (IppiSize&)sz), -// (vBinOp32f, IF_SIMD(_VMax32f)>(src1, step1, src2, step2, dst, step, sz))); + vBinOp32, IF_SIMD(VMax)>(src1, step1, src2, step2, dst, step, sz); } static void max64f( const double* src1, size_t step1, @@ -696,26 +700,23 @@ static void min8u( const uchar* src1, size_t step1, uchar* dst, size_t step, Size sz, void* ) { #if (ARITHM_USE_IPP == 1) - { uchar* s1 = (uchar*)src1; uchar* s2 = (uchar*)src2; uchar* d = dst; fixSteps(sz, sizeof(dst[0]), step1, step2, step); - for(int i = 0; i < sz.height; i++) + int i = 0; + for(; i < sz.height; i++) { - ippsMinEvery_8u(s1, s2, d, sz.width); - s1 += step1; - s2 += step2; - d += step; + if (0 > ippsMinEvery_8u(s1, s2, d, sz.width)) + break; + s1 += step1; + s2 += step2; + d += step; } - } -#else - vBinOp, IF_SIMD(VMin)>(src1, step1, src2, step2, dst, step, sz); + if (i == sz.height) + return; #endif - -// IF_IPP(fixSteps(sz, sizeof(dst[0]), step1, step2, step); -// ippiMinEvery_8u_C1R(src1, (int)step1, src2, (int)step2, dst, (IppiSize&)sz), -// (vBinOp8, IF_SIMD(_VMin8u)>(src1, step1, src2, step2, dst, step, sz))); + vBinOp, IF_SIMD(VMin)>(src1, step1, src2, step2, dst, step, sz); } static void min8s( const schar* src1, size_t step1, @@ -730,26 +731,23 @@ static void min16u( const ushort* src1, size_t step1, ushort* dst, size_t step, Size sz, void* ) { #if (ARITHM_USE_IPP == 1) - { ushort* s1 = (ushort*)src1; ushort* s2 = (ushort*)src2; ushort* d = dst; fixSteps(sz, sizeof(dst[0]), step1, step2, step); - for(int i = 0; i < sz.height; i++) + int i = 0; + for(; i < sz.height; i++) { - ippsMinEvery_16u(s1, s2, d, sz.width); - s1 = (ushort*)((uchar*)s1 + step1); - s2 = (ushort*)((uchar*)s2 + step2); - d = (ushort*)((uchar*)d + step); + if (0 > ippsMinEvery_16u(s1, s2, d, sz.width)) + break; + s1 = (ushort*)((uchar*)s1 + step1); + s2 = (ushort*)((uchar*)s2 + step2); + d = (ushort*)((uchar*)d + step); } - } -#else - vBinOp, IF_SIMD(VMin)>(src1, step1, src2, step2, dst, step, sz); + if (i == sz.height) + return; #endif - -// IF_IPP(fixSteps(sz, sizeof(dst[0]), step1, step2, step); -// ippiMinEvery_16u_C1R(src1, (int)step1, src2, (int)step2, dst, (IppiSize&)sz), -// (vBinOp16, IF_SIMD(_VMin16u)>(src1, step1, src2, step2, dst, step, sz))); + vBinOp, IF_SIMD(VMin)>(src1, step1, src2, step2, dst, step, sz); } static void min16s( const short* src1, size_t step1, @@ -771,25 +769,23 @@ static void min32f( const float* src1, size_t step1, float* dst, size_t step, Size sz, void* ) { #if (ARITHM_USE_IPP == 1) - { float* s1 = (float*)src1; float* s2 = (float*)src2; float* d = dst; fixSteps(sz, sizeof(dst[0]), step1, step2, step); - for(int i = 0; i < sz.height; i++) + int i = 0; + for(; i < sz.height; i++) { - ippsMinEvery_32f(s1, s2, d, sz.width); - s1 = (float*)((uchar*)s1 + step1); - s2 = (float*)((uchar*)s2 + step2); - d = (float*)((uchar*)d + step); + if (0 > ippsMinEvery_32f(s1, s2, d, sz.width)) + break; + s1 = (float*)((uchar*)s1 + step1); + s2 = (float*)((uchar*)s2 + step2); + d = (float*)((uchar*)d + step); } - } -#else - vBinOp32, IF_SIMD(VMin)>(src1, step1, src2, step2, dst, step, sz); + if (i == sz.height) + return; #endif -// IF_IPP(fixSteps(sz, sizeof(dst[0]), step1, step2, step); -// ippiMinEvery_32f_C1R(src1, (int)step1, src2, (int)step2, dst, (IppiSize&)sz), -// (vBinOp32f, IF_SIMD(_VMin32f)>(src1, step1, src2, step2, dst, step, sz))); + vBinOp32, IF_SIMD(VMin)>(src1, step1, src2, step2, dst, step, sz); } static void min64f( const double* src1, size_t step1, @@ -803,9 +799,12 @@ static void absdiff8u( const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, Size sz, void* ) { - IF_IPP(fixSteps(sz, sizeof(dst[0]), step1, step2, step); - ippiAbsDiff_8u_C1R(src1, (int)step1, src2, (int)step2, dst, (int)step, (IppiSize&)sz), - (vBinOp, IF_SIMD(VAbsDiff)>(src1, step1, src2, step2, dst, step, sz))); +#if (ARITHM_USE_IPP == 1) + fixSteps(sz, sizeof(dst[0]), step1, step2, step); + if (0 <= ippiAbsDiff_8u_C1R(src1, (int)step1, src2, (int)step2, dst, (int)step, (IppiSize&)sz)) + return; +#endif + (vBinOp, IF_SIMD(VAbsDiff)>(src1, step1, src2, step2, dst, step, sz)); } static void absdiff8s( const schar* src1, size_t step1, @@ -819,9 +818,12 @@ static void absdiff16u( const ushort* src1, size_t step1, const ushort* src2, size_t step2, ushort* dst, size_t step, Size sz, void* ) { - IF_IPP(fixSteps(sz, sizeof(dst[0]), step1, step2, step); - ippiAbsDiff_16u_C1R(src1, (int)step1, src2, (int)step2, dst, (int)step, (IppiSize&)sz), - (vBinOp, IF_SIMD(VAbsDiff)>(src1, step1, src2, step2, dst, step, sz))); +#if (ARITHM_USE_IPP == 1) + fixSteps(sz, sizeof(dst[0]), step1, step2, step); + if (0 <= ippiAbsDiff_16u_C1R(src1, (int)step1, src2, (int)step2, dst, (int)step, (IppiSize&)sz)) + return; +#endif + (vBinOp, IF_SIMD(VAbsDiff)>(src1, step1, src2, step2, dst, step, sz)); } static void absdiff16s( const short* src1, size_t step1, @@ -842,9 +844,12 @@ static void absdiff32f( const float* src1, size_t step1, const float* src2, size_t step2, float* dst, size_t step, Size sz, void* ) { - IF_IPP(fixSteps(sz, sizeof(dst[0]), step1, step2, step); - ippiAbsDiff_32f_C1R(src1, (int)step1, src2, (int)step2, dst, (int)step, (IppiSize&)sz), - (vBinOp32, IF_SIMD(VAbsDiff)>(src1, step1, src2, step2, dst, step, sz))); +#if (ARITHM_USE_IPP == 1) + fixSteps(sz, sizeof(dst[0]), step1, step2, step); + if (0 <= ippiAbsDiff_32f_C1R(src1, (int)step1, src2, (int)step2, dst, (int)step, (IppiSize&)sz)) + return; +#endif + (vBinOp32, IF_SIMD(VAbsDiff)>(src1, step1, src2, step2, dst, step, sz)); } static void absdiff64f( const double* src1, size_t step1, @@ -859,36 +864,48 @@ static void and8u( const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, Size sz, void* ) { - IF_IPP(fixSteps(sz, sizeof(dst[0]), step1, step2, step); - ippiAnd_8u_C1R(src1, (int)step1, src2, (int)step2, dst, (int)step, (IppiSize&)sz), - (vBinOp, IF_SIMD(VAnd)>(src1, step1, src2, step2, dst, step, sz))); +#if (ARITHM_USE_IPP == 1) + fixSteps(sz, sizeof(dst[0]), step1, step2, step); + if (0 <= ippiAnd_8u_C1R(src1, (int)step1, src2, (int)step2, dst, (int)step, (IppiSize&)sz)) + return; +#endif + (vBinOp, IF_SIMD(VAnd)>(src1, step1, src2, step2, dst, step, sz)); } static void or8u( const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, Size sz, void* ) { - IF_IPP(fixSteps(sz, sizeof(dst[0]), step1, step2, step); - ippiOr_8u_C1R(src1, (int)step1, src2, (int)step2, dst, (int)step, (IppiSize&)sz), - (vBinOp, IF_SIMD(VOr)>(src1, step1, src2, step2, dst, step, sz))); +#if (ARITHM_USE_IPP == 1) + fixSteps(sz, sizeof(dst[0]), step1, step2, step); + if (0 <= ippiOr_8u_C1R(src1, (int)step1, src2, (int)step2, dst, (int)step, (IppiSize&)sz)) + return; +#endif + (vBinOp, IF_SIMD(VOr)>(src1, step1, src2, step2, dst, step, sz)); } static void xor8u( const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, Size sz, void* ) { - IF_IPP(fixSteps(sz, sizeof(dst[0]), step1, step2, step); - ippiXor_8u_C1R(src1, (int)step1, src2, (int)step2, dst, (int)step, (IppiSize&)sz), - (vBinOp, IF_SIMD(VXor)>(src1, step1, src2, step2, dst, step, sz))); +#if (ARITHM_USE_IPP == 1) + fixSteps(sz, sizeof(dst[0]), step1, step2, step); + if (0 <= ippiXor_8u_C1R(src1, (int)step1, src2, (int)step2, dst, (int)step, (IppiSize&)sz)) + return; +#endif + (vBinOp, IF_SIMD(VXor)>(src1, step1, src2, step2, dst, step, sz)); } static void not8u( const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, Size sz, void* ) { - IF_IPP(fixSteps(sz, sizeof(dst[0]), step1, step2, step); (void *)src2; - ippiNot_8u_C1R(src1, (int)step1, dst, (int)step, (IppiSize&)sz), - (vBinOp, IF_SIMD(VNot)>(src1, step1, src2, step2, dst, step, sz))); +#if (ARITHM_USE_IPP == 1) + fixSteps(sz, sizeof(dst[0]), step1, step2, step); (void *)src2; + if (0 <= ippiNot_8u_C1R(src1, (int)step1, dst, (int)step, (IppiSize&)sz)) + return; +#endif + (vBinOp, IF_SIMD(VNot)>(src1, step1, src2, step2, dst, step, sz)); } /****************************************************************************************\ @@ -2369,7 +2386,7 @@ static void cmp8u(const uchar* src1, size_t step1, const uchar* src2, size_t ste if( op >= 0 ) { fixSteps(size, sizeof(dst[0]), step1, step2, step); - if( ippiCompare_8u_C1R(src1, (int)step1, src2, (int)step2, dst, (int)step, (IppiSize&)size, op) >= 0 ) + if (0 <= ippiCompare_8u_C1R(src1, (int)step1, src2, (int)step2, dst, (int)step, (IppiSize&)size, op)) return; } #endif @@ -2452,7 +2469,7 @@ static void cmp16u(const ushort* src1, size_t step1, const ushort* src2, size_t if( op >= 0 ) { fixSteps(size, sizeof(dst[0]), step1, step2, step); - if( ippiCompare_16u_C1R(src1, (int)step1, src2, (int)step2, dst, (int)step, (IppiSize&)size, op) >= 0 ) + if (0 <= ippiCompare_16u_C1R(src1, (int)step1, src2, (int)step2, dst, (int)step, (IppiSize&)size, op)) return; } #endif @@ -2467,7 +2484,7 @@ static void cmp16s(const short* src1, size_t step1, const short* src2, size_t st if( op > 0 ) { fixSteps(size, sizeof(dst[0]), step1, step2, step); - if( ippiCompare_16s_C1R(src1, (int)step1, src2, (int)step2, dst, (int)step, (IppiSize&)size, op) >= 0 ) + if (0 <= ippiCompare_16s_C1R(src1, (int)step1, src2, (int)step2, dst, (int)step, (IppiSize&)size, op)) return; } #endif @@ -2573,7 +2590,7 @@ static void cmp32f(const float* src1, size_t step1, const float* src2, size_t st if( op >= 0 ) { fixSteps(size, sizeof(dst[0]), step1, step2, step); - if( ippiCompare_32f_C1R(src1, (int)step1, src2, (int)step2, dst, (int)step, (IppiSize&)size, op) >= 0 ) + if (0 <= ippiCompare_32f_C1R(src1, (int)step1, src2, (int)step2, dst, (int)step, (IppiSize&)size, op)) return; } #endif diff --git a/modules/core/src/dxt.cpp b/modules/core/src/dxt.cpp index 4cdb6a16d2..c5a44e7ef6 100644 --- a/modules/core/src/dxt.cpp +++ b/modules/core/src/dxt.cpp @@ -53,7 +53,7 @@ namespace cv # pragma warning(disable: 4748) #endif -#if defined HAVE_IPP && IPP_VERSION_MAJOR*100 + IPP_VERSION_MINOR >= 701 +#if IPP_VERSION_X100 >= 701 #define USE_IPP_DFT 1 #else #undef USE_IPP_DFT diff --git a/modules/core/src/mathfuncs.cpp b/modules/core/src/mathfuncs.cpp index 16df02cafa..12ba4fa5b1 100644 --- a/modules/core/src/mathfuncs.cpp +++ b/modules/core/src/mathfuncs.cpp @@ -812,8 +812,6 @@ typedef union } DBLINT; -#ifndef HAVE_IPP - #define EXPTAB_SCALE 6 #define EXPTAB_MASK ((1 << EXPTAB_SCALE) - 1) @@ -1275,13 +1273,26 @@ static void Exp_64f( const double *_x, double *y, int n ) #undef EXPTAB_MASK #undef EXPPOLY_32F_A0 -#else +#ifdef HAVE_IPP +static void Exp_32f_ipp(const float *x, float *y, int n) +{ + if (0 <= ippsExp_32f_A21(x, y, n)) + return; + Exp_32f(x, y, n); +} -#define Exp_32f ippsExp_32f_A21 -#define Exp_64f ippsExp_64f_A50 +static void Exp_64f_ipp(const double *x, double *y, int n) +{ + if (0 <= ippsExp_64f_A50(x, y, n)) + return; + Exp_64f(x, y, n); +} +#define Exp_32f Exp_32f_ipp +#define Exp_64f Exp_64f_ipp #endif + void exp( InputArray _src, OutputArray _dst ) { int type = _src.type(), depth = _src.depth(), cn = _src.channels(); @@ -1302,9 +1313,9 @@ void exp( InputArray _src, OutputArray _dst ) for( size_t i = 0; i < it.nplanes; i++, ++it ) { if( depth == CV_32F ) - Exp_32f( (const float*)ptrs[0], (float*)ptrs[1], len ); + Exp_32f((const float*)ptrs[0], (float*)ptrs[1], len); else - Exp_64f( (const double*)ptrs[0], (double*)ptrs[1], len ); + Exp_64f((const double*)ptrs[0], (double*)ptrs[1], len); } } @@ -1313,8 +1324,6 @@ void exp( InputArray _src, OutputArray _dst ) * L O G * \****************************************************************************************/ -#ifndef HAVE_IPP - #define LOGTAB_SCALE 8 #define LOGTAB_MASK ((1 << LOGTAB_SCALE) - 1) #define LOGTAB_MASK2 ((1 << (20 - LOGTAB_SCALE)) - 1) @@ -1922,11 +1931,23 @@ static void Log_64f( const double *x, double *y, int n ) } } -#else +#ifdef HAVE_IPP +static void Log_32f_ipp(const float *x, float *y, int n) +{ + if (0 <= ippsLn_32f_A21(x, y, n)) + return; + Log_32f(x, y, n); +} -#define Log_32f ippsLn_32f_A21 -#define Log_64f ippsLn_64f_A50 +static void Log_64f_ipp(const double *x, double *y, int n) +{ + if (0 <= ippsLn_64f_A50(x, y, n)) + return; + Log_64f(x, y, n); +} +#define Log_32f Log_32f_ipp +#define Log_64f Log_64f_ipp #endif void log( InputArray _src, OutputArray _dst ) diff --git a/modules/core/src/matmul.cpp b/modules/core/src/matmul.cpp index daad86a0f1..8891bb05f8 100644 --- a/modules/core/src/matmul.cpp +++ b/modules/core/src/matmul.cpp @@ -44,10 +44,6 @@ #include "opencl_kernels.hpp" #include "opencv2/core/opencl/runtime/opencl_clamdblas.hpp" -#ifdef HAVE_IPP -#include "ippversion.h" -#endif - namespace cv { @@ -2803,11 +2799,11 @@ static double dotProd_8u(const uchar* src1, const uchar* src2, int len) { double r = 0; #if ARITHM_USE_IPP - ippiDotProd_8u64f_C1R(src1, (int)(len*sizeof(src1[0])), - src2, (int)(len*sizeof(src2[0])), - ippiSize(len, 1), &r); - return r; -#else + if (0 <= ippiDotProd_8u64f_C1R(src1, (int)(len*sizeof(src1[0])), + src2, (int)(len*sizeof(src2[0])), + ippiSize(len, 1), &r)) + return r; +#endif int i = 0; #if CV_SSE2 @@ -2853,7 +2849,6 @@ static double dotProd_8u(const uchar* src1, const uchar* src2, int len) } #endif return r + dotProd_(src1, src2, len - i); -#endif } @@ -2864,48 +2859,52 @@ static double dotProd_8s(const schar* src1, const schar* src2, int len) static double dotProd_16u(const ushort* src1, const ushort* src2, int len) { +#if (ARITHM_USE_IPP == 1) double r = 0; - IF_IPP(ippiDotProd_16u64f_C1R(src1, (int)(len*sizeof(src1[0])), - src2, (int)(len*sizeof(src2[0])), - ippiSize(len, 1), &r), - r = dotProd_(src1, src2, len)); - return r; + if (0 <= ippiDotProd_16u64f_C1R(src1, (int)(len*sizeof(src1[0])), src2, (int)(len*sizeof(src2[0])), ippiSize(len, 1), &r)) + return r; +#endif + return dotProd_(src1, src2, len); } static double dotProd_16s(const short* src1, const short* src2, int len) { +#if (ARITHM_USE_IPP == 1) double r = 0; - IF_IPP(ippiDotProd_16s64f_C1R(src1, (int)(len*sizeof(src1[0])), - src2, (int)(len*sizeof(src2[0])), - ippiSize(len, 1), &r), - r = dotProd_(src1, src2, len)); - return r; + if (0 <= ippiDotProd_16s64f_C1R(src1, (int)(len*sizeof(src1[0])), src2, (int)(len*sizeof(src2[0])), ippiSize(len, 1), &r)) + return r; +#endif + return dotProd_(src1, src2, len); } static double dotProd_32s(const int* src1, const int* src2, int len) { +#if (ARITHM_USE_IPP == 1) double r = 0; - IF_IPP(ippiDotProd_32s64f_C1R(src1, (int)(len*sizeof(src1[0])), - src2, (int)(len*sizeof(src2[0])), - ippiSize(len, 1), &r), - r = dotProd_(src1, src2, len)); - return r; + if (0 <= ippiDotProd_32s64f_C1R(src1, (int)(len*sizeof(src1[0])), src2, (int)(len*sizeof(src2[0])), ippiSize(len, 1), &r)) + return r; +#endif + return dotProd_(src1, src2, len); } static double dotProd_32f(const float* src1, const float* src2, int len) { +#if (ARITHM_USE_IPP == 1) double r = 0; - IF_IPP(ippsDotProd_32f64f(src1, src2, len, &r), - r = dotProd_(src1, src2, len)); - return r; + if (0 <= ippsDotProd_32f64f(src1, src2, len, &r)) + return r; +#endif + return dotProd_(src1, src2, len); } static double dotProd_64f(const double* src1, const double* src2, int len) { +#if (ARITHM_USE_IPP == 1) double r = 0; - IF_IPP(ippsDotProd_64f(src1, src2, len, &r), - r = dotProd_(src1, src2, len)); - return r; + if (0 <= ippsDotProd_64f(src1, src2, len, &r)) + return r; +#endif + return dotProd_(src1, src2, len); } diff --git a/modules/core/src/out.cpp b/modules/core/src/out.cpp index 3ed454ebfa..d639ac2126 100644 --- a/modules/core/src/out.cpp +++ b/modules/core/src/out.cpp @@ -257,7 +257,7 @@ namespace { char braces[5] = {'\0', '\0', ';', '\0', '\0'}; return cv::makePtr("[", "]", mtx, &*braces, - mtx.cols == 1 || !multiline, mtx.depth() == CV_64F ? prec64f : prec32f ); + mtx.rows == 1 || !multiline, mtx.depth() == CV_64F ? prec64f : prec32f ); } }; @@ -271,7 +271,7 @@ namespace if (mtx.cols == 1) braces[0] = braces[1] = '\0'; return cv::makePtr("[", "]", mtx, &*braces, - mtx.cols*mtx.channels() == 1 || !multiline, mtx.depth() == CV_64F ? prec64f : prec32f ); + mtx.rows*mtx.channels() == 1 || !multiline, mtx.depth() == CV_64F ? prec64f : prec32f ); } }; @@ -290,7 +290,7 @@ namespace braces[0] = braces[1] = '\0'; return cv::makePtr("array([", cv::format("], type='%s')", numpyTypes[mtx.depth()]), mtx, &*braces, - mtx.cols*mtx.channels() == 1 || !multiline, mtx.depth() == CV_64F ? prec64f : prec32f ); + mtx.rows*mtx.channels() == 1 || !multiline, mtx.depth() == CV_64F ? prec64f : prec32f ); } }; @@ -303,7 +303,7 @@ namespace char braces[5] = {'\0', '\0', '\0', '\0', '\0'}; return cv::makePtr(cv::String(), mtx.rows > 1 ? cv::String("\n") : cv::String(), mtx, &*braces, - mtx.cols*mtx.channels() == 1 || !multiline, mtx.depth() == CV_64F ? prec64f : prec32f ); + mtx.rows*mtx.channels() == 1 || !multiline, mtx.depth() == CV_64F ? prec64f : prec32f ); } }; @@ -315,7 +315,7 @@ namespace { char braces[5] = {'\0', '\0', ',', '\0', '\0'}; return cv::makePtr("{", "}", mtx, &*braces, - mtx.cols == 1 || !multiline, mtx.depth() == CV_64F ? prec64f : prec32f ); + mtx.rows == 1 || !multiline, mtx.depth() == CV_64F ? prec64f : prec32f ); } }; diff --git a/modules/core/src/precomp.hpp b/modules/core/src/precomp.hpp index ff5943bc63..1c498cd012 100644 --- a/modules/core/src/precomp.hpp +++ b/modules/core/src/precomp.hpp @@ -199,10 +199,8 @@ enum { BLOCK_SIZE = 1024 }; #if defined HAVE_IPP && (IPP_VERSION_MAJOR >= 7) #define ARITHM_USE_IPP 1 -#define IF_IPP(then_call, else_call) then_call #else #define ARITHM_USE_IPP 0 -#define IF_IPP(then_call, else_call) else_call #endif inline bool checkScalar(const Mat& sc, int atype, int sckind, int akind) diff --git a/modules/core/src/stat.cpp b/modules/core/src/stat.cpp index a4605d1605..0e3d44ed6b 100644 --- a/modules/core/src/stat.cpp +++ b/modules/core/src/stat.cpp @@ -972,7 +972,9 @@ void cv::meanStdDev( InputArray _src, OutputArray _mean, OutputArray _sdv, Input ippiMeanStdDevFuncC1 ippFuncC1 = type == CV_8UC1 ? (ippiMeanStdDevFuncC1)ippiMean_StdDev_8u_C1R : type == CV_16UC1 ? (ippiMeanStdDevFuncC1)ippiMean_StdDev_16u_C1R : - //type == CV_32FC1 ? (ippiMeanStdDevFuncC1)ippiMean_StdDev_32f_C1R ://Aug 2013: bug in IPP 7.1, 8.0 +#if (IPP_VERSION_X100 >= 801) + type == CV_32FC1 ? (ippiMeanStdDevFuncC1)ippiMean_StdDev_32f_C1R ://Aug 2013: bug in IPP 7.1, 8.0 +#endif 0; if( ippFuncC1 ) { @@ -2111,8 +2113,10 @@ double cv::norm( InputArray _src, int normType, InputArray _mask ) type == CV_16UC3 ? (ippiNormFuncNoHint)ippiNorm_Inf_16u_C3R : type == CV_16UC4 ? (ippiNormFuncNoHint)ippiNorm_Inf_16u_C4R : type == CV_16SC1 ? (ippiNormFuncNoHint)ippiNorm_Inf_16s_C1R : - //type == CV_16SC3 ? (ippiNormFunc)ippiNorm_Inf_16s_C3R : //Aug 2013: problem in IPP 7.1, 8.0 : -32768 - //type == CV_16SC4 ? (ippiNormFunc)ippiNorm_Inf_16s_C4R : //Aug 2013: problem in IPP 7.1, 8.0 : -32768 +#if (IPP_VERSION_X100 >= 801) + type == CV_16SC3 ? (ippiNormFuncNoHint)ippiNorm_Inf_16s_C3R : //Aug 2013: problem in IPP 7.1, 8.0 : -32768 + type == CV_16SC4 ? (ippiNormFuncNoHint)ippiNorm_Inf_16s_C4R : //Aug 2013: problem in IPP 7.1, 8.0 : -32768 +#endif type == CV_32FC1 ? (ippiNormFuncNoHint)ippiNorm_Inf_32f_C1R : type == CV_32FC3 ? (ippiNormFuncNoHint)ippiNorm_Inf_32f_C3R : type == CV_32FC4 ? (ippiNormFuncNoHint)ippiNorm_Inf_32f_C4R : @@ -2360,7 +2364,7 @@ double cv::norm( InputArray _src1, InputArray _src2, int normType, InputArray _m #if defined (HAVE_IPP) && (IPP_VERSION_MAJOR >= 7) Mat src1 = _src1.getMat(), src2 = _src2.getMat(), mask = _mask.getMat(); - normType &= 7; + normType &= NORM_TYPE_MASK; CV_Assert( normType == NORM_INF || normType == NORM_L1 || normType == NORM_L2 || normType == NORM_L2SQR || ((normType == NORM_HAMMING || normType == NORM_HAMMING2) && src1.type() == CV_8U) ); size_t total_size = src1.total(); @@ -2541,8 +2545,10 @@ double cv::norm( InputArray _src1, InputArray _src2, int normType, InputArray _m type == CV_16UC3 ? (ippiNormDiffFuncNoHint)ippiNormDiff_Inf_16u_C3R : type == CV_16UC4 ? (ippiNormDiffFuncNoHint)ippiNormDiff_Inf_16u_C4R : type == CV_16SC1 ? (ippiNormDiffFuncNoHint)ippiNormDiff_Inf_16s_C1R : - //type == CV_16SC3 ? (ippiNormDiffFunc)ippiNormDiff_Inf_16s_C3R : //Aug 2013: problem in IPP 7.1, 8.0 : -32768 - //type == CV_16SC4 ? (ippiNormDiffFunc)ippiNormDiff_Inf_16s_C4R : //Aug 2013: problem in IPP 7.1, 8.0 : -32768 +#if (IPP_VERSION_X100 >= 801) + type == CV_16SC3 ? (ippiNormDiffFuncNoHint)ippiNormDiff_Inf_16s_C3R : //Aug 2013: problem in IPP 7.1, 8.0 : -32768 + type == CV_16SC4 ? (ippiNormDiffFuncNoHint)ippiNormDiff_Inf_16s_C4R : //Aug 2013: problem in IPP 7.1, 8.0 : -32768 +#endif type == CV_32FC1 ? (ippiNormDiffFuncNoHint)ippiNormDiff_Inf_32f_C1R : type == CV_32FC3 ? (ippiNormDiffFuncNoHint)ippiNormDiff_Inf_32f_C3R : type == CV_32FC4 ? (ippiNormDiffFuncNoHint)ippiNormDiff_Inf_32f_C4R : diff --git a/modules/core/src/system.cpp b/modules/core/src/system.cpp index 1e6f592d57..4b3efce4a8 100644 --- a/modules/core/src/system.cpp +++ b/modules/core/src/system.cpp @@ -274,7 +274,14 @@ volatile bool useOptimizedFlag = true; #ifdef HAVE_IPP struct IPPInitializer { - IPPInitializer(void) { ippStaticInit(); } + IPPInitializer(void) + { +#if IPP_VERSION_MAJOR >= 8 + ippInit(); +#else + ippStaticInit(); +#endif + } }; IPPInitializer ippInitializer; @@ -390,17 +397,17 @@ int64 getCPUTickCount(void) #else -#ifdef HAVE_IPP -int64 getCPUTickCount(void) -{ - return ippGetCpuClocks(); -} -#else +//#ifdef HAVE_IPP +//int64 getCPUTickCount(void) +//{ +// return ippGetCpuClocks(); +//} +//#else int64 getCPUTickCount(void) { return getTickCount(); } -#endif +//#endif #endif diff --git a/modules/core/test/test_arithm.cpp b/modules/core/test/test_arithm.cpp index 626b44cbc5..2527e5397a 100644 --- a/modules/core/test/test_arithm.cpp +++ b/modules/core/test/test_arithm.cpp @@ -1362,7 +1362,8 @@ TEST_P(ElemWiseTest, accuracy) double maxErr = op->getMaxErr(depth); vector pos; - ASSERT_PRED_FORMAT2(cvtest::MatComparator(maxErr, op->context), dst0, dst) << "\nsrc[0] ~ " << cvtest::MatInfo(!src.empty() ? src[0] : Mat()) << "\ntestCase #" << testIdx << "\n"; + ASSERT_PRED_FORMAT2(cvtest::MatComparator(maxErr, op->context), dst0, dst) << "\nsrc[0] ~ " << + cvtest::MatInfo(!src.empty() ? src[0] : Mat()) << "\ntestCase #" << testIdx << "\n"; } } @@ -1500,7 +1501,7 @@ protected: } Mat d1; d.convertTo(d1, depth); - CV_Assert( norm(c, d1, CV_C) <= DBL_EPSILON ); + CV_Assert( cvtest::norm(c, d1, CV_C) <= DBL_EPSILON ); } Mat_ tmpSrc(100,100); @@ -1574,7 +1575,7 @@ TEST_P(Mul1, One) cv::multiply(3, src, dst); - ASSERT_EQ(0, cv::norm(dst, ref_dst, cv::NORM_INF)); + ASSERT_EQ(0, cvtest::norm(dst, ref_dst, cv::NORM_INF)); } INSTANTIATE_TEST_CASE_P(Arithm, Mul1, testing::Values(Size(2, 2), Size(1, 1))); diff --git a/modules/core/test/test_dxt.cpp b/modules/core/test/test_dxt.cpp index 1c0c7b00bf..9fc12c183d 100644 --- a/modules/core/test/test_dxt.cpp +++ b/modules/core/test/test_dxt.cpp @@ -855,7 +855,7 @@ protected: merge(mv, 2, srcz); dft(srcz, dstz); dft(src, dst, DFT_COMPLEX_OUTPUT); - if(norm(dst, dstz, NORM_INF) > 1e-3) + if (cvtest::norm(dst, dstz, NORM_INF) > 1e-3) { cout << "actual:\n" << dst << endl << endl; cout << "reference:\n" << dstz << endl << endl; diff --git a/modules/core/test/test_eigen.cpp b/modules/core/test/test_eigen.cpp index 21859e59b8..671378443e 100644 --- a/modules/core/test/test_eigen.cpp +++ b/modules/core/test/test_eigen.cpp @@ -175,7 +175,7 @@ bool Core_EigenTest::check_pair_count(const cv::Mat& src, const cv::Mat& evalues { std::cout << endl; std::cout << "Checking sizes of eigen values matrix " << evalues << "..." << endl; std::cout << "Number of rows: " << evalues.rows << " Number of cols: " << evalues.cols << endl; - std:: cout << "Size of src symmetric matrix: " << src.rows << " * " << src.cols << endl; std::cout << endl; + std::cout << "Size of src symmetric matrix: " << src.rows << " * " << src.cols << endl; std::cout << endl; CV_Error(CORE_EIGEN_ERROR_COUNT, MESSAGE_ERROR_COUNT); return false; } @@ -187,7 +187,7 @@ bool Core_EigenTest::check_pair_count(const cv::Mat& src, const cv::Mat& evalues int n = src.rows, s = sign(high_index); int right_eigen_pair_count = n - max(0, low_index) - ((int)((n/2.0)*(s*s-s)) + (1+s-s*s)*(n - (high_index+1))); - if (!((evectors.rows == right_eigen_pair_count) && (evectors.cols == right_eigen_pair_count))) + if (!(evectors.rows == right_eigen_pair_count && evectors.cols == right_eigen_pair_count)) { std::cout << endl; std::cout << "Checking sizes of eigen vectors matrix " << evectors << "..." << endl; std::cout << "Number of rows: " << evectors.rows << " Number of cols: " << evectors.cols << endl; @@ -196,7 +196,7 @@ bool Core_EigenTest::check_pair_count(const cv::Mat& src, const cv::Mat& evalues return false; } - if (!((evalues.rows == right_eigen_pair_count) && (evalues.cols == 1))) + if (!(evalues.rows == right_eigen_pair_count && evalues.cols == 1)) { std::cout << endl; std::cout << "Checking sizes of eigen values matrix " << evalues << "..." << endl; std::cout << "Number of rows: " << evalues.rows << " Number of cols: " << evalues.cols << endl; @@ -212,9 +212,9 @@ void Core_EigenTest::print_information(const size_t norm_idx, const cv::Mat& src { switch (NORM_TYPE[norm_idx]) { - case cv::NORM_L1: {std::cout << "L1"; break;} - case cv::NORM_L2: {std::cout << "L2"; break;} - case cv::NORM_INF: {std::cout << "INF"; break;} + case cv::NORM_L1: std::cout << "L1"; break; + case cv::NORM_L2: std::cout << "L2"; break; + case cv::NORM_INF: std::cout << "INF"; break; default: break; } @@ -234,7 +234,7 @@ bool Core_EigenTest::check_orthogonality(const cv::Mat& U) for (int i = 0; i < COUNT_NORM_TYPES; ++i) { - double diff = cv::norm(UUt, E, NORM_TYPE[i]); + double diff = cvtest::norm(UUt, E, NORM_TYPE[i]); if (diff > eps_vec) { std::cout << endl; std::cout << "Checking orthogonality of matrix " << U << ": "; @@ -271,12 +271,12 @@ bool Core_EigenTest::check_pairs_order(const cv::Mat& eigen_values) for (int i = 0; i < (int)(eigen_values.total() - 1); ++i) if (!(eigen_values.at(i, 0) > eigen_values.at(i+1, 0))) { - std::cout << endl; std::cout << "Checking order of eigen values vector " << eigen_values << "..." << endl; - std::cout << "Pair of indexes with non ascending of eigen values: (" << i << ", " << i+1 << ")." << endl; - std::cout << endl; - CV_Error(CORE_EIGEN_ERROR_ORDER, "Eigen values are not sorted in ascending order."); - return false; - } + std::cout << endl; std::cout << "Checking order of eigen values vector " << eigen_values << "..." << endl; + std::cout << "Pair of indexes with non ascending of eigen values: (" << i << ", " << i+1 << ")." << endl; + std::cout << endl; + CV_Error(CORE_EIGEN_ERROR_ORDER, "Eigen values are not sorted in ascending order."); + return false; + } break; } @@ -296,11 +296,14 @@ bool Core_EigenTest::test_pairs(const cv::Mat& src) cv::eigen(src, eigen_values, eigen_vectors); - if (!check_pair_count(src, eigen_values, eigen_vectors)) return false; + if (!check_pair_count(src, eigen_values, eigen_vectors)) + return false; - if (!check_orthogonality (eigen_vectors)) return false; + if (!check_orthogonality (eigen_vectors)) + return false; - if (!check_pairs_order(eigen_values)) return false; + if (!check_pairs_order(eigen_values)) + return false; cv::Mat eigen_vectors_t; cv::transpose(eigen_vectors, eigen_vectors_t); @@ -340,7 +343,7 @@ bool Core_EigenTest::test_pairs(const cv::Mat& src) for (int i = 0; i < COUNT_NORM_TYPES; ++i) { - double diff = cv::norm(disparity, NORM_TYPE[i]); + double diff = cvtest::norm(disparity, NORM_TYPE[i]); if (diff > eps_vec) { std::cout << endl; std::cout << "Checking accuracy of eigen vectors computing for matrix " << src << ": "; @@ -369,7 +372,7 @@ bool Core_EigenTest::test_values(const cv::Mat& src) for (int i = 0; i < COUNT_NORM_TYPES; ++i) { - double diff = cv::norm(eigen_values_1, eigen_values_2, NORM_TYPE[i]); + double diff = cvtest::norm(eigen_values_1, eigen_values_2, NORM_TYPE[i]); if (diff > eps_val) { std::cout << endl; std::cout << "Checking accuracy of eigen values computing for matrix " << src << ": "; diff --git a/modules/core/test/test_io.cpp b/modules/core/test/test_io.cpp index e6c412f869..ba56f76a6f 100644 --- a/modules/core/test/test_io.cpp +++ b/modules/core/test/test_io.cpp @@ -480,9 +480,9 @@ protected: fs["g1"] >> og1; CV_Assert( mi2.empty() ); CV_Assert( mv2.empty() ); - CV_Assert( norm(mi3, mi4, CV_C) == 0 ); + CV_Assert( cvtest::norm(Mat(mi3), Mat(mi4), CV_C) == 0 ); CV_Assert( mv4.size() == 1 ); - double n = norm(mv3[0], mv4[0], CV_C); + double n = cvtest::norm(mv3[0], mv4[0], CV_C); CV_Assert( vudt2.empty() ); CV_Assert( vudt3 == vudt4 ); CV_Assert( n == 0 ); diff --git a/modules/core/test/test_ippasync.cpp b/modules/core/test/test_ippasync.cpp new file mode 100644 index 0000000000..bd37ffa63b --- /dev/null +++ b/modules/core/test/test_ippasync.cpp @@ -0,0 +1,179 @@ +#include "test_precomp.hpp" +#include "opencv2/ts/ocl_test.hpp" + +#ifdef HAVE_IPP_A +#include "opencv2/core/ippasync.hpp" + +using namespace cv; +using namespace std; +using namespace cvtest; + +namespace cvtest { +namespace ocl { + +PARAM_TEST_CASE(IPPAsync, MatDepth, Channels, hppAccelType) +{ + int type; + int cn; + int depth; + hppAccelType accelType; + + Mat matrix, result; + hppiMatrix * hppMat; + hppAccel accel; + hppiVirtualMatrix * virtMatrix; + hppStatus sts; + + virtual void SetUp() + { + type = CV_MAKE_TYPE(GET_PARAM(0), GET_PARAM(1)); + depth = GET_PARAM(0); + cn = GET_PARAM(1); + accelType = GET_PARAM(2); + } + + virtual void generateTestData() + { + Size matrix_Size = randomSize(2, 100); + const double upValue = 100; + + matrix = randomMat(matrix_Size, type, -upValue, upValue); + } + + void Near(double threshold = 0.0) + { + EXPECT_MAT_NEAR(matrix, result, threshold); + } +}; + +TEST_P(IPPAsync, accuracy) +{ + sts = hppCreateInstance(accelType, 0, &accel); + if (sts!=HPP_STATUS_NO_ERROR) printf("hppStatus = %d\n",sts); + CV_Assert(sts==HPP_STATUS_NO_ERROR); + + virtMatrix = hppiCreateVirtualMatrices(accel, 2); + + for (int j = 0; j < test_loop_times; j++) + { + generateTestData(); + hppMat = hpp::getHpp(matrix,accel); + + hppScalar a = 3; + + sts = hppiAddC(accel, hppMat, a, 0, virtMatrix[0]); + CV_Assert(sts==HPP_STATUS_NO_ERROR); + sts = hppiSubC(accel, virtMatrix[0], a, 0, virtMatrix[1]); + CV_Assert(sts==HPP_STATUS_NO_ERROR); + + sts = hppWait(accel, HPP_TIME_OUT_INFINITE); + CV_Assert(sts==HPP_STATUS_NO_ERROR); + + result = hpp::getMat(virtMatrix[1], accel, cn); + + Near(5.0e-6); + + sts = hppiFreeMatrix(hppMat); + CV_Assert(sts==HPP_STATUS_NO_ERROR); + } + + sts = hppiDeleteVirtualMatrices(accel, virtMatrix); + CV_Assert(sts==HPP_STATUS_NO_ERROR); + sts = hppDeleteInstance(accel); + CV_Assert(sts==HPP_STATUS_NO_ERROR); +} + +PARAM_TEST_CASE(IPPAsyncShared, Channels, hppAccelType) +{ + int cn; + int type; + hppAccelType accelType; + + Mat matrix, result; + hppiMatrix* hppMat; + hppAccel accel; + hppiVirtualMatrix * virtMatrix; + hppStatus sts; + + virtual void SetUp() + { + cn = GET_PARAM(0); + accelType = GET_PARAM(1); + type=CV_MAKE_TYPE(CV_8U, GET_PARAM(0)); + } + + virtual void generateTestData() + { + Size matrix_Size = randomSize(2, 100); + hpp32u pitch, size; + const int upValue = 100; + + sts = hppQueryMatrixAllocParams(accel, (hpp32u)(matrix_Size.width*cn), (hpp32u)matrix_Size.height, HPP_DATA_TYPE_8U, &pitch, &size); + + if (pitch!=0 && size!=0) + { + uchar *pData = (uchar*)_aligned_malloc(size, 4096); + + for (int j=0; j(i,0) * v; - err = norm( Qv, lv ); + err = cvtest::norm( Qv, lv, NORM_L2 ); if( err > eigenEps ) { ts->printf( cvtest::TS::LOG, "bad accuracy of eigen(); err = %f\n", err ); @@ -350,7 +350,7 @@ protected: } // check pca eigenvalues evalEps = 1e-6, evecEps = 1e-3; - err = norm( rPCA.eigenvalues, subEval ); + err = cvtest::norm( rPCA.eigenvalues, subEval, NORM_L2 ); if( err > evalEps ) { ts->printf( cvtest::TS::LOG, "pca.eigenvalues is incorrect (CV_PCA_DATA_AS_ROW); err = %f\n", err ); @@ -362,11 +362,11 @@ protected: { Mat r0 = rPCA.eigenvectors.row(i); Mat r1 = subEvec.row(i); - err = norm( r0, r1, CV_L2 ); + err = cvtest::norm( r0, r1, CV_L2 ); if( err > evecEps ) { r1 *= -1; - double err2 = norm(r0, r1, CV_L2); + double err2 = cvtest::norm(r0, r1, CV_L2); if( err2 > evecEps ) { Mat tmp; @@ -390,7 +390,7 @@ protected: // check pca project Mat subEvec_t = subEvec.t(); Mat prj = rTestPoints.row(i) - avg; prj *= subEvec_t; - err = norm(rPrjTestPoints.row(i), prj, CV_RELATIVE_L2); + err = cvtest::norm(rPrjTestPoints.row(i), prj, CV_RELATIVE_L2); if( err > prjEps ) { ts->printf( cvtest::TS::LOG, "bad accuracy of project() (CV_PCA_DATA_AS_ROW); err = %f\n", err ); @@ -399,7 +399,7 @@ protected: } // check pca backProject Mat backPrj = rPrjTestPoints.row(i) * subEvec + avg; - err = norm( rBackPrjTestPoints.row(i), backPrj, CV_RELATIVE_L2 ); + err = cvtest::norm( rBackPrjTestPoints.row(i), backPrj, CV_RELATIVE_L2 ); if( err > backPrjEps ) { ts->printf( cvtest::TS::LOG, "bad accuracy of backProject() (CV_PCA_DATA_AS_ROW); err = %f\n", err ); @@ -412,14 +412,14 @@ protected: cPCA( rPoints.t(), Mat(), CV_PCA_DATA_AS_COL, maxComponents ); diffPrjEps = 1, diffBackPrjEps = 1; Mat ocvPrjTestPoints = cPCA.project(rTestPoints.t()); - err = norm(cv::abs(ocvPrjTestPoints), cv::abs(rPrjTestPoints.t()), CV_RELATIVE_L2 ); + err = cvtest::norm(cv::abs(ocvPrjTestPoints), cv::abs(rPrjTestPoints.t()), CV_RELATIVE_L2 ); if( err > diffPrjEps ) { ts->printf( cvtest::TS::LOG, "bad accuracy of project() (CV_PCA_DATA_AS_COL); err = %f\n", err ); ts->set_failed_test_info( cvtest::TS::FAIL_BAD_ACCURACY ); return; } - err = norm(cPCA.backProject(ocvPrjTestPoints), rBackPrjTestPoints.t(), CV_RELATIVE_L2 ); + err = cvtest::norm(cPCA.backProject(ocvPrjTestPoints), rBackPrjTestPoints.t(), CV_RELATIVE_L2 ); if( err > diffBackPrjEps ) { ts->printf( cvtest::TS::LOG, "bad accuracy of backProject() (CV_PCA_DATA_AS_COL); err = %f\n", err ); @@ -433,9 +433,9 @@ protected: Mat rvPrjTestPoints = cPCA.project(rTestPoints.t()); if( cPCA.eigenvectors.rows > maxComponents) - err = norm(cv::abs(rvPrjTestPoints.rowRange(0,maxComponents)), cv::abs(rPrjTestPoints.t()), CV_RELATIVE_L2 ); + err = cvtest::norm(cv::abs(rvPrjTestPoints.rowRange(0,maxComponents)), cv::abs(rPrjTestPoints.t()), CV_RELATIVE_L2 ); else - err = norm(cv::abs(rvPrjTestPoints), cv::abs(rPrjTestPoints.colRange(0,cPCA.eigenvectors.rows).t()), CV_RELATIVE_L2 ); + err = cvtest::norm(cv::abs(rvPrjTestPoints), cv::abs(rPrjTestPoints.colRange(0,cPCA.eigenvectors.rows).t()), CV_RELATIVE_L2 ); if( err > diffPrjEps ) { @@ -443,7 +443,7 @@ protected: ts->set_failed_test_info( cvtest::TS::FAIL_BAD_ACCURACY ); return; } - err = norm(cPCA.backProject(rvPrjTestPoints), rBackPrjTestPoints.t(), CV_RELATIVE_L2 ); + err = cvtest::norm(cPCA.backProject(rvPrjTestPoints), rBackPrjTestPoints.t(), CV_RELATIVE_L2 ); if( err > diffBackPrjEps ) { ts->printf( cvtest::TS::LOG, "bad accuracy of backProject() (CV_PCA_DATA_AS_COL); retainedVariance=0.95; err = %f\n", err ); @@ -467,14 +467,14 @@ protected: cvProjectPCA( &_testPoints, &_avg, &_evec, &_prjTestPoints ); cvBackProjectPCA( &_prjTestPoints, &_avg, &_evec, &_backPrjTestPoints ); - err = norm(prjTestPoints, rPrjTestPoints, CV_RELATIVE_L2); + err = cvtest::norm(prjTestPoints, rPrjTestPoints, CV_RELATIVE_L2); if( err > diffPrjEps ) { ts->printf( cvtest::TS::LOG, "bad accuracy of cvProjectPCA() (CV_PCA_DATA_AS_ROW); err = %f\n", err ); ts->set_failed_test_info( cvtest::TS::FAIL_BAD_ACCURACY ); return; } - err = norm(backPrjTestPoints, rBackPrjTestPoints, CV_RELATIVE_L2); + err = cvtest::norm(backPrjTestPoints, rBackPrjTestPoints, CV_RELATIVE_L2); if( err > diffBackPrjEps ) { ts->printf( cvtest::TS::LOG, "bad accuracy of cvBackProjectPCA() (CV_PCA_DATA_AS_ROW); err = %f\n", err ); @@ -495,14 +495,14 @@ protected: cvProjectPCA( &_testPoints, &_avg, &_evec, &_prjTestPoints ); cvBackProjectPCA( &_prjTestPoints, &_avg, &_evec, &_backPrjTestPoints ); - err = norm(cv::abs(prjTestPoints), cv::abs(rPrjTestPoints.t()), CV_RELATIVE_L2 ); + err = cvtest::norm(cv::abs(prjTestPoints), cv::abs(rPrjTestPoints.t()), CV_RELATIVE_L2 ); if( err > diffPrjEps ) { ts->printf( cvtest::TS::LOG, "bad accuracy of cvProjectPCA() (CV_PCA_DATA_AS_COL); err = %f\n", err ); ts->set_failed_test_info( cvtest::TS::FAIL_BAD_ACCURACY ); return; } - err = norm(backPrjTestPoints, rBackPrjTestPoints.t(), CV_RELATIVE_L2); + err = cvtest::norm(backPrjTestPoints, rBackPrjTestPoints.t(), CV_RELATIVE_L2); if( err > diffBackPrjEps ) { ts->printf( cvtest::TS::LOG, "bad accuracy of cvBackProjectPCA() (CV_PCA_DATA_AS_COL); err = %f\n", err ); @@ -518,19 +518,19 @@ protected: PCA lPCA; fs.open( "PCA_store.yml", FileStorage::READ ); lPCA.read( fs.root() ); - err = norm( rPCA.eigenvectors, lPCA.eigenvectors, CV_RELATIVE_L2 ); + err = cvtest::norm( rPCA.eigenvectors, lPCA.eigenvectors, CV_RELATIVE_L2 ); if( err > 0 ) { ts->printf( cvtest::TS::LOG, "bad accuracy of write/load functions (YML); err = %f\n", err ); ts->set_failed_test_info( cvtest::TS::FAIL_BAD_ACCURACY ); } - err = norm( rPCA.eigenvalues, lPCA.eigenvalues, CV_RELATIVE_L2 ); + err = cvtest::norm( rPCA.eigenvalues, lPCA.eigenvalues, CV_RELATIVE_L2 ); if( err > 0 ) { ts->printf( cvtest::TS::LOG, "bad accuracy of write/load functions (YML); err = %f\n", err ); ts->set_failed_test_info( cvtest::TS::FAIL_BAD_ACCURACY ); } - err = norm( rPCA.mean, lPCA.mean, CV_RELATIVE_L2 ); + err = cvtest::norm( rPCA.mean, lPCA.mean, CV_RELATIVE_L2 ); if( err > 0 ) { ts->printf( cvtest::TS::LOG, "bad accuracy of write/load functions (YML); err = %f\n", err ); @@ -731,9 +731,9 @@ void Core_ArrayOpTest::run( int /* start_from */) } minMaxLoc(_all_vals, &min_val, &max_val); - double _norm0 = norm(_all_vals, CV_C); - double _norm1 = norm(_all_vals, CV_L1); - double _norm2 = norm(_all_vals, CV_L2); + double _norm0 = cvtest::norm(_all_vals, CV_C); + double _norm1 = cvtest::norm(_all_vals, CV_L1); + double _norm2 = cvtest::norm(_all_vals, CV_L2); for( i = 0; i < nz0; i++ ) { diff --git a/modules/core/test/test_math.cpp b/modules/core/test/test_math.cpp index 859ebe60ea..0d64fe8c02 100644 --- a/modules/core/test/test_math.cpp +++ b/modules/core/test/test_math.cpp @@ -2433,7 +2433,7 @@ protected: } Mat convertedRes = resInRad * 180. / CV_PI; - double normDiff = norm(convertedRes - resInDeg, NORM_INF); + double normDiff = cvtest::norm(convertedRes - resInDeg, NORM_INF); if(normDiff > FLT_EPSILON * 180.) { ts->printf(cvtest::TS::LOG, "There are incorrect result angles (in radians)\n"); @@ -2569,11 +2569,11 @@ TEST(Core_Invert, small) 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 ); + ASSERT_LT( cvtest::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 ); + ASSERT_LT( cvtest::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 ); + ASSERT_LT( cvtest::norm(b*c, i, CV_C), 0.1 ); } ///////////////////////////////////////////////////////////////////////////////////////////////////// @@ -2621,7 +2621,7 @@ TEST(Core_SVD, flt) Mat X, B1; solve(A, B, X, DECOMP_SVD); B1 = A*X; - EXPECT_LE(norm(B1, B, NORM_L2 + NORM_RELATIVE), FLT_EPSILON*10); + EXPECT_LE(cvtest::norm(B1, B, NORM_L2 + NORM_RELATIVE), FLT_EPSILON*10); } diff --git a/modules/core/test/test_operations.cpp b/modules/core/test/test_operations.cpp index 8215ea93f5..543fb31ac7 100644 --- a/modules/core/test/test_operations.cpp +++ b/modules/core/test/test_operations.cpp @@ -83,11 +83,11 @@ protected: void checkDiff(const Mat& m1, const Mat& m2, const string& s) { - if (norm(m1, m2, NORM_INF) != 0) throw test_excep(s); + if (cvtest::norm(m1, m2, NORM_INF) != 0) throw test_excep(s); } void checkDiffF(const Mat& m1, const Mat& m2, const string& s) { - if (norm(m1, m2, NORM_INF) > 1e-5) throw test_excep(s); + if (cvtest::norm(m1, m2, NORM_INF) > 1e-5) throw test_excep(s); } }; @@ -488,7 +488,7 @@ bool CV_OperationsTest::TestSubMatAccess() coords.push_back(T_bs(i)); //std::cout << T_bs1(i) << std::endl; } - CV_Assert( norm(coords, T_bs.reshape(1,1), NORM_INF) == 0 ); + CV_Assert( cvtest::norm(coords, T_bs.reshape(1,1), NORM_INF) == 0 ); } catch (const test_excep& e) { @@ -776,14 +776,14 @@ bool CV_OperationsTest::TestTemplateMat() mvf.push_back(Mat_::zeros(4, 3)); merge(mvf, mf2); split(mf2, mvf2); - CV_Assert( norm(mvf2[0], mvf[0], CV_C) == 0 && - norm(mvf2[1], mvf[1], CV_C) == 0 ); + CV_Assert( cvtest::norm(mvf2[0], mvf[0], CV_C) == 0 && + cvtest::norm(mvf2[1], mvf[1], CV_C) == 0 ); { Mat a(2,2,CV_32F,1.f); Mat b(1,2,CV_32F,1.f); Mat c = (a*b.t()).t(); - CV_Assert( norm(c, CV_L1) == 4. ); + CV_Assert( cvtest::norm(c, CV_L1) == 4. ); } bool badarg_catched = false; @@ -988,7 +988,7 @@ bool CV_OperationsTest::operations1() Vec v10dzero; for (int ii = 0; ii < 10; ++ii) { - if (!v10dzero[ii] == 0.0) + if (v10dzero[ii] != 0.0) throw test_excep(); } @@ -1014,13 +1014,13 @@ bool CV_OperationsTest::operations1() Matx33f b(1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f, 9.f); Mat c; add(Mat::zeros(3, 3, CV_32F), b, c); - CV_Assert( norm(b, c, CV_C) == 0 ); + CV_Assert( cvtest::norm(b, c, CV_C) == 0 ); add(Mat::zeros(3, 3, CV_64F), b, c, noArray(), c.type()); - CV_Assert( norm(b, c, CV_C) == 0 ); + CV_Assert( cvtest::norm(b, c, CV_C) == 0 ); add(Mat::zeros(6, 1, CV_64F), 1, c, noArray(), c.type()); - CV_Assert( norm(Matx61f(1.f, 1.f, 1.f, 1.f, 1.f, 1.f), c, CV_C) == 0 ); + CV_Assert( cvtest::norm(Matx61f(1.f, 1.f, 1.f, 1.f, 1.f, 1.f), c, CV_C) == 0 ); vector pt2d(3); vector pt3d(2); @@ -1066,11 +1066,11 @@ bool CV_OperationsTest::TestSVD() Mat A = (Mat_(3,4) << 1, 2, -1, 4, 2, 4, 3, 5, -1, -2, 6, 7); Mat x; SVD::solveZ(A,x); - if( norm(A*x, CV_C) > FLT_EPSILON ) + if( cvtest::norm(A*x, CV_C) > FLT_EPSILON ) throw test_excep(); SVD svd(A, SVD::FULL_UV); - if( norm(A*svd.vt.row(3).t(), CV_C) > FLT_EPSILON ) + if( cvtest::norm(A*svd.vt.row(3).t(), CV_C) > FLT_EPSILON ) throw test_excep(); Mat Dp(3,3,CV_32FC1); @@ -1094,11 +1094,11 @@ bool CV_OperationsTest::TestSVD() W=decomp.w; Mat I = Mat::eye(3, 3, CV_32F); - if( norm(U*U.t(), I, CV_C) > FLT_EPSILON || - norm(Vt*Vt.t(), I, CV_C) > FLT_EPSILON || + if( cvtest::norm(U*U.t(), I, CV_C) > FLT_EPSILON || + cvtest::norm(Vt*Vt.t(), I, CV_C) > FLT_EPSILON || W.at(2) < 0 || W.at(1) < W.at(2) || W.at(0) < W.at(1) || - norm(U*Mat::diag(W)*Vt, Q, CV_C) > FLT_EPSILON ) + cvtest::norm(U*Mat::diag(W)*Vt, Q, CV_C) > FLT_EPSILON ) throw test_excep(); } catch(const test_excep&) diff --git a/modules/core/test/test_rand.cpp b/modules/core/test/test_rand.cpp index 1d9b3dd0d1..a94624b89a 100644 --- a/modules/core/test/test_rand.cpp +++ b/modules/core/test/test_rand.cpp @@ -174,7 +174,7 @@ void Core_RandTest::run( int ) } } - if( maxk >= 1 && norm(arr[0], arr[1], NORM_INF) > eps) + if( maxk >= 1 && cvtest::norm(arr[0], arr[1], NORM_INF) > eps) { ts->printf( cvtest::TS::LOG, "RNG output depends on the array lengths (some generated numbers get lost?)" ); ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_OUTPUT ); diff --git a/modules/core/test/test_umat.cpp b/modules/core/test/test_umat.cpp index b7deb48955..d7ae7a9385 100644 --- a/modules/core/test/test_umat.cpp +++ b/modules/core/test/test_umat.cpp @@ -563,12 +563,12 @@ protected: void checkDiff(const Mat& m1, const Mat& m2, const string& s) { - if (norm(m1, m2, NORM_INF) != 0) + if (cvtest::norm(m1, m2, NORM_INF) != 0) throw test_excep(s); } void checkDiffF(const Mat& m1, const Mat& m2, const string& s) { - if (norm(m1, m2, NORM_INF) > 1e-5) + if (cvtest::norm(m1, m2, NORM_INF) > 1e-5) throw test_excep(s); } }; @@ -721,7 +721,7 @@ TEST(Core_UMat, getUMat) um.setTo(17); } - double err = norm(m, ref, NORM_INF); + double err = cvtest::norm(m, ref, NORM_INF); if (err > 0) { std::cout << "m: " << std::endl << m << std::endl; @@ -742,7 +742,7 @@ TEST(UMat, Sync) um.setTo(cv::Scalar::all(19)); - EXPECT_EQ(0, cv::norm(um.getMat(ACCESS_READ), cv::Mat(um.size(), um.type(), 19), NORM_INF)); + EXPECT_EQ(0, cvtest::norm(um.getMat(ACCESS_READ), cv::Mat(um.size(), um.type(), 19), NORM_INF)); } TEST(UMat, setOpenCL) diff --git a/modules/cuda/doc/introduction.rst b/modules/cuda/doc/introduction.rst index 589a39fdc4..230a6f41e3 100644 --- a/modules/cuda/doc/introduction.rst +++ b/modules/cuda/doc/introduction.rst @@ -45,7 +45,7 @@ Utilizing Multiple GPUs ----------------------- In the current version, each of the OpenCV CUDA algorithms can use only a single GPU. So, to utilize multiple GPUs, you have to manually distribute the work between GPUs. -Switching active devie can be done using :ocv:func:`cuda::setDevice()` function. For more details please read Cuda C Programing Guide. +Switching active devie can be done using :ocv:func:`cuda::setDevice()` function. For more details please read Cuda C Programming Guide. While developing algorithms for multiple GPUs, note a data passing overhead. For primitive functions and small images, it can be significant, which may eliminate all the advantages of having multiple GPUs. But for high-level algorithms, consider using multi-GPU acceleration. For example, the Stereo Block Matching algorithm has been successfully parallelized using the following algorithm: diff --git a/modules/cudabgsegm/test/test_bgsegm.cpp b/modules/cudabgsegm/test/test_bgsegm.cpp index 3597e2c10c..75d6d73a3f 100644 --- a/modules/cudabgsegm/test/test_bgsegm.cpp +++ b/modules/cudabgsegm/test/test_bgsegm.cpp @@ -323,7 +323,7 @@ CUDA_TEST_P(MOG2, getBackgroundImage) cv::Mat background_gold; mog2_gold->getBackgroundImage(background_gold); - ASSERT_MAT_NEAR(background_gold, background, 0); + ASSERT_MAT_NEAR(background_gold, background, 1); } INSTANTIATE_TEST_CASE_P(CUDA_BgSegm, MOG2, testing::Combine( diff --git a/modules/features2d/test/test_fast.cpp b/modules/features2d/test/test_fast.cpp index d500ce549c..0bca41b541 100644 --- a/modules/features2d/test/test_fast.cpp +++ b/modules/features2d/test/test_fast.cpp @@ -119,8 +119,8 @@ void CV_FastTest::run( int ) read( fs["exp_kps2"], exp_kps2, Mat() ); fs.release(); - if ( exp_kps1.size != kps1.size || 0 != norm(exp_kps1, kps1, NORM_L2) || - exp_kps2.size != kps2.size || 0 != norm(exp_kps2, kps2, NORM_L2)) + if ( exp_kps1.size != kps1.size || 0 != cvtest::norm(exp_kps1, kps1, NORM_L2) || + exp_kps2.size != kps2.size || 0 != cvtest::norm(exp_kps2, kps2, NORM_L2)) { ts->set_failed_test_info(cvtest::TS::FAIL_MISMATCH); return; diff --git a/modules/features2d/test/test_nearestneighbors.cpp b/modules/features2d/test/test_nearestneighbors.cpp index e61dfce6bb..3d80b0db17 100644 --- a/modules/features2d/test/test_nearestneighbors.cpp +++ b/modules/features2d/test/test_nearestneighbors.cpp @@ -193,8 +193,8 @@ int CV_KDTreeTest_CPP::checkGetPoins( const Mat& data ) // 3d way tr->getPoints( idxs, res3 ); - if( norm( res1, data, NORM_L1) != 0 || - norm( res3, data, NORM_L1) != 0) + if( cvtest::norm( res1, data, NORM_L1) != 0 || + cvtest::norm( res3, data, NORM_L1) != 0) return cvtest::TS::FAIL_BAD_ACCURACY; return cvtest::TS::OK; } @@ -232,7 +232,7 @@ int CV_KDTreeTest_CPP::findNeighbors( Mat& points, Mat& neighbors ) } // compare results - if( norm( neighbors, neighbors2, NORM_L1 ) != 0 ) + if( cvtest::norm( neighbors, neighbors2, NORM_L1 ) != 0 ) return cvtest::TS::FAIL_BAD_ACCURACY; return cvtest::TS::OK; @@ -284,7 +284,7 @@ int CV_FlannTest::knnSearch( Mat& points, Mat& neighbors ) } // compare results - if( norm( neighbors, neighbors1, NORM_L1 ) != 0 ) + if( cvtest::norm( neighbors, neighbors1, NORM_L1 ) != 0 ) return cvtest::TS::FAIL_BAD_ACCURACY; return cvtest::TS::OK; @@ -316,7 +316,7 @@ int CV_FlannTest::radiusSearch( Mat& points, Mat& neighbors ) neighbors1.at(i,j) = *it; } // compare results - if( norm( neighbors, neighbors1, NORM_L1 ) != 0 ) + if( cvtest::norm( neighbors, neighbors1, NORM_L1 ) != 0 ) return cvtest::TS::FAIL_BAD_ACCURACY; return cvtest::TS::OK; diff --git a/modules/highgui/test/test_drawing.cpp b/modules/highgui/test/test_drawing.cpp index 0769f0ce7f..9d9e17dde2 100644 --- a/modules/highgui/test/test_drawing.cpp +++ b/modules/highgui/test/test_drawing.cpp @@ -76,7 +76,7 @@ void CV_DrawingTest::run( int ) } else { - float err = (float)norm( testImg, valImg, CV_RELATIVE_L1 ); + float err = (float)cvtest::norm( testImg, valImg, CV_RELATIVE_L1 ); float Eps = 0.9f; if( err > Eps) { @@ -229,7 +229,7 @@ int CV_DrawingTest_CPP::checkLineIterator( Mat& img ) for(int i = 0; i < it.count; ++it, i++ ) { Vec3b v = (Vec3b)(*(*it)) - img.at(300,i); - float err = (float)norm( v ); + float err = (float)cvtest::norm( v, NORM_L2 ); if( err != 0 ) { ts->printf( ts->LOG, "LineIterator works incorrect" ); @@ -395,7 +395,7 @@ int CV_DrawingTest_C::checkLineIterator( Mat& _img ) for(int i = 0; i < count; i++ ) { Vec3b v = (Vec3b)(*(it.ptr)) - _img.at(300,i); - float err = (float)norm( v ); + float err = (float)cvtest::norm( v, NORM_L2 ); if( err != 0 ) { ts->printf( ts->LOG, "CvLineIterator works incorrect" ); diff --git a/modules/highgui/test/test_ffmpeg.cpp b/modules/highgui/test/test_ffmpeg.cpp index 5dcd67be60..f8491d1a69 100644 --- a/modules/highgui/test/test_ffmpeg.cpp +++ b/modules/highgui/test/test_ffmpeg.cpp @@ -163,7 +163,7 @@ public: CV_Assert( !img0.empty() && !img.empty() && img_next.empty() ); - double diff = norm(img0, img, CV_C); + double diff = cvtest::norm(img0, img, CV_C); CV_Assert( diff == 0 ); } catch(...) diff --git a/modules/highgui/test/test_grfmt.cpp b/modules/highgui/test/test_grfmt.cpp index 2f76406296..e4d3e70461 100644 --- a/modules/highgui/test/test_grfmt.cpp +++ b/modules/highgui/test/test_grfmt.cpp @@ -121,7 +121,7 @@ public: CV_Assert(img.type() == img_test.type()); CV_Assert(num_channels == img_test.channels()); - double n = norm(img, img_test); + double n = cvtest::norm(img, img_test, NORM_L2); if ( n > 1.0) { ts->printf(ts->LOG, "norm = %f \n", n); @@ -151,7 +151,7 @@ public: CV_Assert(img.size() == img_test.size()); CV_Assert(img.type() == img_test.type()); - double n = norm(img, img_test); + double n = cvtest::norm(img, img_test, NORM_L2); if ( n > 1.0) { ts->printf(ts->LOG, "norm = %f \n", n); @@ -183,7 +183,7 @@ public: CV_Assert(img.type() == img_test.type()); - double n = norm(img, img_test); + double n = cvtest::norm(img, img_test, NORM_L2); if ( n > 1.0) { ts->printf(ts->LOG, "norm = %f \n", n); @@ -210,7 +210,7 @@ public: { Mat rle = imread(string(ts->get_data_path()) + "readwrite/rle8.bmp"); Mat bmp = imread(string(ts->get_data_path()) + "readwrite/ordinary.bmp"); - if (norm(rle-bmp)>1.e-10) + if (cvtest::norm(rle-bmp, NORM_L2)>1.e-10) ts->set_failed_test_info(cvtest::TS::FAIL_BAD_ACCURACY); } catch(...) @@ -406,7 +406,7 @@ TEST(Highgui_Jpeg, encode_decode_progressive_jpeg) EXPECT_NO_THROW(cv::imwrite(output_normal, img)); cv::Mat img_jpg_normal = cv::imread(output_normal); - EXPECT_EQ(0, cv::norm(img_jpg_progressive, img_jpg_normal, NORM_INF)); + EXPECT_EQ(0, cvtest::norm(img_jpg_progressive, img_jpg_normal, NORM_INF)); remove(output_progressive.c_str()); } @@ -430,7 +430,7 @@ TEST(Highgui_Jpeg, encode_decode_optimize_jpeg) EXPECT_NO_THROW(cv::imwrite(output_normal, img)); cv::Mat img_jpg_normal = cv::imread(output_normal); - EXPECT_EQ(0, cv::norm(img_jpg_optimized, img_jpg_normal, NORM_INF)); + EXPECT_EQ(0, cvtest::norm(img_jpg_optimized, img_jpg_normal, NORM_INF)); remove(output_optimized.c_str()); } @@ -612,11 +612,11 @@ TEST(Highgui_WebP, encode_decode_lossless_webp) cv::Mat decode = cv::imdecode(buf, IMREAD_COLOR); ASSERT_FALSE(decode.empty()); - EXPECT_TRUE(cv::norm(decode, img_webp, NORM_INF) == 0); + EXPECT_TRUE(cvtest::norm(decode, img_webp, NORM_INF) == 0); ASSERT_FALSE(img_webp.empty()); - EXPECT_TRUE(cv::norm(img, img_webp, NORM_INF) == 0); + EXPECT_TRUE(cvtest::norm(img, img_webp, NORM_INF) == 0); } TEST(Highgui_WebP, encode_decode_lossy_webp) diff --git a/modules/imgproc/doc/feature_detection.rst b/modules/imgproc/doc/feature_detection.rst index de16c07514..2187b8fd86 100644 --- a/modules/imgproc/doc/feature_detection.rst +++ b/modules/imgproc/doc/feature_detection.rst @@ -1,4 +1,4 @@ -Feature Detection +Feature Detection ================= .. highlight:: cpp @@ -15,9 +15,9 @@ Finds edges in an image using the [Canny86]_ algorithm. .. ocv:cfunction:: void cvCanny( const CvArr* image, CvArr* edges, double threshold1, double threshold2, int aperture_size=3 ) - :param image: single-channel 8-bit input image. + :param image: 8-bit input image. - :param edges: output edge map; it has the same size and type as ``image`` . + :param edges: output edge map; single channels 8-bit image, which has the same size as ``image`` . :param threshold1: first threshold for the hysteresis procedure. diff --git a/modules/imgproc/perf/perf_bilateral.cpp b/modules/imgproc/perf/perf_bilateral.cpp index af565f8a5e..4ed0c4db6e 100644 --- a/modules/imgproc/perf/perf_bilateral.cpp +++ b/modules/imgproc/perf/perf_bilateral.cpp @@ -34,5 +34,5 @@ PERF_TEST_P( TestBilateralFilter, BilateralFilter, TEST_CYCLE() bilateralFilter(src, dst, d, sigmaColor, sigmaSpace, BORDER_DEFAULT); - SANITY_CHECK(dst); + SANITY_CHECK(dst, .01, ERROR_RELATIVE); } diff --git a/modules/imgproc/src/canny.cpp b/modules/imgproc/src/canny.cpp index fbc92dde21..65e8173065 100644 --- a/modules/imgproc/src/canny.cpp +++ b/modules/imgproc/src/canny.cpp @@ -42,13 +42,13 @@ #include "precomp.hpp" #include "opencl_kernels.hpp" -/* + #if defined (HAVE_IPP) && (IPP_VERSION_MAJOR >= 7) #define USE_IPP_CANNY 1 #else #undef USE_IPP_CANNY #endif -*/ + namespace cv { @@ -81,8 +81,8 @@ static bool ippCanny(const Mat& _src, Mat& _dst, float low, float high) return false; if( ippiCanny_16s8u_C1R(_dx.ptr(), (int)_dx.step, - _dy.ptr(), (int)_dy.step, - _dst.data, (int)_dst.step, roi, low, high, buffer) < 0 ) + _dy.ptr(), (int)_dy.step, + _dst.data, (int)_dst.step, roi, low, high, buffer) < 0 ) return false; return true; } @@ -286,7 +286,7 @@ void cv::Canny( InputArray _src, OutputArray _dst, #endif #ifdef USE_IPP_CANNY - if( aperture_size == 3 && !L2gradient && + if( aperture_size == 3 && !L2gradient && 1 == cn && ippCanny(src, dst, (float)low_thresh, (float)high_thresh) ) return; #endif diff --git a/modules/imgproc/src/color.cpp b/modules/imgproc/src/color.cpp index 3822ab3c16..8ab7e4929f 100644 --- a/modules/imgproc/src/color.cpp +++ b/modules/imgproc/src/color.cpp @@ -252,6 +252,7 @@ bool CvtColorIPPLoopCopy(Mat& src, Mat& dst, const Cvt& cvt) } bool ok; parallel_for_(Range(0, source.rows), CvtColorIPPLoop_Invoker(source, dst, cvt, &ok), source.total()/(double)(1<<16) ); + //ok = cvt(src.ptr(0), (int)src.step[0], dst.ptr(0), (int)dst.step[0], src.cols, src.rows); return ok; } @@ -297,11 +298,13 @@ static ippiReorderFunc ippiSwapChannelsC3RTab[] = 0, (ippiReorderFunc)ippiSwapChannels_32f_C3R, 0, 0 }; +#if (IPP_VERSION_X100 >= 801) static ippiReorderFunc ippiSwapChannelsC4RTab[] = { - (ippiReorderFunc)ippiSwapChannels_8u_AC4R, 0, (ippiReorderFunc)ippiSwapChannels_16u_AC4R, 0, - 0, (ippiReorderFunc)ippiSwapChannels_32f_AC4R, 0, 0 + (ippiReorderFunc)ippiSwapChannels_8u_C4R, 0, (ippiReorderFunc)ippiSwapChannels_16u_C4R, 0, + 0, (ippiReorderFunc)ippiSwapChannels_32f_C4R, 0, 0 }; +#endif static ippiColor2GrayFunc ippiColor2GrayC3Tab[] = { @@ -3251,11 +3254,13 @@ void cv::cvtColor( InputArray _src, OutputArray _dst, int code, int dcn ) if( CvtColorIPPLoopCopy(src, dst, IPPReorderFunctor(ippiSwapChannelsC3RTab[depth], 2, 1, 0)) ) return; } +#if (IPP_VERSION_X100 >= 801) else if( code == CV_RGBA2BGRA ) { if( CvtColorIPPLoopCopy(src, dst, IPPReorderFunctor(ippiSwapChannelsC4RTab[depth], 2, 1, 0)) ) return; } +#endif #endif if( depth == CV_8U ) @@ -3310,14 +3315,17 @@ void cv::cvtColor( InputArray _src, OutputArray _dst, int code, int dcn ) CV_Assert( scn == 3 || scn == 4 ); _dst.create(sz, CV_MAKETYPE(depth, 1)); dst = _dst.getMat(); -/* +/**/ #if defined (HAVE_IPP) && (IPP_VERSION_MAJOR >= 7) +/* if( code == CV_BGR2GRAY ) { if( CvtColorIPPLoop(src, dst, IPPColor2GrayFunctor(ippiColor2GrayC3Tab[depth])) ) return; } - else if( code == CV_RGB2GRAY ) + else +*/ + if( code == CV_RGB2GRAY ) { if( CvtColorIPPLoop(src, dst, IPPGeneralFunctor(ippiRGB2GrayC3Tab[depth])) ) return; @@ -3333,7 +3341,7 @@ void cv::cvtColor( InputArray _src, OutputArray _dst, int code, int dcn ) return; } #endif -*/ +/**/ bidx = code == CV_BGR2GRAY || code == CV_BGRA2GRAY ? 0 : 2; if( depth == CV_8U ) diff --git a/modules/imgproc/src/deriv.cpp b/modules/imgproc/src/deriv.cpp index df2f371f55..0b19f22be4 100644 --- a/modules/imgproc/src/deriv.cpp +++ b/modules/imgproc/src/deriv.cpp @@ -190,223 +190,231 @@ namespace cv static bool IPPDerivScharr(const Mat& src, Mat& dst, int ddepth, int dx, int dy, double scale) { - int bufSize = 0; - cv::AutoBuffer buffer; - IppiSize roi = ippiSize(src.cols, src.rows); + int bufSize = 0; + cv::AutoBuffer buffer; + IppiSize roi = ippiSize(src.cols, src.rows); - if( ddepth < 0 ) - ddepth = src.depth(); + if( ddepth < 0 ) + ddepth = src.depth(); - dst.create( src.size(), CV_MAKETYPE(ddepth, src.channels()) ); + dst.create( src.size(), CV_MAKETYPE(ddepth, src.channels()) ); - switch(src.type()) - { - case CV_8U: - { + switch(src.type()) + { + case CV_8U: + { if(scale != 1) return false; switch(dst.type()) { - case CV_16S: - { - if((dx == 1) && (dy == 0)) - { - ippiFilterScharrVertGetBufferSize_8u16s_C1R(roi,&bufSize); - buffer.allocate(bufSize); - - ippiFilterScharrVertBorder_8u16s_C1R((const Ipp8u*)src.data, (int)src.step, - (Ipp16s*)dst.data, (int)dst.step, roi, ippBorderRepl, 0, (Ipp8u*)(char*)buffer); - - return true; - } - - if((dx == 0) && (dy == 1)) - { - ippiFilterScharrHorizGetBufferSize_8u16s_C1R(roi,&bufSize); - buffer.allocate(bufSize); - - ippiFilterScharrHorizBorder_8u16s_C1R((const Ipp8u*)src.data, (int)src.step, - (Ipp16s*)dst.data, (int)dst.step, roi, ippBorderRepl, 0, (Ipp8u*)(char*)buffer); - - return true; - } - } - - default: - return false; + case CV_16S: + { + if ((dx == 1) && (dy == 0)) + { + if (0 > ippiFilterScharrVertGetBufferSize_8u16s_C1R(roi,&bufSize)) + return false; + buffer.allocate(bufSize); + return (0 <= ippiFilterScharrVertBorder_8u16s_C1R((const Ipp8u*)src.data, (int)src.step, + (Ipp16s*)dst.data, (int)dst.step, roi, ippBorderRepl, 0, (Ipp8u*)(char*)buffer)); + } + if ((dx == 0) && (dy == 1)) + { + if (0 > ippiFilterScharrHorizGetBufferSize_8u16s_C1R(roi,&bufSize)) + return false; + buffer.allocate(bufSize); + return (0 <= ippiFilterScharrHorizBorder_8u16s_C1R((const Ipp8u*)src.data, (int)src.step, + (Ipp16s*)dst.data, (int)dst.step, roi, ippBorderRepl, 0, (Ipp8u*)(char*)buffer)); + } + return false; + } + default: + return false; } - } - - case CV_32F: - { + } + case CV_32F: + { switch(dst.type()) { - case CV_32F: - if((dx == 1) && (dy == 0)) - { - ippiFilterScharrVertGetBufferSize_32f_C1R(ippiSize(src.cols, src.rows),&bufSize); - buffer.allocate(bufSize); + case CV_32F: + { + if ((dx == 1) && (dy == 0)) + { + if (0 > ippiFilterScharrVertGetBufferSize_32f_C1R(ippiSize(src.cols, src.rows),&bufSize)) + return false; + buffer.allocate(bufSize); - ippiFilterScharrVertBorder_32f_C1R((const Ipp32f*)src.data, (int)src.step, - (Ipp32f*)dst.data, (int)dst.step, ippiSize(src.cols, src.rows), - ippBorderRepl, 0, (Ipp8u*)(char*)buffer); - if(scale != 1) - /* IPP is fast, so MulC produce very little perf degradation */ - ippiMulC_32f_C1IR((Ipp32f)scale, (Ipp32f*)dst.data, (int)dst.step, ippiSize(dst.cols*dst.channels(), dst.rows)); + if (0 > ippiFilterScharrVertBorder_32f_C1R((const Ipp32f*)src.data, (int)src.step, + (Ipp32f*)dst.data, (int)dst.step, ippiSize(src.cols, src.rows), + ippBorderRepl, 0, (Ipp8u*)(char*)buffer)) + { + return false; + } - return true; - } + if (scale != 1) + /* IPP is fast, so MulC produce very little perf degradation.*/ + //ippiMulC_32f_C1IR((Ipp32f)scale, (Ipp32f*)dst.data, (int)dst.step, ippiSize(dst.cols*dst.channels(), dst.rows)); + ippiMulC_32f_C1R((Ipp32f*)dst.data, (int)dst.step, (Ipp32f)scale, (Ipp32f*)dst.data, (int)dst.step, ippiSize(dst.cols*dst.channels(), dst.rows)); + return true; + } + if ((dx == 0) && (dy == 1)) + { + if (0 > ippiFilterScharrHorizGetBufferSize_32f_C1R(ippiSize(src.cols, src.rows),&bufSize)) + return false; + buffer.allocate(bufSize); - if((dx == 0) && (dy == 1)) - { - ippiFilterScharrHorizGetBufferSize_32f_C1R(ippiSize(src.cols, src.rows),&bufSize); - buffer.allocate(bufSize); + if (0 > ippiFilterScharrHorizBorder_32f_C1R((const Ipp32f*)src.data, (int)src.step, + (Ipp32f*)dst.data, (int)dst.step, ippiSize(src.cols, src.rows), + ippBorderRepl, 0, (Ipp8u*)(char*)buffer)) + return false; - ippiFilterScharrHorizBorder_32f_C1R((const Ipp32f*)src.data, (int)src.step, - (Ipp32f*)dst.data, (int)dst.step, ippiSize(src.cols, src.rows), - ippBorderRepl, 0, (Ipp8u*)(char*)buffer); - if(scale != 1) - ippiMulC_32f_C1IR((Ipp32f)scale, (Ipp32f *)dst.data, (int)dst.step, ippiSize(dst.cols*dst.channels(), dst.rows)); - - return true; - } - - default: - return false; + if (scale != 1) + ippiMulC_32f_C1R((Ipp32f *)dst.data, (int)dst.step, (Ipp32f)scale, (Ipp32f *)dst.data, (int)dst.step, ippiSize(dst.cols*dst.channels(), dst.rows)); + return true; + } + } + default: + return false; } - } - - default: - return false; - } + } + default: + return false; + } } static bool IPPDeriv(const Mat& src, Mat& dst, int ddepth, int dx, int dy, int ksize, double scale) { - int bufSize = 0; - cv::AutoBuffer buffer; + int bufSize = 0; + cv::AutoBuffer buffer; + if (ksize == 3 || ksize == 5) + { + if ( ddepth < 0 ) + ddepth = src.depth(); - if(ksize == 3 || ksize == 5) - { - if( ddepth < 0 ) - ddepth = src.depth(); + if (src.type() == CV_8U && dst.type() == CV_16S && scale == 1) + { + if ((dx == 1) && (dy == 0)) + { + if (0 > ippiFilterSobelNegVertGetBufferSize_8u16s_C1R(ippiSize(src.cols, src.rows), (IppiMaskSize)(ksize*10+ksize),&bufSize)) + return false; + buffer.allocate(bufSize); - if(src.type() == CV_8U && dst.type() == CV_16S && scale == 1) - { - if((dx == 1) && (dy == 0)) - { - ippiFilterSobelNegVertGetBufferSize_8u16s_C1R(ippiSize(src.cols, src.rows), (IppiMaskSize)(ksize*10+ksize),&bufSize); - buffer.allocate(bufSize); + return (0 <= ippiFilterSobelNegVertBorder_8u16s_C1R((const Ipp8u*)src.data, (int)src.step, + (Ipp16s*)dst.data, (int)dst.step, ippiSize(src.cols, src.rows), (IppiMaskSize)(ksize*10+ksize), + ippBorderRepl, 0, (Ipp8u*)(char*)buffer)); + } - ippiFilterSobelNegVertBorder_8u16s_C1R((const Ipp8u*)src.data, (int)src.step, - (Ipp16s*)dst.data, (int)dst.step, ippiSize(src.cols, src.rows), (IppiMaskSize)(ksize*10+ksize), - ippBorderRepl, 0, (Ipp8u*)(char*)buffer); - return true; - } + if ((dx == 0) && (dy == 1)) + { + if (0 > ippiFilterSobelHorizGetBufferSize_8u16s_C1R(ippiSize(src.cols, src.rows), (IppiMaskSize)(ksize*10+ksize),&bufSize)) + return false; + buffer.allocate(bufSize); - if((dx == 0) && (dy == 1)) - { - ippiFilterSobelHorizGetBufferSize_8u16s_C1R(ippiSize(src.cols, src.rows), (IppiMaskSize)(ksize*10+ksize),&bufSize); - buffer.allocate(bufSize); + return (0 <= ippiFilterSobelHorizBorder_8u16s_C1R((const Ipp8u*)src.data, (int)src.step, + (Ipp16s*)dst.data, (int)dst.step, ippiSize(src.cols, src.rows), (IppiMaskSize)(ksize*10+ksize), + ippBorderRepl, 0, (Ipp8u*)(char*)buffer)); + } - ippiFilterSobelHorizBorder_8u16s_C1R((const Ipp8u*)src.data, (int)src.step, - (Ipp16s*)dst.data, (int)dst.step, ippiSize(src.cols, src.rows), (IppiMaskSize)(ksize*10+ksize), - ippBorderRepl, 0, (Ipp8u*)(char*)buffer); + if ((dx == 2) && (dy == 0)) + { + if (0 > ippiFilterSobelVertSecondGetBufferSize_8u16s_C1R(ippiSize(src.cols, src.rows), (IppiMaskSize)(ksize*10+ksize),&bufSize)) + return false; + buffer.allocate(bufSize); - return true; - } + return (0 <= ippiFilterSobelVertSecondBorder_8u16s_C1R((const Ipp8u*)src.data, (int)src.step, + (Ipp16s*)dst.data, (int)dst.step, ippiSize(src.cols, src.rows), (IppiMaskSize)(ksize*10+ksize), + ippBorderRepl, 0, (Ipp8u*)(char*)buffer)); + } - if((dx == 2) && (dy == 0)) - { - ippiFilterSobelVertSecondGetBufferSize_8u16s_C1R(ippiSize(src.cols, src.rows), (IppiMaskSize)(ksize*10+ksize),&bufSize); - buffer.allocate(bufSize); + if ((dx == 0) && (dy == 2)) + { + if (0 > ippiFilterSobelHorizSecondGetBufferSize_8u16s_C1R(ippiSize(src.cols, src.rows), (IppiMaskSize)(ksize*10+ksize),&bufSize)) + return false; + buffer.allocate(bufSize); - ippiFilterSobelVertSecondBorder_8u16s_C1R((const Ipp8u*)src.data, (int)src.step, - (Ipp16s*)dst.data, (int)dst.step, ippiSize(src.cols, src.rows), (IppiMaskSize)(ksize*10+ksize), - ippBorderRepl, 0, (Ipp8u*)(char*)buffer); + return (0 <= ippiFilterSobelHorizSecondBorder_8u16s_C1R((const Ipp8u*)src.data, (int)src.step, + (Ipp16s*)dst.data, (int)dst.step, ippiSize(src.cols, src.rows), (IppiMaskSize)(ksize*10+ksize), + ippBorderRepl, 0, (Ipp8u*)(char*)buffer)); + } + } - return true; - } + if (src.type() == CV_32F && dst.type() == CV_32F) + { + if ((dx == 1) && (dy == 0)) + { + if (0 > ippiFilterSobelNegVertGetBufferSize_32f_C1R(ippiSize(src.cols, src.rows), (IppiMaskSize)(ksize*10+ksize), &bufSize)) + return false; + buffer.allocate(bufSize); - if((dx == 0) && (dy == 2)) - { - ippiFilterSobelHorizSecondGetBufferSize_8u16s_C1R(ippiSize(src.cols, src.rows), (IppiMaskSize)(ksize*10+ksize),&bufSize); - buffer.allocate(bufSize); + if (0 > ippiFilterSobelNegVertBorder_32f_C1R((const Ipp32f*)src.data, (int)src.step, + (Ipp32f*)dst.data, (int)dst.step, ippiSize(src.cols, src.rows), (IppiMaskSize)(ksize*10+ksize), + ippBorderRepl, 0, (Ipp8u*)(char*)buffer)) + { + return false; + } + if(scale != 1) + ippiMulC_32f_C1R((Ipp32f *)dst.data, (int)dst.step, (Ipp32f)scale, (Ipp32f *)dst.data, (int)dst.step, ippiSize(dst.cols*dst.channels(), dst.rows)); + return true; + } - ippiFilterSobelHorizSecondBorder_8u16s_C1R((const Ipp8u*)src.data, (int)src.step, - (Ipp16s*)dst.data, (int)dst.step, ippiSize(src.cols, src.rows), (IppiMaskSize)(ksize*10+ksize), - ippBorderRepl, 0, (Ipp8u*)(char*)buffer); + if ((dx == 0) && (dy == 1)) + { + if (0 > ippiFilterSobelHorizGetBufferSize_32f_C1R(ippiSize(src.cols, src.rows), (IppiMaskSize)(ksize*10+ksize),&bufSize)) + return false; + buffer.allocate(bufSize); - return true; - } - } + if (0 > ippiFilterSobelHorizBorder_32f_C1R((const Ipp32f*)src.data, (int)src.step, + (Ipp32f*)dst.data, (int)dst.step, ippiSize(src.cols, src.rows), (IppiMaskSize)(ksize*10+ksize), + ippBorderRepl, 0, (Ipp8u*)(char*)buffer)) + { + return false; + } + if(scale != 1) + ippiMulC_32f_C1R((Ipp32f *)dst.data, (int)dst.step, (Ipp32f)scale, (Ipp32f *)dst.data, (int)dst.step, ippiSize(dst.cols*dst.channels(), dst.rows)); + return true; + } - if(src.type() == CV_32F && dst.type() == CV_32F) - { - if((dx == 1) && (dy == 0)) - { - ippiFilterSobelNegVertGetBufferSize_32f_C1R(ippiSize(src.cols, src.rows), (IppiMaskSize)(ksize*10+ksize), &bufSize); - buffer.allocate(bufSize); + if((dx == 2) && (dy == 0)) + { + if (0 > ippiFilterSobelVertSecondGetBufferSize_32f_C1R(ippiSize(src.cols, src.rows), (IppiMaskSize)(ksize*10+ksize),&bufSize)) + return false; + buffer.allocate(bufSize); - ippiFilterSobelNegVertBorder_32f_C1R((const Ipp32f*)src.data, (int)src.step, - (Ipp32f*)dst.data, (int)dst.step, ippiSize(src.cols, src.rows), (IppiMaskSize)(ksize*10+ksize), - ippBorderRepl, 0, (Ipp8u*)(char*)buffer); - if(scale != 1) - ippiMulC_32f_C1IR((Ipp32f)scale, (Ipp32f *)dst.data, (int)dst.step, ippiSize(dst.cols*dst.channels(), dst.rows)); + if (0 > ippiFilterSobelVertSecondBorder_32f_C1R((const Ipp32f*)src.data, (int)src.step, + (Ipp32f*)dst.data, (int)dst.step, ippiSize(src.cols, src.rows), (IppiMaskSize)(ksize*10+ksize), + ippBorderRepl, 0, (Ipp8u*)(char*)buffer)) + { + return false; + } + if(scale != 1) + ippiMulC_32f_C1R((Ipp32f *)dst.data, (int)dst.step, (Ipp32f)scale, (Ipp32f *)dst.data, (int)dst.step, ippiSize(dst.cols*dst.channels(), dst.rows)); + return true; + } - return true; - } + if((dx == 0) && (dy == 2)) + { + if (0 > ippiFilterSobelHorizSecondGetBufferSize_32f_C1R(ippiSize(src.cols, src.rows), (IppiMaskSize)(ksize*10+ksize),&bufSize)) + return false; + buffer.allocate(bufSize); - if((dx == 0) && (dy == 1)) - { - ippiFilterSobelHorizGetBufferSize_32f_C1R(ippiSize(src.cols, src.rows), (IppiMaskSize)(ksize*10+ksize),&bufSize); - buffer.allocate(bufSize); + if (0 > ippiFilterSobelHorizSecondBorder_32f_C1R((const Ipp32f*)src.data, (int)src.step, + (Ipp32f*)dst.data, (int)dst.step, ippiSize(src.cols, src.rows), (IppiMaskSize)(ksize*10+ksize), + ippBorderRepl, 0, (Ipp8u*)(char*)buffer)) + { + return false; + } - ippiFilterSobelHorizBorder_32f_C1R((const Ipp32f*)src.data, (int)src.step, - (Ipp32f*)dst.data, (int)dst.step, ippiSize(src.cols, src.rows), (IppiMaskSize)(ksize*10+ksize), - ippBorderRepl, 0, (Ipp8u*)(char*)buffer); - if(scale != 1) - ippiMulC_32f_C1IR((Ipp32f)scale, (Ipp32f *)dst.data, (int)dst.step, ippiSize(dst.cols*dst.channels(), dst.rows)); + if(scale != 1) + ippiMulC_32f_C1R((Ipp32f *)dst.data, (int)dst.step, (Ipp32f)scale, (Ipp32f *)dst.data, (int)dst.step, ippiSize(dst.cols*dst.channels(), dst.rows)); + return true; + } + } + } - return true; - } - - if((dx == 2) && (dy == 0)) - { - ippiFilterSobelVertSecondGetBufferSize_32f_C1R(ippiSize(src.cols, src.rows), (IppiMaskSize)(ksize*10+ksize),&bufSize); - buffer.allocate(bufSize); - - ippiFilterSobelVertSecondBorder_32f_C1R((const Ipp32f*)src.data, (int)src.step, - (Ipp32f*)dst.data, (int)dst.step, ippiSize(src.cols, src.rows), (IppiMaskSize)(ksize*10+ksize), - ippBorderRepl, 0, (Ipp8u*)(char*)buffer); - if(scale != 1) - ippiMulC_32f_C1IR((Ipp32f)scale, (Ipp32f *)dst.data, (int)dst.step, ippiSize(dst.cols*dst.channels(), dst.rows)); - - return true; - } - - if((dx == 0) && (dy == 2)) - { - ippiFilterSobelHorizSecondGetBufferSize_32f_C1R(ippiSize(src.cols, src.rows), (IppiMaskSize)(ksize*10+ksize),&bufSize); - buffer.allocate(bufSize); - - ippiFilterSobelHorizSecondBorder_32f_C1R((const Ipp32f*)src.data, (int)src.step, - (Ipp32f*)dst.data, (int)dst.step, ippiSize(src.cols, src.rows), (IppiMaskSize)(ksize*10+ksize), - ippBorderRepl, 0, (Ipp8u*)(char*)buffer); - if(scale != 1) - ippiMulC_32f_C1IR((Ipp32f)scale, (Ipp32f *)dst.data, (int)dst.step, ippiSize(dst.cols*dst.channels(), dst.rows)); - - return true; - } - } - } - - if(ksize <= 0) - return IPPDerivScharr(src, dst, ddepth, dx, dy, scale); - - return false; + if(ksize <= 0) + return IPPDerivScharr(src, dst, ddepth, dx, dy, scale); + return false; } } @@ -436,7 +444,7 @@ void cv::Sobel( InputArray _src, OutputArray _dst, int ddepth, int dx, int dy, if(dx < 3 && dy < 3 && cn == 1 && borderType == BORDER_REPLICATE) { Mat src = _src.getMat(), dst = _dst.getMat(); - if(IPPDeriv(src, dst, ddepth, dx, dy, ksize,scale)) + if (IPPDeriv(src, dst, ddepth, dx, dy, ksize,scale)) return; } #endif diff --git a/modules/imgproc/src/filter.cpp b/modules/imgproc/src/filter.cpp index 2bc6b8a706..8b337f645b 100644 --- a/modules/imgproc/src/filter.cpp +++ b/modules/imgproc/src/filter.cpp @@ -47,7 +47,7 @@ Base Image Filter \****************************************************************************************/ -#if defined HAVE_IPP && IPP_VERSION_MAJOR*100 + IPP_VERSION_MINOR >= 701 +#if IPP_VERSION_X100 >= 701 #define USE_IPP_SEP_FILTERS 1 #else #undef USE_IPP_SEP_FILTERS @@ -1420,36 +1420,16 @@ struct RowVec_32f int operator()(const uchar* _src, uchar* _dst, int width, int cn) const { +#ifdef USE_IPP_SEP_FILTERS + int ret = ippiOperator(_src, _dst, width, cn); + if (ret > 0) + return ret; +#endif int _ksize = kernel.rows + kernel.cols - 1; const float* src0 = (const float*)_src; float* dst = (float*)_dst; const float* _kx = (const float*)kernel.data; -#ifdef USE_IPP_SEP_FILTERS - IppiSize roisz = { width, 1 }; - if( (cn == 1 || cn == 3) && width >= _ksize*8 ) - { - if( bufsz < 0 ) - { - if( (cn == 1 && ippiFilterRowBorderPipelineGetBufferSize_32f_C1R(roisz, _ksize, &bufsz) < 0) || - (cn == 3 && ippiFilterRowBorderPipelineGetBufferSize_32f_C3R(roisz, _ksize, &bufsz) < 0)) - return 0; - } - AutoBuffer buf(bufsz + 64); - uchar* bufptr = alignPtr((uchar*)buf, 32); - int step = (int)(width*sizeof(dst[0])*cn); - float borderValue[] = {0.f, 0.f, 0.f}; - // here is the trick. IPP needs border type and extrapolates the row. We did it already. - // So we pass anchor=0 and ignore the right tail of results since they are incorrect there. - if( (cn == 1 && ippiFilterRowBorderPipeline_32f_C1R(src0, step, &dst, roisz, _kx, _ksize, 0, - ippBorderRepl, borderValue[0], bufptr) < 0) || - (cn == 3 && ippiFilterRowBorderPipeline_32f_C3R(src0, step, &dst, roisz, _kx, _ksize, 0, - ippBorderRepl, borderValue, bufptr) < 0)) - return 0; - return width - _ksize + 1; - } -#endif - if( !haveSSE ) return 0; @@ -1479,7 +1459,38 @@ struct RowVec_32f Mat kernel; bool haveSSE; #ifdef USE_IPP_SEP_FILTERS +private: mutable int bufsz; + int ippiOperator(const uchar* _src, uchar* _dst, int width, int cn) const + { + int _ksize = kernel.rows + kernel.cols - 1; + if ((1 != cn && 3 != cn) || width < _ksize*8) + return 0; + + const float* src = (const float*)_src; + float* dst = (float*)_dst; + const float* _kx = (const float*)kernel.data; + + IppiSize roisz = { width, 1 }; + if( bufsz < 0 ) + { + if( (cn == 1 && ippiFilterRowBorderPipelineGetBufferSize_32f_C1R(roisz, _ksize, &bufsz) < 0) || + (cn == 3 && ippiFilterRowBorderPipelineGetBufferSize_32f_C3R(roisz, _ksize, &bufsz) < 0)) + return 0; + } + AutoBuffer buf(bufsz + 64); + uchar* bufptr = alignPtr((uchar*)buf, 32); + int step = (int)(width*sizeof(dst[0])*cn); + float borderValue[] = {0.f, 0.f, 0.f}; + // here is the trick. IPP needs border type and extrapolates the row. We did it already. + // So we pass anchor=0 and ignore the right tail of results since they are incorrect there. + if( (cn == 1 && ippiFilterRowBorderPipeline_32f_C1R(src, step, &dst, roisz, _kx, _ksize, 0, + ippBorderRepl, borderValue[0], bufptr) < 0) || + (cn == 3 && ippiFilterRowBorderPipeline_32f_C3R(src, step, &dst, roisz, _kx, _ksize, 0, + ippBorderRepl, borderValue, bufptr) < 0)) + return 0; + return width - _ksize + 1; + } #endif }; diff --git a/modules/imgproc/src/imgwarp.cpp b/modules/imgproc/src/imgwarp.cpp index da392b055b..0c7aafc7b9 100644 --- a/modules/imgproc/src/imgwarp.cpp +++ b/modules/imgproc/src/imgwarp.cpp @@ -55,7 +55,7 @@ static IppStatus sts = ippInit(); namespace cv { -#if defined (HAVE_IPP) && (IPP_VERSION_MAJOR*100 + IPP_VERSION_MINOR >= 701) +#if IPP_VERSION_X100 >= 701 typedef IppStatus (CV_STDCALL* ippiResizeFunc)(const void*, int, const void*, int, IppiPoint, IppiSize, IppiBorderType, void*, void*, Ipp8u*); typedef IppStatus (CV_STDCALL* ippiResizeGetBufferSize)(void*, IppiSize, Ipp32u, int*); typedef IppStatus (CV_STDCALL* ippiResizeGetSrcOffset)(void*, IppiPoint, IppiPoint*); @@ -1912,7 +1912,7 @@ static int computeResizeAreaTab( int ssize, int dsize, int cn, double scale, Dec getBufferSizeFunc = (ippiResizeGetBufferSize)ippiResizeGetBufferSize_##TYPE;\ getSrcOffsetFunc = (ippiResizeGetSrcOffset)ippiResizeGetSrcOffset_##TYPE; -#if defined (HAVE_IPP) && (IPP_VERSION_MAJOR*100 + IPP_VERSION_MINOR >= 701) +#if IPP_VERSION_X100 >= 701 class IPPresizeInvoker : public ParallelLoopBody { @@ -1971,7 +1971,7 @@ public: CHECK_IPP_STATUS(getBufferSizeFunc(pSpec, dstSize, cn, &bufsize)); CHECK_IPP_STATUS(getSrcOffsetFunc(pSpec, dstOffset, &srcOffset)); - Ipp8u* pSrc = (Ipp8u*)src.data + (int)src.step[0] * srcOffset.y + srcOffset.x * cn * itemSize; + const Ipp8u* pSrc = (const Ipp8u*)src.data + (int)src.step[0] * srcOffset.y + srcOffset.x * cn * itemSize; Ipp8u* pDst = (Ipp8u*)dst.data + (int)dst.step[0] * dstOffset.y + dstOffset.x * cn * itemSize; AutoBuffer buf(bufsize + 64); @@ -1980,9 +1980,8 @@ public: if( func( pSrc, (int)src.step[0], pDst, (int)dst.step[0], dstOffset, dstSize, ippBorderRepl, 0, pSpec, bufptr ) < 0 ) *ok = false; } - private: - Mat & src; + const Mat & src; Mat & dst; double inv_scale_x; double inv_scale_y; @@ -2385,7 +2384,7 @@ void cv::resize( InputArray _src, OutputArray _dst, Size dsize, double scale_x = 1./inv_scale_x, scale_y = 1./inv_scale_y; int k, sx, sy, dx, dy; -#if defined (HAVE_IPP) && (IPP_VERSION_MAJOR*100 + IPP_VERSION_MINOR >= 701) +#if IPP_VERSION_X100 >= 701 #define IPP_RESIZE_EPS 1.e-10 double ex = fabs((double)dsize.width/src.cols - inv_scale_x)/inv_scale_x; @@ -4025,25 +4024,25 @@ public: *ok = true; } - virtual void operator() (const Range& range) const - { - IppiSize srcsize = { src.cols, src.rows }; - IppiRect srcroi = { 0, 0, src.cols, src.rows }; - IppiRect dstroi = { 0, range.start, dst.cols, range.end - range.start }; - int cnn = src.channels(); - if( borderType == BORDER_CONSTANT ) - { - IppiSize setSize = { dst.cols, range.end - range.start }; - void *dataPointer = dst.data + dst.step[0] * range.start; - if( !IPPSet( borderValue, dataPointer, (int)dst.step[0], setSize, cnn, src.depth() ) ) - { - *ok = false; - return; - } - } - if( func( src.data, srcsize, (int)src.step[0], srcroi, dst.data, (int)dst.step[0], dstroi, coeffs, mode ) < 0) ////Aug 2013: problem in IPP 7.1, 8.0 : sometimes function return ippStsCoeffErr - *ok = false; - } + virtual void operator() (const Range& range) const + { + IppiSize srcsize = { src.cols, src.rows }; + IppiRect srcroi = { 0, 0, src.cols, src.rows }; + IppiRect dstroi = { 0, range.start, dst.cols, range.end - range.start }; + int cnn = src.channels(); + if( borderType == BORDER_CONSTANT ) + { + IppiSize setSize = { dst.cols, range.end - range.start }; + void *dataPointer = dst.data + dst.step[0] * range.start; + if( !IPPSet( borderValue, dataPointer, (int)dst.step[0], setSize, cnn, src.depth() ) ) + { + *ok = false; + return; + } + } + if( func( src.data, srcsize, (int)src.step[0], srcroi, dst.data, (int)dst.step[0], dstroi, coeffs, mode ) < 0) ////Aug 2013: problem in IPP 7.1, 8.0 : sometimes function return ippStsCoeffErr + *ok = false; + } private: Mat &src; Mat &dst; @@ -4368,26 +4367,26 @@ public: *ok = true; } - virtual void operator() (const Range& range) const - { - IppiSize srcsize = {src.cols, src.rows}; - IppiRect srcroi = {0, 0, src.cols, src.rows}; - IppiRect dstroi = {0, range.start, dst.cols, range.end - range.start}; - int cnn = src.channels(); + virtual void operator() (const Range& range) const + { + IppiSize srcsize = {src.cols, src.rows}; + IppiRect srcroi = {0, 0, src.cols, src.rows}; + IppiRect dstroi = {0, range.start, dst.cols, range.end - range.start}; + int cnn = src.channels(); - if( borderType == BORDER_CONSTANT ) - { - IppiSize setSize = {dst.cols, range.end - range.start}; - void *dataPointer = dst.data + dst.step[0] * range.start; - if( !IPPSet( borderValue, dataPointer, (int)dst.step[0], setSize, cnn, src.depth() ) ) - { - *ok = false; - return; - } - } - if( func(src.data, srcsize, (int)src.step[0], srcroi, dst.data, (int)dst.step[0], dstroi, coeffs, mode) < 0) - *ok = false; - } + if( borderType == BORDER_CONSTANT ) + { + IppiSize setSize = {dst.cols, range.end - range.start}; + void *dataPointer = dst.data + dst.step[0] * range.start; + if( !IPPSet( borderValue, dataPointer, (int)dst.step[0], setSize, cnn, src.depth() ) ) + { + *ok = false; + return; + } + } + if( func(src.data, srcsize, (int)src.step[0], srcroi, dst.data, (int)dst.step[0], dstroi, coeffs, mode) < 0) + *ok = false; + } private: Mat &src; Mat &dst; diff --git a/modules/imgproc/src/morph.cpp b/modules/imgproc/src/morph.cpp index 1dd0a252e8..07aa4c5dd3 100644 --- a/modules/imgproc/src/morph.cpp +++ b/modules/imgproc/src/morph.cpp @@ -1136,80 +1136,128 @@ private: Scalar borderValue; }; -#if defined (HAVE_IPP) && (IPP_VERSION_MAJOR >= 7) +#if IPP_VERSION_X100 >= 801 static bool IPPMorphReplicate(int op, const Mat &src, Mat &dst, const Mat &kernel, const Size& ksize, const Point &anchor, bool rectKernel) { int type = src.type(); const Mat* _src = &src; Mat temp; - if( src.data == dst.data ) + if (src.data == dst.data) { src.copyTo(temp); _src = &temp; } - //DEPRECATED. Allocates and initializes morphology state structure for erosion or dilation operation. - typedef IppStatus (CV_STDCALL* ippiMorphologyInitAllocFunc)(int, const void*, IppiSize, IppiPoint, IppiMorphState **); - typedef IppStatus (CV_STDCALL* ippiMorphologyBorderReplicateFunc)(const void*, int, void *, int, - IppiSize, IppiBorderType, IppiMorphState *); - typedef IppStatus (CV_STDCALL* ippiFilterMinMaxGetBufferSizeFunc)(int, IppiSize, int*); - typedef IppStatus (CV_STDCALL* ippiFilterMinMaxBorderReplicateFunc)(const void*, int, void*, int, - IppiSize, IppiSize, IppiPoint, void*); - - ippiMorphologyInitAllocFunc initAllocFunc = 0; - ippiMorphologyBorderReplicateFunc morphFunc = 0; - ippiFilterMinMaxGetBufferSizeFunc getBufSizeFunc = 0; - ippiFilterMinMaxBorderReplicateFunc morphRectFunc = 0; - - #define IPP_MORPH_CASE(type, flavor) \ - case type: \ - initAllocFunc = (ippiMorphologyInitAllocFunc)ippiMorphologyInitAlloc_##flavor; \ - morphFunc = op == MORPH_ERODE ? (ippiMorphologyBorderReplicateFunc)ippiErodeBorderReplicate_##flavor : \ - (ippiMorphologyBorderReplicateFunc)ippiDilateBorderReplicate_##flavor; \ - getBufSizeFunc = (ippiFilterMinMaxGetBufferSizeFunc)ippiFilterMinGetBufferSize_##flavor; \ - morphRectFunc = op == MORPH_ERODE ? (ippiFilterMinMaxBorderReplicateFunc)ippiFilterMinBorderReplicate_##flavor : \ - (ippiFilterMinMaxBorderReplicateFunc)ippiFilterMaxBorderReplicate_##flavor; \ - break - - switch( type ) - { - IPP_MORPH_CASE(CV_8UC1, 8u_C1R); - IPP_MORPH_CASE(CV_8UC3, 8u_C3R); - IPP_MORPH_CASE(CV_8UC4, 8u_C4R); - IPP_MORPH_CASE(CV_32FC1, 32f_C1R); - IPP_MORPH_CASE(CV_32FC3, 32f_C3R); - IPP_MORPH_CASE(CV_32FC4, 32f_C4R); - default: - return false; - } - #undef IPP_MORPH_CASE IppiSize roiSize = {src.cols, src.rows}; IppiSize kernelSize = {ksize.width, ksize.height}; - IppiPoint point = {anchor.x, anchor.y}; - if( !rectKernel && morphFunc && initAllocFunc ) + if (!rectKernel) { - IppiMorphState* pState; - if( initAllocFunc( roiSize.width, kernel.data, kernelSize, point, &pState ) < 0 ) +#if 1 + if (((kernel.cols - 1) / 2 != anchor.x) || ((kernel.rows - 1) / 2 != anchor.y)) return false; - bool is_ok = morphFunc( _src->data, (int)_src->step[0], - dst.data, (int)dst.step[0], - roiSize, ippBorderRepl, pState ) >= 0; - ippiMorphologyFree(pState); - return is_ok; + #define IPP_MORPH_CASE(cvtype, flavor, data_type) \ + case cvtype: \ + {\ + int specSize = 0, bufferSize = 0;\ + if (0 > ippiMorphologyBorderGetSize_##flavor(roiSize.width, kernelSize, &specSize, &bufferSize))\ + return false;\ + IppiMorphState *pSpec = (IppiMorphState*)ippMalloc(specSize);\ + Ipp8u *pBuffer = (Ipp8u*)ippMalloc(bufferSize);\ + if (0 > ippiMorphologyBorderInit_##flavor(roiSize.width, kernel.data, kernelSize, pSpec, pBuffer))\ + {\ + ippFree(pBuffer);\ + ippFree(pSpec);\ + return false;\ + }\ + bool ok = false;\ + if (op == MORPH_ERODE)\ + ok = (0 <= ippiErodeBorder_##flavor((Ipp##data_type *)_src->data, (int)_src->step[0], (Ipp##data_type *)dst.data, (int)dst.step[0],\ + roiSize, ippBorderRepl, 0, pSpec, pBuffer));\ + else\ + ok = (0 <= ippiDilateBorder_##flavor((Ipp##data_type *)_src->data, (int)_src->step[0], (Ipp##data_type *)dst.data, (int)dst.step[0],\ + roiSize, ippBorderRepl, 0, pSpec, pBuffer));\ + ippFree(pBuffer);\ + ippFree(pSpec);\ + return ok;\ + }\ + break; +#else + IppiPoint point = {anchor.x, anchor.y}; + // this is case, which can be used with the anchor not in center of the kernel, but + // ippiMorphologyBorderGetSize_, ippiErodeBorderReplicate_ and ippiDilateBorderReplicate_ are deprecated. + #define IPP_MORPH_CASE(cvtype, flavor, data_type) \ + case cvtype: \ + {\ + int specSize = 0;\ + int bufferSize = 0;\ + if (0 > ippiMorphologyGetSize_##flavor( roiSize.width, kernel.data kernelSize, &specSize))\ + return false;\ + bool ok = false;\ + IppiMorphState* pState = (IppiMorphState*)ippMalloc(specSize);\ + if (ippiMorphologyInit_##flavor(roiSize.width, kernel.data, kernelSize, point, pState) >= 0)\ + {\ + if (op == MORPH_ERODE)\ + ok = ippiErodeBorderReplicate_##flavor((Ipp##data_type *)_src->data, (int)_src->step[0],\ + (Ipp##data_type *)dst.data, (int)dst.step[0],\ + roiSize, ippBorderRepl, pState ) >= 0;\ + else\ + ok = ippiDilateBorderReplicate_##flavor((Ipp##data_type *)_src->data, (int)_src->step[0],\ + (Ipp##data_type *)dst.data, (int)dst.step[0],\ + roiSize, ippBorderRepl, pState ) >= 0;\ + }\ + ippFree(pState);\ + return ok;\ + }\ + break; +#endif + switch (type) + { + IPP_MORPH_CASE(CV_8UC1, 8u_C1R, 8u); + IPP_MORPH_CASE(CV_8UC3, 8u_C3R, 8u); + IPP_MORPH_CASE(CV_8UC4, 8u_C4R, 8u); + IPP_MORPH_CASE(CV_32FC1, 32f_C1R, 32f); + IPP_MORPH_CASE(CV_32FC3, 32f_C3R, 32f); + IPP_MORPH_CASE(CV_32FC4, 32f_C4R, 32f); + default: + return false; + } + + #undef IPP_MORPH_CASE } - else if( rectKernel && morphRectFunc && getBufSizeFunc ) + else { - int bufSize = 0; - if( getBufSizeFunc( src.cols, kernelSize, &bufSize) < 0 ) + IppiPoint point = {anchor.x, anchor.y}; + + #define IPP_MORPH_CASE(cvtype, flavor, data_type) \ + case cvtype: \ + {\ + int bufSize = 0;\ + if (0 > ippiFilterMinGetBufferSize_##flavor(src.cols, kernelSize, &bufSize))\ + return false;\ + AutoBuffer buf(bufSize + 64);\ + uchar* buffer = alignPtr((uchar*)buf, 32);\ + if (op == MORPH_ERODE)\ + return (0 <= ippiFilterMinBorderReplicate_##flavor((Ipp##data_type *)_src->data, (int)_src->step[0], (Ipp##data_type *)dst.data, (int)dst.step[0], roiSize, kernelSize, point, buffer));\ + return (0 <= ippiFilterMaxBorderReplicate_##flavor((Ipp##data_type *)_src->data, (int)_src->step[0], (Ipp##data_type *)dst.data, (int)dst.step[0], roiSize, kernelSize, point, buffer));\ + }\ + break; + + switch (type) + { + IPP_MORPH_CASE(CV_8UC1, 8u_C1R, 8u); + IPP_MORPH_CASE(CV_8UC3, 8u_C3R, 8u); + IPP_MORPH_CASE(CV_8UC4, 8u_C4R, 8u); + IPP_MORPH_CASE(CV_32FC1, 32f_C1R, 32f); + IPP_MORPH_CASE(CV_32FC3, 32f_C3R, 32f); + IPP_MORPH_CASE(CV_32FC4, 32f_C4R, 32f); + default: return false; - AutoBuffer buf(bufSize + 64); - uchar* buffer = alignPtr((uchar*)buf, 32); - return morphRectFunc(_src->data, (int)_src->step[0], dst.data, (int)dst.step[0], - roiSize, kernelSize, point, buffer) >= 0; + } + + #undef IPP_MORPH_CASE } - return false; } static bool IPPMorphOp(int op, InputArray _src, OutputArray _dst, @@ -1411,7 +1459,7 @@ static void morphOp( int op, InputArray _src, OutputArray _dst, Size ksize = kernel.data ? kernel.size() : Size(3,3); anchor = normalizeAnchor(anchor, ksize); -#if defined (HAVE_IPP) && (IPP_VERSION_MAJOR >= 7) +#if IPP_VERSION_X100 >= 801 if( IPPMorphOp(op, _src, _dst, kernel, anchor, iterations, borderType, borderValue) ) return; #endif diff --git a/modules/imgproc/src/smooth.cpp b/modules/imgproc/src/smooth.cpp index 6a18af5c2d..84570bd2c2 100644 --- a/modules/imgproc/src/smooth.cpp +++ b/modules/imgproc/src/smooth.cpp @@ -1109,20 +1109,27 @@ void cv::GaussianBlur( InputArray _src, OutputArray _dst, Size ksize, return; #endif -#if defined HAVE_IPP && (IPP_VERSION_MAJOR >= 7) +#if IPP_VERSION_X100 >= 801 if( type == CV_32FC1 && sigma1 == sigma2 && ksize.width == ksize.height && sigma1 != 0.0 ) { Mat src = _src.getMat(), dst = _dst.getMat(); IppiSize roi = { src.cols, src.rows }; - int bufSize = 0; - ippiFilterGaussGetBufferSize_32f_C1R(roi, ksize.width, &bufSize); - AutoBuffer buf(bufSize+128); - if( ippiFilterGaussBorder_32f_C1R((const Ipp32f *)src.data, (int)src.step, - (Ipp32f *)dst.data, (int)dst.step, - roi, ksize.width, (Ipp32f)sigma1, - (IppiBorderType)borderType, 0.0, - alignPtr(&buf[0],32)) >= 0 ) - return; + int specSize = 0, bufferSize = 0; + if (0 <= ippiFilterGaussianGetBufferSize(roi, (Ipp32u)ksize.width, ipp32f, 1, &specSize, &bufferSize)) + { + IppFilterGaussianSpec *pSpec = (IppFilterGaussianSpec*)ippMalloc(specSize); + Ipp8u *pBuffer = (Ipp8u*)ippMalloc(bufferSize); + if (0 <= ippiFilterGaussianInit(roi, (Ipp32u)ksize.width, (Ipp32f)sigma1, (IppiBorderType)borderType, ipp32f, 1, pSpec, pBuffer)) + { + IppStatus sts = ippiFilterGaussianBorder_32f_C1R( (const Ipp32f *)src.data, (int)src.step, + (Ipp32f *)dst.data, (int)dst.step, + roi, 0.0, pSpec, pBuffer); + ippFree(pBuffer); + ippFree(pSpec); + if (0 <= sts) + return; + } + } } #endif @@ -2180,11 +2187,19 @@ public: IppiSize kernel = {d, d}; IppiSize roi={dst.cols, range.end - range.start}; int bufsize=0; - ippiFilterBilateralGetBufSize_8u_C1R( ippiFilterBilateralGauss, roi, kernel, &bufsize); + if (0 > ippiFilterBilateralGetBufSize_8u_C1R( ippiFilterBilateralGauss, roi, kernel, &bufsize)) + { + *ok = false; + return; + } AutoBuffer buf(bufsize); IppiFilterBilateralSpec *pSpec = (IppiFilterBilateralSpec *)alignPtr(&buf[0], 32); - ippiFilterBilateralInit_8u_C1R( ippiFilterBilateralGauss, kernel, (Ipp32f)sigma_color, (Ipp32f)sigma_space, 1, pSpec ); - if( ippiFilterBilateral_8u_C1R( src.ptr(range.start) + radius * ((int)src.step[0] + 1), (int)src.step[0], dst.ptr(range.start), (int)dst.step[0], roi, kernel, pSpec ) < 0) + if (0 > ippiFilterBilateralInit_8u_C1R( ippiFilterBilateralGauss, kernel, (Ipp32f)sigma_color, (Ipp32f)sigma_space, 1, pSpec )) + { + *ok = false; + return; + } + if (0 > ippiFilterBilateral_8u_C1R( src.ptr(range.start) + radius * ((int)src.step[0] + 1), (int)src.step[0], dst.ptr(range.start), (int)dst.step[0], roi, kernel, pSpec )) *ok = false; } private: diff --git a/modules/imgproc/src/sumpixels.cpp b/modules/imgproc/src/sumpixels.cpp index 4e18f119fa..c32813fabd 100644 --- a/modules/imgproc/src/sumpixels.cpp +++ b/modules/imgproc/src/sumpixels.cpp @@ -365,30 +365,32 @@ void cv::integral( InputArray _src, OutputArray _sum, OutputArray _sqsum, Output #if defined (HAVE_IPP) && (IPP_VERSION_MAJOR >= 7) if( ( depth == CV_8U ) && ( sdepth == CV_32F || sdepth == CV_32S ) && ( !_tilted.needed() ) && ( !_sqsum.needed() || sqdepth == CV_64F ) && ( cn == 1 ) ) { + IppStatus status = ippStsErr; IppiSize srcRoiSize = ippiSize( src.cols, src.rows ); if( sdepth == CV_32F ) { if( _sqsum.needed() ) { - ippiSqrIntegral_8u32f64f_C1R( (const Ipp8u*)src.data, (int)src.step, (Ipp32f*)sum.data, (int)sum.step, (Ipp64f*)sqsum.data, (int)sqsum.step, srcRoiSize, 0, 0 ); + status = ippiSqrIntegral_8u32f64f_C1R( (const Ipp8u*)src.data, (int)src.step, (Ipp32f*)sum.data, (int)sum.step, (Ipp64f*)sqsum.data, (int)sqsum.step, srcRoiSize, 0, 0 ); } else { - ippiIntegral_8u32f_C1R( (const Ipp8u*)src.data, (int)src.step, (Ipp32f*)sum.data, (int)sum.step, srcRoiSize, 0 ); + status = ippiIntegral_8u32f_C1R( (const Ipp8u*)src.data, (int)src.step, (Ipp32f*)sum.data, (int)sum.step, srcRoiSize, 0 ); } } else if( sdepth == CV_32S ) { if( _sqsum.needed() ) { - ippiSqrIntegral_8u32s64f_C1R( (const Ipp8u*)src.data, (int)src.step, (Ipp32s*)sum.data, (int)sum.step, (Ipp64f*)sqsum.data, (int)sqsum.step, srcRoiSize, 0, 0 ); + status = ippiSqrIntegral_8u32s64f_C1R( (const Ipp8u*)src.data, (int)src.step, (Ipp32s*)sum.data, (int)sum.step, (Ipp64f*)sqsum.data, (int)sqsum.step, srcRoiSize, 0, 0 ); } else { - ippiIntegral_8u32s_C1R( (const Ipp8u*)src.data, (int)src.step, (Ipp32s*)sum.data, (int)sum.step, srcRoiSize, 0 ); + status = ippiIntegral_8u32s_C1R( (const Ipp8u*)src.data, (int)src.step, (Ipp32s*)sum.data, (int)sum.step, srcRoiSize, 0 ); } } - return; + if (0 <= status) + return; } #endif diff --git a/modules/imgproc/test/ocl/test_histogram.cpp b/modules/imgproc/test/ocl/test_histogram.cpp index 0a27907b63..c13556b301 100644 --- a/modules/imgproc/test/ocl/test_histogram.cpp +++ b/modules/imgproc/test/ocl/test_histogram.cpp @@ -13,6 +13,7 @@ // Copyright (C) 2010-2012, Institute Of Software Chinese Academy Of Science, all rights reserved. // Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved. // Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved. +// Copyright (C) 2014, Itseez, Inc., all rights reserved. // Third party copyrights are property of their respective owners. // // @Authors @@ -144,6 +145,37 @@ PARAM_TEST_CASE(CalcBackProject, MatDepth, int, bool) scale = randomDouble(0.1, 1); } + + virtual void test_by_pict() + { + Mat frame1 = readImage("optflow/RubberWhale1.png", IMREAD_GRAYSCALE); + + UMat usrc; + frame1.copyTo(usrc); + int histSize = randomInt(3, 29); + float hue_range[] = { 0, 180 }; + const float* ranges1 = { hue_range }; + Mat hist1; + + //compute histogram + calcHist(&frame1, 1, 0, Mat(), hist1, 1, &histSize, &ranges1, true, false); + normalize(hist1, hist1, 0, 255, NORM_MINMAX, -1, Mat()); + + Mat dst1; + UMat udst1, src, uhist1; + hist1.copyTo(uhist1); + std::vector uims; + uims.push_back(usrc); + std::vector urngs; + urngs.push_back(0); + urngs.push_back(180); + std::vector chs; + chs.push_back(0); + + OCL_OFF(calcBackProject(&frame1, 1, 0, hist1, dst1, &ranges1, 1, true)); + OCL_ON(calcBackProject(uims, chs, uhist1, udst1, urngs, 1.0)); + EXPECT_MAT_NEAR(dst1, udst1, 0.0); + } }; //////////////////////////////// CalcBackProject ////////////////////////////////////////////// @@ -157,7 +189,14 @@ OCL_TEST_P(CalcBackProject, Mat) OCL_OFF(cv::calcBackProject(images_roi, channels, hist_roi, dst_roi, ranges, scale)); OCL_ON(cv::calcBackProject(uimages_roi, channels, uhist_roi, udst_roi, ranges, scale)); - OCL_EXPECT_MATS_NEAR(dst, 0.0); + Size dstSize = dst_roi.size(); + int nDiffs = (int)(0.03f*dstSize.height*dstSize.width); + + //check if the dst mats are the same except 3% difference + EXPECT_MAT_N_DIFF(dst_roi, udst_roi, nDiffs); + + //check in addition on given image + test_by_pict(); } } diff --git a/modules/imgproc/test/test_bilateral_filter.cpp b/modules/imgproc/test/test_bilateral_filter.cpp index 0bfc3dc4cc..ba4c9d57b8 100644 --- a/modules/imgproc/test/test_bilateral_filter.cpp +++ b/modules/imgproc/test/test_bilateral_filter.cpp @@ -264,7 +264,7 @@ namespace cvtest reference_dst.convertTo(reference_dst, type); } - double e = norm(reference_dst, _parallel_dst); + double e = cvtest::norm(reference_dst, _parallel_dst, NORM_L2); if (e > eps) { ts->printf(cvtest::TS::CONSOLE, "actual error: %g, expected: %g", e, eps); diff --git a/modules/imgproc/test/test_connectedcomponents.cpp b/modules/imgproc/test/test_connectedcomponents.cpp index a9567da970..dd4d8339a0 100644 --- a/modules/imgproc/test/test_connectedcomponents.cpp +++ b/modules/imgproc/test/test_connectedcomponents.cpp @@ -91,12 +91,12 @@ void CV_ConnectedComponentsTest::run( int /* start_from */) exp = labelImage; } - if (0 != norm(labelImage > 0, exp > 0, NORM_INF)) + if (0 != cvtest::norm(labelImage > 0, exp > 0, NORM_INF)) { ts->set_failed_test_info( cvtest::TS::FAIL_MISMATCH ); return; } - if (nLabels != norm(labelImage, NORM_INF)+1) + if (nLabels != cvtest::norm(labelImage, NORM_INF)+1) { ts->set_failed_test_info( cvtest::TS::FAIL_MISMATCH ); return; diff --git a/modules/imgproc/test/test_convhull.cpp b/modules/imgproc/test/test_convhull.cpp index 2b6169cf5b..6b5144f924 100644 --- a/modules/imgproc/test/test_convhull.cpp +++ b/modules/imgproc/test/test_convhull.cpp @@ -566,6 +566,8 @@ int CV_ConvHullTest::validate_test_results( int test_case_idx ) hull = cvCreateMat( 1, hull_count, CV_32FC2 ); mask = cvCreateMat( 1, hull_count, CV_8UC1 ); cvZero( mask ); + Mat _mask = cvarrToMat(mask); + h = (CvPoint2D32f*)(hull->data.ptr); // extract convex hull points @@ -643,7 +645,7 @@ int CV_ConvHullTest::validate_test_results( int test_case_idx ) mask->data.ptr[idx] = (uchar)1; } - if( cvNorm( mask, 0, CV_L1 ) != hull_count ) + if( cvtest::norm( _mask, Mat::zeros(_mask.dims, _mask.size, _mask.type()), NORM_L1 ) != hull_count ) { ts->printf( cvtest::TS::LOG, "Not every convex hull vertex coincides with some input point\n" ); code = cvtest::TS::FAIL_BAD_ACCURACY; diff --git a/modules/imgproc/test/test_houghLines.cpp b/modules/imgproc/test/test_houghLines.cpp index fa9ecafef0..660b3dd583 100644 --- a/modules/imgproc/test/test_houghLines.cpp +++ b/modules/imgproc/test/test_houghLines.cpp @@ -137,7 +137,7 @@ void CV_HoughLinesTest::run_test(int type) if( exp_lines.size != lines.size ) transpose(lines, lines); - if ( exp_lines.size != lines.size || norm(exp_lines, lines, NORM_INF) > 1e-4 ) + if ( exp_lines.size != lines.size || cvtest::norm(exp_lines, lines, NORM_INF) > 1e-4 ) { ts->set_failed_test_info(cvtest::TS::FAIL_MISMATCH); return; diff --git a/modules/imgproc/test/test_imgwarp.cpp b/modules/imgproc/test/test_imgwarp.cpp index 53f7d5c2fc..b0897483a2 100644 --- a/modules/imgproc/test/test_imgwarp.cpp +++ b/modules/imgproc/test/test_imgwarp.cpp @@ -1530,7 +1530,7 @@ TEST(Imgproc_resize_area, regression) } } - ASSERT_EQ(norm(one_channel_diff, cv::NORM_INF), 0); + ASSERT_EQ(cvtest::norm(one_channel_diff, cv::NORM_INF), 0); } diff --git a/modules/imgproc/test/test_imgwarp_strict.cpp b/modules/imgproc/test/test_imgwarp_strict.cpp index 76d65b198b..07c5e0cc85 100644 --- a/modules/imgproc/test/test_imgwarp_strict.cpp +++ b/modules/imgproc/test/test_imgwarp_strict.cpp @@ -254,7 +254,7 @@ void CV_ImageWarpBaseTest::validate_results() const // fabs(rD[dx] - D[dx]) < 250.0f && rD[dx] <= 255.0f && D[dx] <= 255.0f && rD[dx] >= 0.0f && D[dx] >= 0.0f) { - PRINT_TO_LOG("\nNorm of the difference: %lf\n", norm(reference_dst, _dst, NORM_INF)); + PRINT_TO_LOG("\nNorm of the difference: %lf\n", cvtest::norm(reference_dst, _dst, NORM_INF)); PRINT_TO_LOG("Error in (dx, dy): (%d, %d)\n", dx / cn + 1, dy + 1); PRINT_TO_LOG("Tuple (rD, D): (%f, %f)\n", rD[dx], D[dx]); PRINT_TO_LOG("Dsize: (%d, %d)\n", dsize.width / cn, dsize.height); diff --git a/modules/java/generator/src/java/android+OpenCVLoader.java b/modules/java/generator/src/java/android+OpenCVLoader.java index 0892e3af3c..13cd428494 100644 --- a/modules/java/generator/src/java/android+OpenCVLoader.java +++ b/modules/java/generator/src/java/android+OpenCVLoader.java @@ -42,6 +42,11 @@ public class OpenCVLoader */ public static final String OPENCV_VERSION_2_4_8 = "2.4.8"; + /** + * OpenCV Library version 2.4.9. + */ + public static final String OPENCV_VERSION_2_4_9 = "2.4.9"; + /** * Loads and initializes OpenCV library from current application package. Roughly, it's an analog of system.loadLibrary("opencv_java"). * @return Returns true is initialization of OpenCV was successful. diff --git a/modules/legacy/src/blobtrackanalysishist.cpp b/modules/legacy/src/blobtrackanalysishist.cpp index 0e349f9f4e..c75c954912 100644 --- a/modules/legacy/src/blobtrackanalysishist.cpp +++ b/modules/legacy/src/blobtrackanalysishist.cpp @@ -730,12 +730,12 @@ private: m_pFViVarRes = (int*)cvAlloc(sizeof(int)*m_Dim); m_Sizes = (int*)cvAlloc(sizeof(int)*m_Dim); - { /* Create init sparce matrix: */ + { /* Create init sparse matrix: */ int i; for(i=0;iget_var_types(); bool is_classifier = var_types->data.ptr[var_types->cols-1] == CV_VAR_CATEGORICAL; - if( ( fabs( cvNorm( var_types, 0, CV_L1 ) - + + Mat _var_types = cvarrToMat(var_types); + if( ( fabs( cvtest::norm( _var_types, Mat::zeros(_var_types.dims, _var_types.size, _var_types.type()), CV_L1 ) - (var_types->rows + var_types->cols - 2)*CV_VAR_ORDERED - CV_VAR_CATEGORICAL ) > FLT_EPSILON ) || !is_classifier ) CV_Error( CV_StsBadArg, "incorrect types of predictors or responses" ); diff --git a/modules/ml/test/test_save_load.cpp b/modules/ml/test/test_save_load.cpp index 7300185b4d..8b58ce534a 100644 --- a/modules/ml/test/test_save_load.cpp +++ b/modules/ml/test/test_save_load.cpp @@ -184,8 +184,8 @@ TEST(DISABLED_ML_SVM, linear_save_load) svm3.predict(samples, r3); double eps = 1e-4; - EXPECT_LE(norm(r1, r2, NORM_INF), eps); - EXPECT_LE(norm(r1, r3, NORM_INF), eps); + EXPECT_LE(cvtest::norm(r1, r2, NORM_INF), eps); + EXPECT_LE(cvtest::norm(r1, r3, NORM_INF), eps); remove(tname.c_str()); } diff --git a/modules/objdetect/src/haar.cpp b/modules/objdetect/src/haar.cpp index 2f864797fb..4b2d2b0d51 100644 --- a/modules/objdetect/src/haar.cpp +++ b/modules/objdetect/src/haar.cpp @@ -1318,9 +1318,9 @@ public: if( cascade->hid_cascade->ipp_stages ) { IppiRect iequRect = {equRect.x, equRect.y, equRect.width, equRect.height}; - ippiRectStdDev_32f_C1R(sum1.ptr(y1), sum1.step, - sqsum1.ptr(y1), sqsum1.step, - norm1->ptr(y1), norm1->step, + ippiRectStdDev_32f_C1R(sum1.ptr(y1), (int)sum1.step, + sqsum1.ptr(y1), (int)sqsum1.step, + norm1->ptr(y1), (int)norm1->step, ippiSize(ssz.width, ssz.height), iequRect ); int positive = (ssz.width/ystep)*((ssz.height + ystep-1)/ystep); @@ -1341,9 +1341,9 @@ public: for( int j = 0; j < cascade->count; j++ ) { if( ippiApplyHaarClassifier_32f_C1R( - sum1.ptr(y1), sum1.step, - norm1->ptr(y1), norm1->step, - mask1->ptr(y1), mask1->step, + sum1.ptr(y1), (int)sum1.step, + norm1->ptr(y1), (int)norm1->step, + mask1->ptr(y1), (int)mask1->step, ippiSize(ssz.width, ssz.height), &positive, cascade->hid_cascade->stage_classifier[j].threshold, (IppiHaarClassifier_32f*)cascade->hid_cascade->ipp_stages[j]) < 0 ) diff --git a/modules/objdetect/test/test_cascadeandhog.cpp b/modules/objdetect/test/test_cascadeandhog.cpp index 746a48ca97..4a311e49e9 100644 --- a/modules/objdetect/test/test_cascadeandhog.cpp +++ b/modules/objdetect/test/test_cascadeandhog.cpp @@ -1087,7 +1087,7 @@ void HOGDescriptorTester::detect(const Mat& img, } const double eps = 0.0; - double diff_norm = norm(Mat(actual_weights) - Mat(weights), NORM_L2); + double diff_norm = cvtest::norm(actual_weights, weights, NORM_L2); if (diff_norm > eps) { ts->printf(cvtest::TS::SUMMARY, "Weights for found locations aren't equal.\n" @@ -1168,7 +1168,7 @@ void HOGDescriptorTester::compute(InputArray _img, vector& descriptors, std::vector actual_descriptors; actual_hog->compute(img, actual_descriptors, winStride, padding, locations); - double diff_norm = cv::norm(Mat(actual_descriptors) - Mat(descriptors), NORM_L2); + double diff_norm = cvtest::norm(actual_descriptors, descriptors, NORM_L2); const double eps = 0.0; if (diff_norm > eps) { @@ -1318,7 +1318,7 @@ void HOGDescriptorTester::computeGradient(const Mat& img, Mat& grad, Mat& qangle const double eps = 0.0; for (i = 0; i < 2; ++i) { - double diff_norm = norm(reference_mats[i] - actual_mats[i], NORM_L2); + double diff_norm = cvtest::norm(reference_mats[i], actual_mats[i], NORM_L2); if (diff_norm > eps) { ts->printf(cvtest::TS::LOG, "%s matrices are not equal\n" diff --git a/modules/ts/include/opencv2/ts.hpp b/modules/ts/include/opencv2/ts.hpp index 8febfca9c8..457f00b3e2 100644 --- a/modules/ts/include/opencv2/ts.hpp +++ b/modules/ts/include/opencv2/ts.hpp @@ -47,6 +47,8 @@ using cv::Scalar; using cv::Size; using cv::Point; using cv::Rect; +using cv::InputArray; +using cv::noArray; class CV_EXPORTS TS; @@ -124,8 +126,8 @@ CV_EXPORTS void initUndistortMap( const Mat& a, const Mat& k, Size sz, Mat& mapx CV_EXPORTS void minMaxLoc(const Mat& src, double* minval, double* maxval, vector* minloc, vector* maxloc, const Mat& mask=Mat()); -CV_EXPORTS double norm(const Mat& src, int normType, const Mat& mask=Mat()); -CV_EXPORTS double norm(const Mat& src1, const Mat& src2, int normType, const Mat& mask=Mat()); +CV_EXPORTS double norm(InputArray src, int normType, InputArray mask=noArray()); +CV_EXPORTS double norm(InputArray src1, InputArray src2, int normType, InputArray mask=noArray()); CV_EXPORTS Scalar mean(const Mat& src, const Mat& mask=Mat()); CV_EXPORTS bool cmpUlps(const Mat& data, const Mat& refdata, int expMaxDiff, double* realMaxDiff, vector* idx); diff --git a/modules/ts/include/opencv2/ts/ocl_test.hpp b/modules/ts/include/opencv2/ts/ocl_test.hpp index 0f0d9657fe..5dd25dba4f 100644 --- a/modules/ts/include/opencv2/ts/ocl_test.hpp +++ b/modules/ts/include/opencv2/ts/ocl_test.hpp @@ -85,6 +85,17 @@ do \ << "Size: " << mat1.size() << std::endl; \ } while ((void)0, 0) +#define EXPECT_MAT_N_DIFF(mat1, mat2, num) \ +do \ +{ \ + ASSERT_EQ(mat1.type(), mat2.type()); \ + ASSERT_EQ(mat1.size(), mat2.size()); \ + Mat diff; \ + absdiff(mat1, mat2, diff); \ + EXPECT_LE(countNonZero(diff.reshape(1)), num) \ + << "Size: " << mat1.size() << std::endl; \ +} while ((void)0, 0) + #define OCL_EXPECT_MATS_NEAR(name, eps) \ do \ { \ @@ -232,9 +243,9 @@ struct CV_EXPORTS TestUtils static inline double checkNormRelative(InputArray m1, InputArray m2, InputArray mask = noArray()) { - return cv::norm(m1.getMat(), m2.getMat(), cv::NORM_INF, mask) / + return cvtest::norm(m1.getMat(), m2.getMat(), cv::NORM_INF, mask) / std::max((double)std::numeric_limits::epsilon(), - (double)std::max(cv::norm(m1.getMat(), cv::NORM_INF), norm(m2.getMat(), cv::NORM_INF))); + (double)std::max(cvtest::norm(m1.getMat(), cv::NORM_INF), cvtest::norm(m2.getMat(), cv::NORM_INF))); } }; diff --git a/modules/ts/src/ocl_test.cpp b/modules/ts/src/ocl_test.cpp index 0291cadbed..a2a75cf888 100644 --- a/modules/ts/src/ocl_test.cpp +++ b/modules/ts/src/ocl_test.cpp @@ -225,12 +225,12 @@ Mat TestUtils::readImageType(const String &fname, int type) double TestUtils::checkNorm1(InputArray m, InputArray mask) { - return norm(m.getMat(), NORM_INF, mask); + return cvtest::norm(m.getMat(), NORM_INF, mask.getMat()); } double TestUtils::checkNorm2(InputArray m1, InputArray m2, InputArray mask) { - return norm(m1.getMat(), m2.getMat(), NORM_INF, mask); + return cvtest::norm(m1.getMat(), m2.getMat(), NORM_INF, mask.getMat()); } double TestUtils::checkSimilarity(InputArray m1, InputArray m2) diff --git a/modules/ts/src/ts_func.cpp b/modules/ts/src/ts_func.cpp index 89c91b98f1..e3563caa4f 100644 --- a/modules/ts/src/ts_func.cpp +++ b/modules/ts/src/ts_func.cpp @@ -1238,15 +1238,16 @@ norm_(const _Tp* src1, const _Tp* src2, size_t total, int cn, int normType, doub } -double norm(const Mat& src, int normType, const Mat& mask) +double norm(InputArray _src, int normType, InputArray _mask) { + Mat src = _src.getMat(), mask = _mask.getMat(); if( normType == NORM_HAMMING || normType == NORM_HAMMING2 ) { if( !mask.empty() ) { Mat temp; bitwise_and(src, mask, temp); - return norm(temp, normType, Mat()); + return cvtest::norm(temp, normType, Mat()); } CV_Assert( src.depth() == CV_8U ); @@ -1317,8 +1318,12 @@ double norm(const Mat& src, int normType, const Mat& mask) } -double norm(const Mat& src1, const Mat& src2, int normType, const Mat& mask) +double norm(InputArray _src1, InputArray _src2, int normType, InputArray _mask) { + Mat src1 = _src1.getMat(), src2 = _src2.getMat(), mask = _mask.getMat(); + bool isRelative = (normType & NORM_RELATIVE) != 0; + normType &= ~NORM_RELATIVE; + if( normType == NORM_HAMMING || normType == NORM_HAMMING2 ) { Mat temp; @@ -1391,7 +1396,7 @@ double norm(const Mat& src1, const Mat& src2, int normType, const Mat& mask) } if( normType0 == NORM_L2 ) result = sqrt(result); - return result; + return isRelative ? result / (cvtest::norm(src2, normType) + DBL_EPSILON) : result; } diff --git a/modules/video/src/lkpyramid.cpp b/modules/video/src/lkpyramid.cpp index a33e47664d..5b653c9d1c 100644 --- a/modules/video/src/lkpyramid.cpp +++ b/modules/video/src/lkpyramid.cpp @@ -987,7 +987,7 @@ namespace cv idxArg = kernel.set(idxArg, (int)winSize.height); // int c_winSize_y idxArg = kernel.set(idxArg, (int)iters); // int c_iters idxArg = kernel.set(idxArg, (char)calcErr); //char calcErr - return kernel.run(2, globalThreads, localThreads, true); + return kernel.run(2, globalThreads, localThreads, false); } private: inline static bool isDeviceCPU() diff --git a/modules/video/src/opencl/pyrlk.cl b/modules/video/src/opencl/pyrlk.cl index 822e628f25..cf401057d4 100644 --- a/modules/video/src/opencl/pyrlk.cl +++ b/modules/video/src/opencl/pyrlk.cl @@ -45,11 +45,15 @@ // //M*/ -#define BUFFER 64 -#define BUFFER2 BUFFER>>1 +#define GRIDSIZE 3 +#define LSx 8 +#define LSy 8 +#define BUFFER (LSx*LSy) +#define BUFFER2 BUFFER>>1 #ifndef WAVE_SIZE #define WAVE_SIZE 1 #endif + #ifdef CPU inline void reduce3(float val1, float val2, float val3, __local float* smem1, __local float* smem2, __local float* smem3, int tid) @@ -128,24 +132,21 @@ inline void reduce3(float val1, float val2, float val3, #if WAVE_SIZE <16 } barrier(CLK_LOCAL_MEM_FENCE); - if (tid < 8) + if (tid<1) { #endif - smem1[tid] += smem1[tid + 8]; - smem2[tid] += smem2[tid + 8]; - smem3[tid] += smem3[tid + 8]; - - smem1[tid] += smem1[tid + 4]; - smem2[tid] += smem2[tid + 4]; - smem3[tid] += smem3[tid + 4]; - - smem1[tid] += smem1[tid + 2]; - smem2[tid] += smem2[tid + 2]; - smem3[tid] += smem3[tid + 2]; - - smem1[tid] += smem1[tid + 1]; - smem2[tid] += smem2[tid + 1]; - smem3[tid] += smem3[tid + 1]; + local float8* m1 = (local float8*)smem1; + local float8* m2 = (local float8*)smem2; + local float8* m3 = (local float8*)smem3; + float8 t1 = m1[0]+m1[1]; + float8 t2 = m2[0]+m2[1]; + float8 t3 = m3[0]+m3[1]; + float4 t14 = t1.lo + t1.hi; + float4 t24 = t2.lo + t2.hi; + float4 t34 = t3.lo + t3.hi; + smem1[0] = t14.x+t14.y+t14.z+t14.w; + smem2[0] = t24.x+t24.y+t24.z+t24.w; + smem3[0] = t34.x+t34.y+t34.z+t34.w; } barrier(CLK_LOCAL_MEM_FENCE); } @@ -171,20 +172,17 @@ inline void reduce2(float val1, float val2, __local volatile float* smem1, __loc #if WAVE_SIZE <16 } barrier(CLK_LOCAL_MEM_FENCE); - if (tid < 8) + if (tid<1) { #endif - smem1[tid] += smem1[tid + 8]; - smem2[tid] += smem2[tid + 8]; - - smem1[tid] += smem1[tid + 4]; - smem2[tid] += smem2[tid + 4]; - - smem1[tid] += smem1[tid + 2]; - smem2[tid] += smem2[tid + 2]; - - smem1[tid] += smem1[tid + 1]; - smem2[tid] += smem2[tid + 1]; + local float8* m1 = (local float8*)smem1; + local float8* m2 = (local float8*)smem2; + float8 t1 = m1[0]+m1[1]; + float8 t2 = m2[0]+m2[1]; + float4 t14 = t1.lo + t1.hi; + float4 t24 = t2.lo + t2.hi; + smem1[0] = t14.x+t14.y+t14.z+t14.w; + smem2[0] = t24.x+t24.y+t24.z+t24.w; } barrier(CLK_LOCAL_MEM_FENCE); } @@ -207,13 +205,13 @@ inline void reduce1(float val1, __local volatile float* smem1, int tid) #if WAVE_SIZE <16 } barrier(CLK_LOCAL_MEM_FENCE); - if (tid < 8) + if (tid<1) { #endif - smem1[tid] += smem1[tid + 8]; - smem1[tid] += smem1[tid + 4]; - smem1[tid] += smem1[tid + 2]; - smem1[tid] += smem1[tid + 1]; + local float8* m1 = (local float8*)smem1; + float8 t1 = m1[0]+m1[1]; + float4 t14 = t1.lo + t1.hi; + smem1[0] = t14.x+t14.y+t14.z+t14.w; } barrier(CLK_LOCAL_MEM_FENCE); } @@ -225,18 +223,21 @@ inline void reduce1(float val1, __local volatile float* smem1, int tid) // Image read mode __constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_LINEAR; -inline void SetPatch(image2d_t I, float x, float y, +// macro to get pixel value from local memory +#define VAL(_y,_x,_yy,_xx) (IPatchLocal[yid+((_y)*LSy)+1+(_yy)][xid+((_x)*LSx)+1+(_xx)]) +inline void SetPatch(local float IPatchLocal[LSy*GRIDSIZE+2][LSx*GRIDSIZE+2], int TileY, int TileX, float* Pch, float* Dx, float* Dy, - float* A11, float* A12, float* A22) + float* A11, float* A12, float* A22, float w) { - *Pch = read_imagef(I, sampler, (float2)(x, y)).x; + unsigned int xid=get_local_id(0); + unsigned int yid=get_local_id(1); + *Pch = VAL(TileY,TileX,0,0); - float dIdx = 3.0f * read_imagef(I, sampler, (float2)(x + 1, y - 1)).x + 10.0f * read_imagef(I, sampler, (float2)(x + 1, y)).x + 3.0f * read_imagef(I, sampler, (float2)(x + 1, y + 1)).x - - (3.0f * read_imagef(I, sampler, (float2)(x - 1, y - 1)).x + 10.0f * read_imagef(I, sampler, (float2)(x - 1, y)).x + 3.0f * read_imagef(I, sampler, (float2)(x - 1, y + 1)).x); - - float dIdy = 3.0f * read_imagef(I, sampler, (float2)(x - 1, y + 1)).x + 10.0f * read_imagef(I, sampler, (float2)(x, y + 1)).x + 3.0f * read_imagef(I, sampler, (float2)(x + 1, y + 1)).x - - (3.0f * read_imagef(I, sampler, (float2)(x - 1, y - 1)).x + 10.0f * read_imagef(I, sampler, (float2)(x, y - 1)).x + 3.0f * read_imagef(I, sampler, (float2)(x + 1, y - 1)).x); + float dIdx = (3.0f*VAL(TileY,TileX,-1,1)+10.0f*VAL(TileY,TileX,0,1)+3.0f*VAL(TileY,TileX,+1,1))-(3.0f*VAL(TileY,TileX,-1,-1)+10.0f*VAL(TileY,TileX,0,-1)+3.0f*VAL(TileY,TileX,+1,-1)); + float dIdy = (3.0f*VAL(TileY,TileX,1,-1)+10.0f*VAL(TileY,TileX,1,0)+3.0f*VAL(TileY,TileX,1,+1))-(3.0f*VAL(TileY,TileX,-1,-1)+10.0f*VAL(TileY,TileX,-1,0)+3.0f*VAL(TileY,TileX,-1,+1)); + dIdx *= w; + dIdy *= w; *Dx = dIdx; *Dy = dIdy; @@ -245,6 +246,7 @@ inline void SetPatch(image2d_t I, float x, float y, *A12 += dIdx * dIdy; *A22 += dIdy * dIdy; } +#undef VAL inline void GetPatch(image2d_t J, float x, float y, float* Pch, float* Dx, float* Dy, @@ -262,7 +264,38 @@ inline void GetError(image2d_t J, const float x, const float y, const float* Pch *errval += fabs(diff); } -#define GRIDSIZE 3 + +//macro to read pixel value into local memory. +#define READI(_y,_x) IPatchLocal[yid+((_y)*LSy)][xid+((_x)*LSx)] = read_imagef(I, sampler, (float2)(Point.x + xid+(_x)*LSx + 0.5f-1, Point.y + yid+(_y)*LSy+ 0.5f-1)).x; +void ReadPatchIToLocalMem(image2d_t I, float2 Point, local float IPatchLocal[LSy*GRIDSIZE+2][LSx*GRIDSIZE+2]) +{ + unsigned int xid=get_local_id(0); + unsigned int yid=get_local_id(1); + //read (3*LSx)*(3*LSy) window. each macro call read LSx*LSy pixels block + READI(0,0);READI(0,1);READI(0,2); + READI(1,0);READI(1,1);READI(1,2); + READI(2,0);READI(2,1);READI(2,2); + if(xid<2) + {// read last 2 columns border. each macro call reads 2*LSy pixels block + READI(0,3); + READI(1,3); + READI(2,3); + } + + if(yid<2) + {// read last 2 row. each macro call reads LSx*2 pixels block + READI(3,0);READI(3,1);READI(3,2); + } + + if(yid<2 && xid<2) + {// read right bottom 2x2 corner. one macro call reads 2*2 pixels block + READI(3,3); + } + barrier(CLK_LOCAL_MEM_FENCE); +} +#undef READI + +__attribute__((reqd_work_group_size(LSx, LSy, 1))) __kernel void lkSparse(image2d_t I, image2d_t J, __global const float2* prevPts, __global float2* nextPts, __global uchar* status, __global float* err, const int level, const int rows, const int cols, int PATCH_X, int PATCH_Y, int c_winSize_x, int c_winSize_y, int c_iters, char calcErr) @@ -277,6 +310,8 @@ __kernel void lkSparse(image2d_t I, image2d_t J, unsigned int xsize=get_local_size(0); unsigned int ysize=get_local_size(1); int xBase, yBase, k; + float wx = ((xid+2*xsize)>1, (c_winSize_y - 1)>>1); @@ -305,65 +340,54 @@ __kernel void lkSparse(image2d_t I, image2d_t J, float dIdx_patch[GRIDSIZE][GRIDSIZE]; float dIdy_patch[GRIDSIZE][GRIDSIZE]; - yBase=yid; + // local memory to read image with border to calc sobels + local float IPatchLocal[LSy*GRIDSIZE+2][LSx*GRIDSIZE+2]; + ReadPatchIToLocalMem(I,prevPt,IPatchLocal); + { - xBase=xid; - SetPatch(I, prevPt.x + xBase + 0.5f, prevPt.y + yBase + 0.5f, + SetPatch(IPatchLocal, 0, 0, &I_patch[0][0], &dIdx_patch[0][0], &dIdy_patch[0][0], - &A11, &A12, &A22); + &A11, &A12, &A22,1); - xBase+=xsize; - SetPatch(I, prevPt.x + xBase + 0.5f, prevPt.y + yBase + 0.5f, + SetPatch(IPatchLocal, 0, 1, &I_patch[0][1], &dIdx_patch[0][1], &dIdy_patch[0][1], - &A11, &A12, &A22); + &A11, &A12, &A22,1); - xBase+=xsize; - if(xBase + android:versionCode="218@ANDROID_PLATFORM_VERSION_CODE@" + android:versionName="2.18" > diff --git a/platforms/android/service/engine/jni/BinderComponent/OpenCVEngine.cpp b/platforms/android/service/engine/jni/BinderComponent/OpenCVEngine.cpp index 359906406e..2b113b4e22 100644 --- a/platforms/android/service/engine/jni/BinderComponent/OpenCVEngine.cpp +++ b/platforms/android/service/engine/jni/BinderComponent/OpenCVEngine.cpp @@ -15,7 +15,7 @@ using namespace android; const int OpenCVEngine::Platform = DetectKnownPlatforms(); const int OpenCVEngine::CpuID = GetCpuID(); -const int OpenCVEngine::KnownVersions[] = {2040000, 2040100, 2040200, 2040300, 2040301, 2040302, 2040400, 2040500, 2040600, 2040700, 2040701, 2040800}; +const int OpenCVEngine::KnownVersions[] = {2040000, 2040100, 2040200, 2040300, 2040301, 2040302, 2040400, 2040500, 2040600, 2040700, 2040701, 2040800, 2040900}; bool OpenCVEngine::ValidateVersion(int version) { diff --git a/platforms/android/service/engine/src/org/opencv/engine/manager/ManagerActivity.java b/platforms/android/service/engine/src/org/opencv/engine/manager/ManagerActivity.java index 8d40242033..0cd2fd58ef 100644 --- a/platforms/android/service/engine/src/org/opencv/engine/manager/ManagerActivity.java +++ b/platforms/android/service/engine/src/org/opencv/engine/manager/ManagerActivity.java @@ -117,7 +117,7 @@ public class ManagerActivity extends Activity } else { - HardwarePlatformView.setText("Tegra 5"); + HardwarePlatformView.setText("Tegra K1"); } } else diff --git a/platforms/android/service/readme.txt b/platforms/android/service/readme.txt index 65678093de..51853c24e5 100644 --- a/platforms/android/service/readme.txt +++ b/platforms/android/service/readme.txt @@ -14,20 +14,20 @@ manually using adb tool: .. code-block:: sh - adb install OpenCV-2.4.8-android-sdk/apk/OpenCV_2.4.8_Manager_2.16_.apk + adb install OpenCV-2.4.9-android-sdk/apk/OpenCV_2.4.9_Manager_2.18_.apk Use the table below to determine proper OpenCV Manager package for your device: +------------------------------+--------------+----------------------------------------------------+ | Hardware Platform | Android ver. | Package name | +==============================+==============+====================================================+ -| armeabi-v7a (ARMv7-A + NEON) | >= 2.3 | OpenCV_2.4.8_Manager_2.16_armv7a-neon.apk | +| armeabi-v7a (ARMv7-A + NEON) | >= 2.3 | OpenCV_2.4.9_Manager_2.18_armv7a-neon.apk | +------------------------------+--------------+----------------------------------------------------+ -| armeabi-v7a (ARMv7-A + NEON) | = 2.2 | OpenCV_2.4.8_Manager_2.16_armv7a-neon-android8.apk | +| armeabi-v7a (ARMv7-A + NEON) | = 2.2 | OpenCV_2.4.9_Manager_2.18_armv7a-neon-android8.apk | +------------------------------+--------------+----------------------------------------------------+ -| armeabi (ARMv5, ARMv6) | >= 2.3 | OpenCV_2.4.8_Manager_2.16_armeabi.apk | +| armeabi (ARMv5, ARMv6) | >= 2.3 | OpenCV_2.4.9_Manager_2.18_armeabi.apk | +------------------------------+--------------+----------------------------------------------------+ -| Intel x86 | >= 2.3 | OpenCV_2.4.8_Manager_2.16_x86.apk | +| Intel x86 | >= 2.3 | OpenCV_2.4.9_Manager_2.18_x86.apk | +------------------------------+--------------+----------------------------------------------------+ -| MIPS | >= 2.3 | OpenCV_2.4.8_Manager_2.16_mips.apk | +| MIPS | >= 2.3 | OpenCV_2.4.9_Manager_2.18_mips.apk | +------------------------------+--------------+----------------------------------------------------+ diff --git a/samples/cpp/tutorial_code/core/ippasync/ippasync_sample.cpp b/samples/cpp/tutorial_code/core/ippasync/ippasync_sample.cpp new file mode 100644 index 0000000000..0cfc5e6932 --- /dev/null +++ b/samples/cpp/tutorial_code/core/ippasync/ippasync_sample.cpp @@ -0,0 +1,168 @@ +#include + +#include "opencv2/core/utility.hpp" +#include "opencv2/imgproc.hpp" +#include "opencv2/highgui.hpp" +#include "cvconfig.h" + +using namespace std; +using namespace cv; + +#ifdef HAVE_IPP_A +#include "opencv2/core/ippasync.hpp" + +#define CHECK_STATUS(STATUS, NAME)\ + if(STATUS!=HPP_STATUS_NO_ERROR){ printf("%s error %d\n", NAME, STATUS);\ + if (virtMatrix) {hppStatus delSts = hppiDeleteVirtualMatrices(accel, virtMatrix); CHECK_DEL_STATUS(delSts,"hppiDeleteVirtualMatrices");}\ + if (accel) {hppStatus delSts = hppDeleteInstance(accel); CHECK_DEL_STATUS(delSts, "hppDeleteInstance");}\ + return -1;} + +#define CHECK_DEL_STATUS(STATUS, NAME)\ + if(STATUS!=HPP_STATUS_NO_ERROR){ printf("%s error %d\n", NAME, STATUS); return -1;} + +#endif + +static void help() +{ + printf("\nThis program shows how to use the conversion for IPP Async.\n" +"This example uses the Sobel filter.\n" +"You can use cv::Sobel or hppiSobel.\n" +"Usage: \n" +"./ipp_async_sobel [--camera]=, \n" +" [--file_name]=\n" +" [--accel]=\n\n"); +} + +const char* keys = +{ + "{c camera | | use camera or not}" + "{fn file_name|baboon.jpg | image file }" + "{a accel |auto | accelerator type: auto (default), cpu, gpu}" +}; + +//this is a sample for hppiSobel functions +int main(int argc, const char** argv) +{ + help(); + + VideoCapture cap; + CommandLineParser parser(argc, argv, keys); + Mat image, gray, result; + +#ifdef HAVE_IPP_A + + hppiMatrix* src,* dst; + hppAccel accel = 0; + hppAccelType accelType; + hppStatus sts; + hppiVirtualMatrix * virtMatrix; + + bool useCamera = parser.has("camera"); + string file = parser.get("file_name"); + string sAccel = parser.get("accel"); + + parser.printMessage(); + + if( useCamera ) + { + printf("used camera\n"); + cap.open(0); + } + else + { + printf("used image %s\n", file.c_str()); + cap.open(file.c_str()); + } + + if( !cap.isOpened() ) + { + printf("can not open camera or video file\n"); + return -1; + } + + accelType = sAccel == "cpu" ? HPP_ACCEL_TYPE_CPU: + sAccel == "gpu" ? HPP_ACCEL_TYPE_GPU: + HPP_ACCEL_TYPE_ANY; + + //Create accelerator instance + sts = hppCreateInstance(accelType, 0, &accel); + CHECK_STATUS(sts, "hppCreateInstance"); + + accelType = hppQueryAccelType(accel); + + sAccel = accelType == HPP_ACCEL_TYPE_CPU ? "cpu": + accelType == HPP_ACCEL_TYPE_GPU ? "gpu": + accelType == HPP_ACCEL_TYPE_GPU_VIA_DX9 ? "gpu dx9": "?"; + + printf("accelType %s\n", sAccel.c_str()); + + virtMatrix = hppiCreateVirtualMatrices(accel, 1); + + for(;;) + { + cap >> image; + if(image.empty()) + break; + + cvtColor( image, gray, COLOR_BGR2GRAY ); + + result.create( image.rows, image.cols, CV_8U); + + double execTime = (double)getTickCount(); + + //convert Mat to hppiMatrix + src = hpp::getHpp(gray,accel); + dst = hpp::getHpp(result,accel); + + sts = hppiSobel(accel,src, HPP_MASK_SIZE_3X3,HPP_NORM_L1,virtMatrix[0]); + CHECK_STATUS(sts,"hppiSobel"); + + sts = hppiConvert(accel, virtMatrix[0], 0, HPP_RND_MODE_NEAR, dst, HPP_DATA_TYPE_8U); + CHECK_STATUS(sts,"hppiConvert"); + + // Wait for tasks to complete + sts = hppWait(accel, HPP_TIME_OUT_INFINITE); + CHECK_STATUS(sts, "hppWait"); + + execTime = ((double)getTickCount() - execTime)*1000./getTickFrequency(); + + printf("Time : %0.3fms\n", execTime); + + imshow("image", image); + imshow("rez", result); + + waitKey(15); + + sts = hppiFreeMatrix(src); + CHECK_DEL_STATUS(sts,"hppiFreeMatrix"); + + sts = hppiFreeMatrix(dst); + CHECK_DEL_STATUS(sts,"hppiFreeMatrix"); + + } + + if (!useCamera) + waitKey(0); + + if (virtMatrix) + { + sts = hppiDeleteVirtualMatrices(accel, virtMatrix); + CHECK_DEL_STATUS(sts,"hppiDeleteVirtualMatrices"); + } + + if (accel) + { + sts = hppDeleteInstance(accel); + CHECK_DEL_STATUS(sts, "hppDeleteInstance"); + } + + printf("SUCCESS\n"); + +#else + + printf("IPP Async not supported\n"); + +#endif + + return 0; +}