mirror of
https://github.com/opencv/opencv.git
synced 2025-06-07 01:13:28 +08:00
Merge remote-tracking branch 'upstream/3.4' into merge-3.4
This commit is contained in:
commit
50bec53afc
31
.editorconfig
Normal file
31
.editorconfig
Normal file
@ -0,0 +1,31 @@
|
||||
# https://editorconfig.org/
|
||||
|
||||
root = true
|
||||
|
||||
[*]
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
|
||||
[{CMakeLists.*,*.cmake}]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
[Makefile]
|
||||
indent_style = tab
|
||||
|
||||
[*.{bat,cmd,cmd.*}]
|
||||
end_of_line = crlf
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
[*.{ps1,ps1.*}]
|
||||
end_of_line = crlf
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
|
||||
[*.{md,markdown}]
|
||||
indent_size = 2
|
26
3rdparty/ippicv/ippicv.cmake
vendored
26
3rdparty/ippicv/ippicv.cmake
vendored
@ -2,37 +2,37 @@ function(download_ippicv root_var)
|
||||
set(${root_var} "" PARENT_SCOPE)
|
||||
|
||||
# Commit SHA in the opencv_3rdparty repo
|
||||
set(IPPICV_COMMIT "bdb7bb85f34a8cb0d35e40a81f58da431aa1557a")
|
||||
set(IPPICV_COMMIT "32e315a5b106a7b89dbed51c28f8120a48b368b4")
|
||||
# Define actual ICV versions
|
||||
if(APPLE)
|
||||
set(OPENCV_ICV_PLATFORM "macosx")
|
||||
set(OPENCV_ICV_PACKAGE_SUBDIR "ippicv_mac")
|
||||
if(X86_64)
|
||||
set(OPENCV_ICV_NAME "ippicv_2017u3_mac_intel64_general_20180518.tgz")
|
||||
set(OPENCV_ICV_HASH "3ae52b9be0fe73dd45bc5e9429cd3732")
|
||||
set(OPENCV_ICV_NAME "ippicv_2019_mac_intel64_general_20180723.tgz")
|
||||
set(OPENCV_ICV_HASH "fe6b2bb75ae0e3f19ad3ae1a31dfa4a2")
|
||||
else()
|
||||
set(OPENCV_ICV_NAME "ippicv_2017u3_mac_ia32_general_20180518.tgz")
|
||||
set(OPENCV_ICV_HASH "698660b975b62bee3ef6c5af51e97544")
|
||||
set(OPENCV_ICV_NAME "ippicv_2019_mac_ia32_general_20180723.tgz")
|
||||
set(OPENCV_ICV_HASH "b5dfa78c87eb75c64470cbe5ec876f4f")
|
||||
endif()
|
||||
elseif((UNIX AND NOT ANDROID) OR (UNIX AND ANDROID_ABI MATCHES "x86"))
|
||||
set(OPENCV_ICV_PLATFORM "linux")
|
||||
set(OPENCV_ICV_PACKAGE_SUBDIR "ippicv_lnx")
|
||||
if(X86_64)
|
||||
set(OPENCV_ICV_NAME "ippicv_2017u3_lnx_intel64_general_20180518.tgz")
|
||||
set(OPENCV_ICV_HASH "b7cc351267db2d34b9efa1cd22ff0572")
|
||||
set(OPENCV_ICV_NAME "ippicv_2019_lnx_intel64_general_20180723.tgz")
|
||||
set(OPENCV_ICV_HASH "c0bd78adb4156bbf552c1dfe90599607")
|
||||
else()
|
||||
set(OPENCV_ICV_NAME "ippicv_2017u3_lnx_ia32_general_20180518.tgz")
|
||||
set(OPENCV_ICV_HASH "ea72de74dae3c604eb6348395366e78e")
|
||||
set(OPENCV_ICV_NAME "ippicv_2019_lnx_ia32_general_20180723.tgz")
|
||||
set(OPENCV_ICV_HASH "4f38432c30bfd6423164b7a24bbc98a0")
|
||||
endif()
|
||||
elseif(WIN32 AND NOT ARM)
|
||||
set(OPENCV_ICV_PLATFORM "windows")
|
||||
set(OPENCV_ICV_PACKAGE_SUBDIR "ippicv_win")
|
||||
if(X86_64)
|
||||
set(OPENCV_ICV_NAME "ippicv_2017u3_win_intel64_general_20180518.zip")
|
||||
set(OPENCV_ICV_HASH "915ff92958089ede8ea532d3c4fe7187")
|
||||
set(OPENCV_ICV_NAME "ippicv_2019_win_intel64_20180723_general.zip")
|
||||
set(OPENCV_ICV_HASH "1d222685246896fe089f88b8858e4b2f")
|
||||
else()
|
||||
set(OPENCV_ICV_NAME "ippicv_2017u3_win_ia32_general_20180518.zip")
|
||||
set(OPENCV_ICV_HASH "928168c2d99ab284047dfcfb7a821d91")
|
||||
set(OPENCV_ICV_NAME "ippicv_2019_win_ia32_20180723_general.zip")
|
||||
set(OPENCV_ICV_HASH "0157251a2eb9cd63a3ebc7eed0f3e59e")
|
||||
endif()
|
||||
else()
|
||||
return()
|
||||
|
@ -329,8 +329,10 @@ OCV_OPTION(ENABLE_OMIT_FRAME_POINTER "Enable -fomit-frame-pointer for GCC"
|
||||
OCV_OPTION(ENABLE_POWERPC "Enable PowerPC for GCC" ON IF (CV_GCC AND CMAKE_SYSTEM_PROCESSOR MATCHES powerpc.*) )
|
||||
OCV_OPTION(ENABLE_VSX "Enable POWER8 and above VSX (64-bit little-endian)" ON IF ((CV_GCC OR CV_CLANG) AND PPC64LE) )
|
||||
OCV_OPTION(ENABLE_FAST_MATH "Enable -ffast-math (not recommended for GCC 4.6.x)" OFF IF (CV_GCC AND (X86 OR X86_64)) )
|
||||
if(NOT IOS) # Use CPU_BASELINE instead
|
||||
OCV_OPTION(ENABLE_NEON "Enable NEON instructions" (NEON OR ANDROID_ARM_NEON OR AARCH64) IF (CV_GCC OR CV_CLANG) AND (ARM OR AARCH64 OR IOS) )
|
||||
OCV_OPTION(ENABLE_VFPV3 "Enable VFPv3-D32 instructions" OFF IF (CV_GCC OR CV_CLANG) AND (ARM OR AARCH64 OR IOS) )
|
||||
endif()
|
||||
OCV_OPTION(ENABLE_NOISY_WARNINGS "Show all warnings even if they are too noisy" OFF )
|
||||
OCV_OPTION(OPENCV_WARNINGS_ARE_ERRORS "Treat warnings as errors" OFF )
|
||||
OCV_OPTION(ANDROID_EXAMPLES_WITH_LIBS "Build binaries of Android examples with native libraries" OFF IF ANDROID )
|
||||
|
@ -448,7 +448,9 @@ foreach(OPT ${CPU_KNOWN_OPTIMIZATIONS})
|
||||
if(NOT ";${CPU_BASELINE_FINAL};" MATCHES ";${OPT};")
|
||||
list(APPEND CPU_BASELINE_FINAL ${OPT})
|
||||
endif()
|
||||
ocv_append_optimization_flag(CPU_BASELINE_FLAGS ${OPT})
|
||||
if(NOT CPU_BASELINE_DETECT) # Don't change compiler flags in 'detection' mode
|
||||
ocv_append_optimization_flag(CPU_BASELINE_FLAGS ${OPT})
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
|
@ -240,11 +240,12 @@ endif()
|
||||
|
||||
if(NOT DEFINED IPPROOT)
|
||||
include("${OpenCV_SOURCE_DIR}/3rdparty/ippicv/ippicv.cmake")
|
||||
download_ippicv(IPPROOT)
|
||||
if(NOT IPPROOT)
|
||||
download_ippicv(ICV_PACKAGE_ROOT)
|
||||
if(NOT ICV_PACKAGE_ROOT)
|
||||
return()
|
||||
endif()
|
||||
ocv_install_3rdparty_licenses(ippicv "${IPPROOT}/readme.htm" "${IPPROOT}/license/ippEULA.txt")
|
||||
set(IPPROOT "${ICV_PACKAGE_ROOT}/icv")
|
||||
ocv_install_3rdparty_licenses(ippicv "${IPPROOT}/readme.htm" "${ICV_PACKAGE_ROOT}/EULA.txt")
|
||||
endif()
|
||||
|
||||
file(TO_CMAKE_PATH "${IPPROOT}" __IPPROOT)
|
||||
|
@ -1,17 +1,19 @@
|
||||
#
|
||||
# The script to detect Intel(R) Integrated Performance Primitives Integration Wrappers (IPP IW)
|
||||
# The script to detect Intel(R) Integrated Performance Primitives Integration Wrappers (IPP Integration Wrappers)
|
||||
# installation/package
|
||||
#
|
||||
#
|
||||
# On return this will define:
|
||||
#
|
||||
# HAVE_IPP_IW - True if Intel IPP found
|
||||
# IPP_IW_PATH - Root of Intel IPP IW directory
|
||||
# IPP_IW_LIBRARIES - Intel IPP IW libraries
|
||||
# IPP_IW_INCLUDES - Intel IPP IW include folder
|
||||
# HAVE_IPP_IW - True if Intel IPP Integration Wrappers found
|
||||
# HAVE_IPP_IW_LL - True if Intel IPP Integration Wrappers found with Low Level API header
|
||||
# IPP_IW_PATH - Root of Intel IPP Integration Wrappers directory
|
||||
# IPP_IW_LIBRARIES - Intel IPP Integration Wrappers libraries
|
||||
# IPP_IW_INCLUDES - Intel IPP Integration Wrappers include folder
|
||||
#
|
||||
|
||||
unset(HAVE_IPP_IW CACHE)
|
||||
unset(HAVE_IPP_IW_LL CACHE)
|
||||
unset(IPP_IW_PATH)
|
||||
unset(IPP_IW_LIBRARIES)
|
||||
unset(IPP_IW_INCLUDES)
|
||||
@ -29,13 +31,16 @@ macro(ippiw_debugmsg MESSAGE)
|
||||
endmacro()
|
||||
file(TO_CMAKE_PATH "${IPPROOT}" IPPROOT)
|
||||
|
||||
# This function detects Intel IPP IW version by analyzing .h file
|
||||
# This function detects Intel IPP Integration Wrappers version by analyzing .h file
|
||||
macro(ippiw_setup PATH BUILD)
|
||||
set(FILE "${PATH}/include/iw/iw_ll.h") # check if Intel IPP IW is OpenCV specific
|
||||
ippiw_debugmsg("Checking path: ${PATH}")
|
||||
set(FILE "${PATH}/include/iw/iw_version.h")
|
||||
if(${BUILD})
|
||||
ippiw_debugmsg("Checking sources: ${PATH}")
|
||||
else()
|
||||
ippiw_debugmsg("Checking binaries: ${PATH}")
|
||||
endif()
|
||||
if(EXISTS "${FILE}")
|
||||
set(FILE "${PATH}/include/iw/iw_version.h")
|
||||
ippiw_debugmsg("vfile\tok")
|
||||
ippiw_debugmsg("vfile\tfound")
|
||||
file(STRINGS "${FILE}" IW_VERSION_MAJOR REGEX "IW_VERSION_MAJOR")
|
||||
file(STRINGS "${FILE}" IW_VERSION_MINOR REGEX "IW_VERSION_MINOR")
|
||||
file(STRINGS "${FILE}" IW_VERSION_UPDATE REGEX "IW_VERSION_UPDATE")
|
||||
@ -56,13 +61,13 @@ macro(ippiw_setup PATH BUILD)
|
||||
math(EXPR IW_MIN_COMPATIBLE_IPP_EXP "${IW_MIN_COMPATIBLE_IPP_MAJOR}*10000 + ${IW_MIN_COMPATIBLE_IPP_MINOR}*100 + ${IW_MIN_COMPATIBLE_IPP_UPDATE}")
|
||||
|
||||
if((IPP_VERSION_EXP GREATER IW_MIN_COMPATIBLE_IPP_EXP) OR (IPP_VERSION_EXP EQUAL IW_MIN_COMPATIBLE_IPP_EXP))
|
||||
ippiw_debugmsg("version\tok")
|
||||
ippiw_debugmsg("vcheck\tpassed")
|
||||
if(${BUILD})
|
||||
# check sources
|
||||
if(EXISTS "${PATH}/src/iw_core.c")
|
||||
ippiw_debugmsg("sources\tok")
|
||||
ippiw_debugmsg("sources\tyes")
|
||||
set(IPP_IW_PATH "${PATH}")
|
||||
message(STATUS "found Intel IPP IW sources: ${IW_VERSION_MAJOR}.${IW_VERSION_MINOR}.${IW_VERSION_UPDATE}")
|
||||
message(STATUS "found Intel IPP Integration Wrappers sources: ${IW_VERSION_MAJOR}.${IW_VERSION_MINOR}.${IW_VERSION_UPDATE}")
|
||||
message(STATUS "at: ${IPP_IW_PATH}")
|
||||
|
||||
set(IPP_IW_LIBRARY ippiw)
|
||||
@ -72,7 +77,13 @@ macro(ippiw_setup PATH BUILD)
|
||||
add_subdirectory("${IPP_IW_PATH}/" ${OpenCV_BINARY_DIR}/3rdparty/ippiw)
|
||||
|
||||
set(HAVE_IPP_IW 1)
|
||||
set(FILE "${PATH}/include/iw/iw_ll.h") # check if Intel IPP Integration Wrappers is OpenCV specific
|
||||
if(EXISTS "${FILE}")
|
||||
set(HAVE_IPP_IW_LL 1)
|
||||
endif()
|
||||
return()
|
||||
else()
|
||||
ippiw_debugmsg("sources\tno")
|
||||
endif()
|
||||
else()
|
||||
# check binaries
|
||||
@ -82,9 +93,9 @@ macro(ippiw_setup PATH BUILD)
|
||||
set(FILE "${PATH}/lib/ia32/${CMAKE_STATIC_LIBRARY_PREFIX}ipp_iw${CMAKE_STATIC_LIBRARY_SUFFIX}")
|
||||
endif()
|
||||
if(EXISTS ${FILE})
|
||||
ippiw_debugmsg("binaries\tok (64=${IPP_X64})")
|
||||
ippiw_debugmsg("binaries\tyes (64=${IPP_X64})")
|
||||
set(IPP_IW_PATH "${PATH}")
|
||||
message(STATUS "found Intel IPP IW binaries: ${IW_VERSION_MAJOR}.${IW_VERSION_MINOR}.${IW_VERSION_UPDATE}")
|
||||
message(STATUS "found Intel IPP Integration Wrappers binaries: ${IW_VERSION_MAJOR}.${IW_VERSION_MINOR}.${IW_VERSION_UPDATE}")
|
||||
message(STATUS "at: ${IPP_IW_PATH}")
|
||||
|
||||
add_library(ippiw STATIC IMPORTED)
|
||||
@ -105,81 +116,77 @@ macro(ippiw_setup PATH BUILD)
|
||||
|
||||
set(HAVE_IPP_IW 1)
|
||||
set(BUILD_IPP_IW 0)
|
||||
set(FILE "${PATH}/include/iw/iw_ll.h") # check if Intel IPP Integration Wrappers is OpenCV specific
|
||||
if(EXISTS "${FILE}")
|
||||
set(HAVE_IPP_IW_LL 1)
|
||||
endif()
|
||||
return()
|
||||
else()
|
||||
ippiw_debugmsg("binaries\tno")
|
||||
endif()
|
||||
endif()
|
||||
else()
|
||||
ippiw_debugmsg("vcheck\tfailed")
|
||||
endif()
|
||||
else()
|
||||
ippiw_debugmsg("vfile\tnot found")
|
||||
endif()
|
||||
set(HAVE_IPP_IW 0)
|
||||
set(HAVE_IPP_IW_LL 0)
|
||||
endmacro()
|
||||
|
||||
# check os and architecture
|
||||
if(APPLE)
|
||||
set(IW_PACKAGE_SUBDIR "ippiw_mac")
|
||||
elseif((UNIX AND NOT ANDROID) OR (UNIX AND ANDROID_ABI MATCHES "x86"))
|
||||
set(IW_PACKAGE_SUBDIR "ippiw_lnx")
|
||||
elseif(WIN32 AND NOT ARM)
|
||||
set(IW_PACKAGE_SUBDIR "ippiw_win")
|
||||
else()
|
||||
message(SEND_ERROR "Improper system for Intel IPP Integrations Wrappers. This message shouldn't appear. Check Intel IPP configurations steps")
|
||||
return()
|
||||
endif()
|
||||
|
||||
# check build options first
|
||||
if(BUILD_IPP_IW)
|
||||
# custom path
|
||||
if(DEFINED IPPIWROOT)
|
||||
ippiw_setup("${IPPIWROOT}/" 1)
|
||||
message(STATUS "Can't find Intel IPP IW sources at: ${IPPIWROOT}")
|
||||
message(STATUS "Can't find Intel IPP Integration Wrappers sources at: ${IPPIWROOT}")
|
||||
endif()
|
||||
|
||||
# local sources
|
||||
ippiw_setup("${OpenCV_SOURCE_DIR}/3rdparty/ippiw" 1)
|
||||
|
||||
set(IPPIW_ROOT "${IPPROOT}/../${IW_PACKAGE_SUBDIR}")
|
||||
set(IPPIW_ROOT "${IPPROOT}/../iw")
|
||||
ocv_install_3rdparty_licenses(ippiw
|
||||
"${IPPIW_ROOT}/EULA.txt"
|
||||
"${IPPIW_ROOT}/redist.txt"
|
||||
"${IPPIW_ROOT}/support.txt"
|
||||
"${IPPIW_ROOT}/third-party-programs.txt")
|
||||
"${IPPIW_ROOT}/../EULA.txt"
|
||||
"${IPPIW_ROOT}/../support.txt"
|
||||
"${IPPIW_ROOT}/../third-party-programs.txt")
|
||||
|
||||
# Package sources
|
||||
get_filename_component(__PATH "${IPPROOT}/../${IW_PACKAGE_SUBDIR}/" ABSOLUTE)
|
||||
get_filename_component(__PATH "${IPPROOT}/../iw/" ABSOLUTE)
|
||||
ippiw_setup("${__PATH}" 1)
|
||||
|
||||
# take Intel IPP Integration Wrappers from ICV package
|
||||
if(NOT HAVE_IPP_ICV)
|
||||
message(STATUS "Cannot find Intel IPP Integration Wrappers. Checking \"Intel IPP for OpenCV\" package")
|
||||
set(TEMP_ROOT 0)
|
||||
include("${OpenCV_SOURCE_DIR}/3rdparty/ippicv/ippicv.cmake")
|
||||
download_ippicv(TEMP_ROOT)
|
||||
set(IPPIW_ROOT "${TEMP_ROOT}/iw/")
|
||||
ocv_install_3rdparty_licenses(ippiw
|
||||
"${IPPIW_ROOT}/../EULA.txt"
|
||||
"${IPPIW_ROOT}/../support.txt"
|
||||
"${IPPIW_ROOT}/../third-party-programs.txt")
|
||||
|
||||
ippiw_setup("${IPPIW_ROOT}" 1)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
||||
# custom binaries
|
||||
if(DEFINED IPPIWROOT)
|
||||
ippiw_setup("${IPPIWROOT}/" 0)
|
||||
message(STATUS "Can't find Intel IPP IW sources at: ${IPPIWROOT}")
|
||||
message(STATUS "Can't find Intel IPP Integration Wrappers binaries at: ${IPPIWROOT}")
|
||||
endif()
|
||||
|
||||
# check binaries in IPP folder
|
||||
ippiw_setup("${IPPROOT}/" 0)
|
||||
|
||||
# check binaries near IPP folder
|
||||
ippiw_setup("${IPPROOT}/../${IW_PACKAGE_SUBDIR}/" 0)
|
||||
|
||||
|
||||
# take Intel IPP IW from ICV package
|
||||
if(NOT HAVE_IPP_ICV AND BUILD_IPP_IW)
|
||||
message(STATUS "Cannot find Intel IPP IW. Checking \"Intel IPP for OpenCV\" package")
|
||||
set(TEMP_ROOT 0)
|
||||
include("${OpenCV_SOURCE_DIR}/3rdparty/ippicv/ippicv.cmake")
|
||||
download_ippicv(TEMP_ROOT)
|
||||
set(IPPIW_ROOT "${TEMP_ROOT}/../${IW_PACKAGE_SUBDIR}")
|
||||
ocv_install_3rdparty_licenses(ippiw
|
||||
"${IPPIW_ROOT}/EULA.txt"
|
||||
"${IPPIW_ROOT}/redist.txt"
|
||||
"${IPPIW_ROOT}/support.txt"
|
||||
"${IPPIW_ROOT}/third-party-programs.txt")
|
||||
|
||||
# Package sources. Only sources are compatible with regular Intel IPP
|
||||
ippiw_setup("${IPPIW_ROOT}" 1)
|
||||
endif()
|
||||
ippiw_setup("${IPPROOT}/../iw/" 0)
|
||||
|
||||
|
||||
set(HAVE_IPP_IW 0)
|
||||
set(HAVE_IPP_IW_LL 0)
|
||||
message(STATUS "Cannot find Intel IPP Integration Wrappers, optimizations will be limited. Use IPPIWROOT to set custom location")
|
||||
return()
|
||||
|
@ -102,6 +102,7 @@
|
||||
#cmakedefine HAVE_IPP
|
||||
#cmakedefine HAVE_IPP_ICV
|
||||
#cmakedefine HAVE_IPP_IW
|
||||
#cmakedefine HAVE_IPP_IW_LL
|
||||
|
||||
/* JPEG-2000 codec */
|
||||
#cmakedefine HAVE_JASPER
|
||||
|
@ -55,10 +55,18 @@ you can get a better result.
|
||||
|
||||

|
||||
|
||||
@note More details to be added
|
||||
There are some parameters when you get familiar with StereoBM, and you may need to fine tune the parameters to get better and smooth results. Parameters:
|
||||
- texture_threshold: filters out areas that don't have enough texture for reliable matching
|
||||
- Speckle range and size: Block-based matchers often produce "speckles" near the boundaries of objects, where the matching window catches the foreground on one side and the background on the other. In this scene it appears that the matcher is also finding small spurious matches in the projected texture on the table. To get rid of these artifacts we post-process the disparity image with a speckle filter controlled by the speckle_size and speckle_range parameters. speckle_size is the number of pixels below which a disparity blob is dismissed as "speckle." speckle_range controls how close in value disparities must be to be considered part of the same blob.
|
||||
- Number of disparities: How many pixels to slide the window over. The larger it is, the larger the range of visible depths, but more computation is required.
|
||||
- min_disparity: the offset from the x-position of the left pixel at which to begin searching.
|
||||
- uniqueness_ratio: Another post-filtering step. If the best matching disparity is not sufficiently better than every other disparity in the search range, the pixel is filtered out. You can try tweaking this if texture_threshold and the speckle filtering are still letting through spurious matches.
|
||||
- prefilter_size and prefilter_cap: The pre-filtering phase, which normalizes image brightness and enhances texture in preparation for block matching. Normally you should not need to adjust these.
|
||||
|
||||
|
||||
Additional Resources
|
||||
--------------------
|
||||
- [Ros stereo img processing wiki page](http://wiki.ros.org/stereo_image_proc/Tutorials/ChoosingGoodStereoParameters)
|
||||
|
||||
Exercises
|
||||
---------
|
||||
|
BIN
doc/tutorials/imgproc/periodic_noise_removing_filter/images/period_filter.jpg
Executable file
BIN
doc/tutorials/imgproc/periodic_noise_removing_filter/images/period_filter.jpg
Executable file
Binary file not shown.
After Width: | Height: | Size: 8.3 KiB |
BIN
doc/tutorials/imgproc/periodic_noise_removing_filter/images/period_input.jpg
Executable file
BIN
doc/tutorials/imgproc/periodic_noise_removing_filter/images/period_input.jpg
Executable file
Binary file not shown.
After Width: | Height: | Size: 68 KiB |
BIN
doc/tutorials/imgproc/periodic_noise_removing_filter/images/period_output.jpg
Executable file
BIN
doc/tutorials/imgproc/periodic_noise_removing_filter/images/period_output.jpg
Executable file
Binary file not shown.
After Width: | Height: | Size: 52 KiB |
BIN
doc/tutorials/imgproc/periodic_noise_removing_filter/images/period_psd.jpg
Executable file
BIN
doc/tutorials/imgproc/periodic_noise_removing_filter/images/period_psd.jpg
Executable file
Binary file not shown.
After Width: | Height: | Size: 6.5 KiB |
@ -0,0 +1,61 @@
|
||||
Periodic Noise Removing Filter {#tutorial_periodic_noise_removing_filter}
|
||||
==========================
|
||||
|
||||
Goal
|
||||
----
|
||||
|
||||
In this tutorial you will learn:
|
||||
|
||||
- how to remove periodic noise in the Fourier domain
|
||||
|
||||
Theory
|
||||
------
|
||||
|
||||
@note The explanation is based on the book @cite gonzalez. The image on this page is a real world image.
|
||||
|
||||
Periodic noise produces spikes in the Fourier domain that can often be detected by visual analysis.
|
||||
|
||||
### How to remove periodic noise in the Fourier domain?
|
||||
|
||||
Periodic noise can be reduced significantly via frequency domain filtering. On this page we use a notch reject filter with an appropriate radius to completely enclose the noise spikes in the Fourier domain. The notch filter rejects frequencies in predefined neighborhoods around a center frequency. The number of notch filters is arbitrary. The shape of the notch areas can also be arbitrary (e.g. rectangular or circular). On this page we use three circular shape notch reject filters. Power spectrum densify of an image is used for the noise spike’s visual detection.
|
||||
|
||||
Source code
|
||||
-----------
|
||||
|
||||
You can find source code in the `samples/cpp/tutorial_code/ImgProc/periodic_noise_removing_filter/periodic_noise_removing_filter.cpp` of the OpenCV source code library.
|
||||
|
||||
@include samples/cpp/tutorial_code/ImgProc/periodic_noise_removing_filter/periodic_noise_removing_filter.cpp
|
||||
|
||||
Explanation
|
||||
-----------
|
||||
|
||||
Periodic noise reduction by frequency domain filtering consists of power spectrum density calculation (for the noise spikes visual detection), notch reject filter synthesis and frequency filtering:
|
||||
@snippet samples/cpp/tutorial_code/ImgProc/periodic_noise_removing_filter/periodic_noise_removing_filter.cpp main
|
||||
|
||||
A function calcPSD() calculates power spectrum density of an image:
|
||||
@snippet samples/cpp/tutorial_code/ImgProc/periodic_noise_removing_filter/periodic_noise_removing_filter.cpp calcPSD
|
||||
|
||||
A function synthesizeFilterH() forms a transfer function of an ideal circular shape notch reject filter according to a center frequency and a radius:
|
||||
@snippet samples/cpp/tutorial_code/ImgProc/periodic_noise_removing_filter/periodic_noise_removing_filter.cpp synthesizeFilterH
|
||||
|
||||
A function filter2DFreq() filters an image in the frequency domain. The functions fftshift() and filter2DFreq() are copied from the tutorial @ref tutorial_out_of_focus_deblur_filter "Out-of-focus Deblur Filter".
|
||||
|
||||
Result
|
||||
------
|
||||
|
||||
The figure below shows an image heavily corrupted by periodical noise of various frequencies.
|
||||

|
||||
|
||||
The noise components are easily seen as bright dots (spikes) in the Power spectrum density shown in the figure below.
|
||||

|
||||
|
||||
The figure below shows a notch reject filter with an appropriate radius to completely enclose the noise spikes.
|
||||

|
||||
|
||||
The result of processing the image with the notch reject filter is shown below.
|
||||

|
||||
|
||||
The improvement is quite evident. This image contains significantly less visible periodic noise than the original image.
|
||||
|
||||
You can also find a quick video demonstration of this filtering idea on [YouTube](https://youtu.be/Qne51TcWwAc).
|
||||
@youtube{Qne51TcWwAc}
|
@ -340,3 +340,13 @@ In this section you will learn about the image processing (manipulation) functio
|
||||
*Author:* Karpushin Vladislav
|
||||
|
||||
You will learn how to segment an anisotropic image with a single local orientation by a gradient structure tensor.
|
||||
|
||||
- @subpage tutorial_periodic_noise_removing_filter
|
||||
|
||||
*Languages:* C++
|
||||
|
||||
*Compatibility:* \> OpenCV 2.0
|
||||
|
||||
*Author:* Karpushin Vladislav
|
||||
|
||||
You will learn how to remove periodic noise in the Fourier domain.
|
||||
|
@ -628,9 +628,13 @@ CV_EXPORTS_W void setUseIPP(bool flag);
|
||||
CV_EXPORTS_W String getIppVersion();
|
||||
|
||||
// IPP Not-Exact mode. This function may force use of IPP then both IPP and OpenCV provide proper results
|
||||
// but have internal accuracy differences which have to much direct or indirect impact on accuracy tests.
|
||||
CV_EXPORTS_W bool useIPP_NE();
|
||||
CV_EXPORTS_W void setUseIPP_NE(bool flag);
|
||||
// but have internal accuracy differences which have too much direct or indirect impact on accuracy tests.
|
||||
CV_EXPORTS_W bool useIPP_NotExact();
|
||||
CV_EXPORTS_W void setUseIPP_NotExact(bool flag);
|
||||
#ifndef DISABLE_OPENCV_3_COMPATIBILITY
|
||||
static inline bool useIPP_NE() { return useIPP_NotExact(); }
|
||||
static inline void setUseIPP_NE(bool flag) { setUseIPP_NotExact(flag); }
|
||||
#endif
|
||||
|
||||
} // ipp
|
||||
|
||||
|
@ -849,10 +849,10 @@ OPENCV_HAL_IMPL_VSX_BIN_FUNC2(v_int64x2, v_uint64x2, vec_udword2_c, v_absdiff, v
|
||||
|
||||
/** Rounding **/
|
||||
inline v_int32x4 v_round(const v_float32x4& a)
|
||||
{ return v_int32x4(vec_cts(vec_round(a.val))); }
|
||||
{ return v_int32x4(vec_cts(vec_rint(a.val))); }
|
||||
|
||||
inline v_int32x4 v_round(const v_float64x2& a)
|
||||
{ return v_int32x4(vec_mergesqo(vec_ctso(vec_round(a.val)), vec_int4_z)); }
|
||||
{ return v_int32x4(vec_mergesqo(vec_ctso(vec_rint(a.val)), vec_int4_z)); }
|
||||
|
||||
inline v_int32x4 v_floor(const v_float32x4& a)
|
||||
{ return v_int32x4(vec_cts(vec_floor(a.val))); }
|
||||
|
@ -194,8 +194,8 @@ T* allocSingleton(size_t count = 1) { return static_cast<T*>(allocSingletonBuffe
|
||||
#define IPP_DISABLE_LAB_RGB 1 // breaks OCL accuracy tests
|
||||
#define IPP_DISABLE_RGB_XYZ 1 // big accuracy difference
|
||||
#define IPP_DISABLE_XYZ_RGB 1 // big accuracy difference
|
||||
#define IPP_DISABLE_HAAR 1 // improper integration/results
|
||||
#define IPP_DISABLE_HOUGH 1 // improper integration/results
|
||||
#define IPP_DISABLE_FILTER2D_BIG_MASK 1 // different results on masks > 7x7
|
||||
|
||||
#define IPP_DISABLE_GAUSSIANBLUR_PARALLEL 1 // not supported (2017u2 / 2017u3)
|
||||
|
||||
@ -229,7 +229,9 @@ T* allocSingleton(size_t count = 1) { return static_cast<T*>(allocSingletonBuffe
|
||||
# pragma GCC diagnostic ignored "-Wsuggest-override"
|
||||
# endif
|
||||
#include "iw++/iw.hpp"
|
||||
# ifdef HAVE_IPP_IW_LL
|
||||
#include "iw/iw_ll.h"
|
||||
# endif
|
||||
# if defined(__OPENCV_BUILD) && defined(__GNUC__) && __GNUC__ >= 5
|
||||
# pragma GCC diagnostic pop
|
||||
# endif
|
||||
|
@ -341,7 +341,7 @@ namespace cv
|
||||
{
|
||||
static bool ipp_extractChannel(const Mat &src, Mat &dst, int channel)
|
||||
{
|
||||
#ifdef HAVE_IPP_IW
|
||||
#ifdef HAVE_IPP_IW_LL
|
||||
CV_INSTRUMENT_REGION_IPP();
|
||||
|
||||
int srcChannels = src.channels();
|
||||
@ -379,7 +379,7 @@ static bool ipp_extractChannel(const Mat &src, Mat &dst, int channel)
|
||||
|
||||
static bool ipp_insertChannel(const Mat &src, Mat &dst, int channel)
|
||||
{
|
||||
#ifdef HAVE_IPP_IW
|
||||
#ifdef HAVE_IPP_IW_LL
|
||||
CV_INSTRUMENT_REGION_IPP();
|
||||
|
||||
int srcChannels = src.channels();
|
||||
|
@ -328,7 +328,7 @@ void Mat::copyTo( OutputArray _dst ) const
|
||||
#ifdef HAVE_IPP
|
||||
static bool ipp_copyTo(const Mat &src, Mat &dst, const Mat &mask)
|
||||
{
|
||||
#ifdef HAVE_IPP_IW
|
||||
#ifdef HAVE_IPP_IW_LL
|
||||
CV_INSTRUMENT_REGION_IPP();
|
||||
|
||||
if(mask.channels() > 1 || mask.depth() != CV_8U)
|
||||
@ -463,7 +463,7 @@ Mat& Mat::operator = (const Scalar& s)
|
||||
#ifdef HAVE_IPP
|
||||
static bool ipp_Mat_setTo_Mat(Mat &dst, Mat &_val, Mat &mask)
|
||||
{
|
||||
#ifdef HAVE_IPP_IW
|
||||
#ifdef HAVE_IPP_IW_LL
|
||||
CV_INSTRUMENT_REGION_IPP();
|
||||
|
||||
if(mask.empty())
|
||||
@ -1152,7 +1152,7 @@ namespace cv {
|
||||
static bool ipp_copyMakeBorder( Mat &_src, Mat &_dst, int top, int bottom,
|
||||
int left, int right, int _borderType, const Scalar& value )
|
||||
{
|
||||
#if defined HAVE_IPP_IW && !IPP_DISABLE_PERF_COPYMAKE
|
||||
#if defined HAVE_IPP_IW_LL && !IPP_DISABLE_PERF_COPYMAKE
|
||||
CV_INSTRUMENT_REGION_IPP();
|
||||
|
||||
::ipp::IwiBorderSize borderSize(left, top, right, bottom);
|
||||
|
@ -674,6 +674,24 @@ static bool ipp_meanStdDev(Mat& src, OutputArray _mean, OutputArray _sdv, Mat& m
|
||||
if (cn > 1)
|
||||
return false;
|
||||
#endif
|
||||
#if IPP_VERSION_X100 >= 201900 && IPP_VERSION_X100 < 201901
|
||||
// IPP_DISABLE: 32f C3C functions can read outside of allocated memory
|
||||
if (cn > 1 && src.depth() == CV_32F)
|
||||
return false;
|
||||
|
||||
// SSE4.2 buffer overrun
|
||||
#if defined(_WIN32) && !defined(_WIN64)
|
||||
// IPPICV doesn't have AVX2 in 32-bit builds
|
||||
// However cv::ipp::getIppTopFeatures() may return AVX2 value on AVX2 capable H/W
|
||||
// details #12959
|
||||
#else
|
||||
if (cv::ipp::getIppTopFeatures() == ippCPUID_SSE42) // Linux x64 + OPENCV_IPP=SSE42 is affected too
|
||||
#endif
|
||||
{
|
||||
if (src.depth() == CV_32F && src.dims > 1 && src.size[src.dims - 1] == 6)
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
size_t total_size = src.total();
|
||||
int rows = src.size[0], cols = rows ? (int)(total_size/rows) : 0;
|
||||
|
@ -230,7 +230,7 @@ static MergeFunc getMergeFunc(int depth)
|
||||
namespace cv {
|
||||
static bool ipp_merge(const Mat* mv, Mat& dst, int channels)
|
||||
{
|
||||
#ifdef HAVE_IPP_IW
|
||||
#ifdef HAVE_IPP_IW_LL
|
||||
CV_INSTRUMENT_REGION_IPP();
|
||||
|
||||
if(channels != 3 && channels != 4)
|
||||
|
@ -8,6 +8,8 @@
|
||||
#include "opencv2/core/openvx/ovx_defs.hpp"
|
||||
#include "stat.hpp"
|
||||
|
||||
#define IPP_DISABLE_MINMAXIDX_MANY_ROWS 1 // see Core_MinMaxIdx.rows_overflow test
|
||||
|
||||
/****************************************************************************************\
|
||||
* minMaxLoc *
|
||||
\****************************************************************************************/
|
||||
@ -624,6 +626,10 @@ static bool ipp_minMaxIdx(Mat &src, double* _minVal, double* _maxVal, int* _minI
|
||||
if(src.dims <= 2)
|
||||
{
|
||||
IppiSize size = ippiSize(src.size());
|
||||
#if defined(_WIN32) && !defined(_WIN64) && IPP_VERSION_X100 == 201900 && IPP_DISABLE_MINMAXIDX_MANY_ROWS
|
||||
if (size.height > 65536)
|
||||
return false; // test: Core_MinMaxIdx.rows_overflow
|
||||
#endif
|
||||
size.width *= src.channels();
|
||||
|
||||
status = ippMinMaxFun(src.ptr(), (int)src.step, size, dataType, pMinVal, pMaxVal, pMinIdx, pMaxIdx, (Ipp8u*)mask.ptr(), (int)mask.step);
|
||||
|
@ -238,7 +238,7 @@ static SplitFunc getSplitFunc(int depth)
|
||||
namespace cv {
|
||||
static bool ipp_split(const Mat& src, Mat* mv, int channels)
|
||||
{
|
||||
#ifdef HAVE_IPP_IW
|
||||
#ifdef HAVE_IPP_IW_LL
|
||||
CV_INSTRUMENT_REGION_IPP();
|
||||
|
||||
if(channels != 3 && channels != 4)
|
||||
|
@ -2017,7 +2017,12 @@ public:
|
||||
env = pIppEnv;
|
||||
if(env.size())
|
||||
{
|
||||
#if IPP_VERSION_X100 >= 201703
|
||||
#if IPP_VERSION_X100 >= 201900
|
||||
const Ipp64u minorFeatures = ippCPUID_MOVBE|ippCPUID_AES|ippCPUID_CLMUL|ippCPUID_ABR|ippCPUID_RDRAND|ippCPUID_F16C|
|
||||
ippCPUID_ADCOX|ippCPUID_RDSEED|ippCPUID_PREFETCHW|ippCPUID_SHA|ippCPUID_MPX|ippCPUID_AVX512CD|ippCPUID_AVX512ER|
|
||||
ippCPUID_AVX512PF|ippCPUID_AVX512BW|ippCPUID_AVX512DQ|ippCPUID_AVX512VL|ippCPUID_AVX512VBMI|ippCPUID_AVX512_4FMADDPS|
|
||||
ippCPUID_AVX512_4VNNIW|ippCPUID_AVX512IFMA;
|
||||
#elif IPP_VERSION_X100 >= 201703
|
||||
const Ipp64u minorFeatures = ippCPUID_MOVBE|ippCPUID_AES|ippCPUID_CLMUL|ippCPUID_ABR|ippCPUID_RDRAND|ippCPUID_F16C|
|
||||
ippCPUID_ADCOX|ippCPUID_RDSEED|ippCPUID_PREFETCHW|ippCPUID_SHA|ippCPUID_MPX|ippCPUID_AVX512CD|ippCPUID_AVX512ER|
|
||||
ippCPUID_AVX512PF|ippCPUID_AVX512BW|ippCPUID_AVX512DQ|ippCPUID_AVX512VL|ippCPUID_AVX512VBMI;
|
||||
@ -2210,7 +2215,7 @@ void setUseIPP(bool flag)
|
||||
#endif
|
||||
}
|
||||
|
||||
bool useIPP_NE()
|
||||
bool useIPP_NotExact()
|
||||
{
|
||||
#ifdef HAVE_IPP
|
||||
CoreTLSData* data = getCoreTlsData().get();
|
||||
@ -2224,11 +2229,11 @@ bool useIPP_NE()
|
||||
#endif
|
||||
}
|
||||
|
||||
void setUseIPP_NE(bool flag)
|
||||
void setUseIPP_NotExact(bool flag)
|
||||
{
|
||||
CoreTLSData* data = getCoreTlsData().get();
|
||||
#ifdef HAVE_IPP
|
||||
data->useIPP_NE = (getIPPSingleton().useIPP_NE)?flag:false;
|
||||
data->useIPP_NE = flag;
|
||||
#else
|
||||
CV_UNUSED(flag);
|
||||
data->useIPP_NE = false;
|
||||
|
@ -2369,4 +2369,30 @@ TEST(UMat_Core_DivideRules, type_32f) { testDivide<float, true>(); }
|
||||
TEST(Core_DivideRules, type_64f) { testDivide<double, false>(); }
|
||||
TEST(UMat_Core_DivideRules, type_64f) { testDivide<double, true>(); }
|
||||
|
||||
|
||||
TEST(Core_MinMaxIdx, rows_overflow)
|
||||
{
|
||||
const int N = 65536 + 1;
|
||||
const int M = 1;
|
||||
{
|
||||
setRNGSeed(123);
|
||||
Mat m(N, M, CV_32FC1);
|
||||
randu(m, -100, 100);
|
||||
double minVal = 0, maxVal = 0;
|
||||
int minIdx[CV_MAX_DIM] = { 0 }, maxIdx[CV_MAX_DIM] = { 0 };
|
||||
cv::minMaxIdx(m, &minVal, &maxVal, minIdx, maxIdx);
|
||||
|
||||
double minVal0 = 0, maxVal0 = 0;
|
||||
int minIdx0[CV_MAX_DIM] = { 0 }, maxIdx0[CV_MAX_DIM] = { 0 };
|
||||
cv::ipp::setUseIPP(false);
|
||||
cv::minMaxIdx(m, &minVal0, &maxVal0, minIdx0, maxIdx0);
|
||||
cv::ipp::setUseIPP(true);
|
||||
|
||||
EXPECT_FALSE(fabs(minVal0 - minVal) > 1e-6 || fabs(maxVal0 - maxVal) > 1e-6) << "NxM=" << N << "x" << M <<
|
||||
" min=" << minVal0 << " vs " << minVal <<
|
||||
" max=" << maxVal0 << " vs " << maxVal;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}} // namespace
|
||||
|
@ -379,6 +379,10 @@ public:
|
||||
layerParams.blobs[1].setTo(1); // std
|
||||
}
|
||||
}
|
||||
else if ("ConvolutionDepthwise" == type)
|
||||
{
|
||||
type = "Convolution";
|
||||
}
|
||||
|
||||
int id = dstNet.addLayer(name, type, layerParams);
|
||||
|
||||
|
@ -724,7 +724,16 @@ int ORB_Impl::descriptorType() const
|
||||
|
||||
int ORB_Impl::defaultNorm() const
|
||||
{
|
||||
return NORM_HAMMING;
|
||||
switch (wta_k)
|
||||
{
|
||||
case 2:
|
||||
return NORM_HAMMING;
|
||||
case 3:
|
||||
case 4:
|
||||
return NORM_HAMMING2;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
|
@ -4585,7 +4585,7 @@ static bool ippFilter2D(int stype, int dtype, int kernel_type,
|
||||
return false;
|
||||
#endif
|
||||
|
||||
#if IPP_VERSION_X100 < 201801
|
||||
#if IPP_DISABLE_FILTER2D_BIG_MASK
|
||||
// Too big difference compared to OpenCV FFT-based convolution
|
||||
if(kernel_type == CV_32FC1 && (type == ipp16s || type == ipp16u) && (kernel_width > 7 || kernel_height > 7))
|
||||
return false;
|
||||
|
@ -3321,7 +3321,7 @@ static bool ipp_resize(const uchar * src_data, size_t src_step, int src_width, i
|
||||
return false;
|
||||
|
||||
// Resize which doesn't match OpenCV exactly
|
||||
if (!cv::ipp::useIPP_NE())
|
||||
if (!cv::ipp::useIPP_NotExact())
|
||||
{
|
||||
if (ippInter == ippNearest || ippInter == ippSuper || (ippDataType == ipp8u && ippInter == ippLinear))
|
||||
return false;
|
||||
|
@ -4,5 +4,5 @@ ocv_define_module(objdetect opencv_core opencv_imgproc opencv_calib3d WRAP java
|
||||
if(HAVE_QUIRC)
|
||||
get_property(QUIRC_INCLUDE GLOBAL PROPERTY QUIRC_INCLUDE_DIR)
|
||||
ocv_include_directories(${QUIRC_INCLUDE})
|
||||
ocv_target_link_libraries(${PROJECT_NAME} quirc)
|
||||
ocv_target_link_libraries(${the_module} quirc)
|
||||
endif()
|
||||
|
106
modules/objdetect/perf/perf_qrcode_pipeline.cpp
Normal file
106
modules/objdetect/perf/perf_qrcode_pipeline.cpp
Normal file
@ -0,0 +1,106 @@
|
||||
// This file is part of OpenCV project.
|
||||
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
// of this distribution and at http://opencv.org/license.html.
|
||||
|
||||
#include "perf_precomp.hpp"
|
||||
|
||||
namespace opencv_test
|
||||
{
|
||||
namespace
|
||||
{
|
||||
|
||||
typedef ::perf::TestBaseWithParam< std::string > Perf_Objdetect_QRCode;
|
||||
|
||||
PERF_TEST_P_(Perf_Objdetect_QRCode, detect)
|
||||
{
|
||||
const std::string name_current_image = GetParam();
|
||||
const std::string root = "cv/qrcode/";
|
||||
|
||||
std::string image_path = findDataFile(root + name_current_image);
|
||||
Mat src = imread(image_path, IMREAD_GRAYSCALE), straight_barcode;
|
||||
ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
|
||||
|
||||
std::vector< Point > corners;
|
||||
TEST_CYCLE() ASSERT_TRUE(detectQRCode(src, corners));
|
||||
SANITY_CHECK(corners);
|
||||
}
|
||||
|
||||
#ifdef HAVE_QUIRC
|
||||
PERF_TEST_P_(Perf_Objdetect_QRCode, decode)
|
||||
{
|
||||
const std::string name_current_image = GetParam();
|
||||
const std::string root = "cv/qrcode/";
|
||||
|
||||
std::string image_path = findDataFile(root + name_current_image);
|
||||
Mat src = imread(image_path, IMREAD_GRAYSCALE), straight_barcode;
|
||||
ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
|
||||
|
||||
std::vector< Point > corners;
|
||||
std::string decoded_info;
|
||||
ASSERT_TRUE(detectQRCode(src, corners));
|
||||
TEST_CYCLE() ASSERT_TRUE(decodeQRCode(src, corners, decoded_info, straight_barcode));
|
||||
|
||||
std::vector<uint8_t> decoded_info_uint8_t(decoded_info.begin(), decoded_info.end());
|
||||
SANITY_CHECK(decoded_info_uint8_t);
|
||||
SANITY_CHECK(straight_barcode);
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(/*nothing*/, Perf_Objdetect_QRCode,
|
||||
::testing::Values(
|
||||
"version_1_down.jpg", "version_1_left.jpg", "version_1_right.jpg", "version_1_up.jpg", "version_1_top.jpg",
|
||||
"version_5_down.jpg", "version_5_left.jpg", "version_5_right.jpg", "version_5_up.jpg", "version_5_top.jpg",
|
||||
"russian.jpg", "kanji.jpg", "link_github_ocv.jpg", "link_ocv.jpg", "link_wiki_cv.jpg"
|
||||
)
|
||||
);
|
||||
|
||||
typedef ::perf::TestBaseWithParam< tuple< std::string, Size > > Perf_Objdetect_Not_QRCode;
|
||||
|
||||
PERF_TEST_P_(Perf_Objdetect_Not_QRCode, detect)
|
||||
{
|
||||
std::vector<Point> corners;
|
||||
std::string type_gen = get<0>(GetParam());
|
||||
Size resolution = get<1>(GetParam());
|
||||
Mat not_qr_code(resolution, CV_8UC1, Scalar(0));
|
||||
if (type_gen == "random")
|
||||
{
|
||||
RNG rng;
|
||||
rng.fill(not_qr_code, RNG::UNIFORM, Scalar(0), Scalar(1));
|
||||
}
|
||||
|
||||
TEST_CYCLE() ASSERT_FALSE(detectQRCode(not_qr_code, corners));
|
||||
SANITY_CHECK_NOTHING();
|
||||
}
|
||||
|
||||
#ifdef HAVE_QUIRC
|
||||
PERF_TEST_P_(Perf_Objdetect_Not_QRCode, decode)
|
||||
{
|
||||
Mat straight_barcode;
|
||||
std::string decoded_info;
|
||||
std::vector< Point > corners;
|
||||
corners.push_back(Point( 0, 0)); corners.push_back(Point( 0, 5));
|
||||
corners.push_back(Point(10, 0)); corners.push_back(Point(15, 15));
|
||||
|
||||
std::string type_gen = get<0>(GetParam());
|
||||
Size resolution = get<1>(GetParam());
|
||||
Mat not_qr_code(resolution, CV_8UC1, Scalar(0));
|
||||
if (type_gen == "random")
|
||||
{
|
||||
RNG rng;
|
||||
rng.fill(not_qr_code, RNG::UNIFORM, Scalar(0), Scalar(1));
|
||||
}
|
||||
|
||||
TEST_CYCLE() ASSERT_FALSE(decodeQRCode(not_qr_code, corners, decoded_info, straight_barcode));
|
||||
SANITY_CHECK_NOTHING();
|
||||
}
|
||||
#endif
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(/*nothing*/, Perf_Objdetect_Not_QRCode,
|
||||
::testing::Combine(
|
||||
::testing::Values("zero", "random"),
|
||||
::testing::Values(Size(640, 480), Size(1280, 720), Size(1920, 1080))
|
||||
));
|
||||
|
||||
}
|
||||
} // namespace
|
@ -94,7 +94,6 @@ typedef struct CvHidHaarClassifierCascade
|
||||
sqsumtype *pq0, *pq1, *pq2, *pq3;
|
||||
sumtype *p0, *p1, *p2, *p3;
|
||||
|
||||
void** ipp_stages;
|
||||
bool is_tree;
|
||||
bool isStumpBased;
|
||||
} CvHidHaarClassifierCascade;
|
||||
@ -128,23 +127,6 @@ icvReleaseHidHaarClassifierCascade( CvHidHaarClassifierCascade** _cascade )
|
||||
{
|
||||
if( _cascade && *_cascade )
|
||||
{
|
||||
#ifdef HAVE_IPP
|
||||
CvHidHaarClassifierCascade* cascade = *_cascade;
|
||||
if( CV_IPP_CHECK_COND && cascade->ipp_stages )
|
||||
{
|
||||
int i;
|
||||
for( i = 0; i < cascade->count; i++ )
|
||||
{
|
||||
if( cascade->ipp_stages[i] )
|
||||
#if IPP_VERSION_X100 < 900 && !IPP_DISABLE_HAAR
|
||||
ippiHaarClassifierFree_32f( (IppiHaarClassifier_32f*)cascade->ipp_stages[i] );
|
||||
#else
|
||||
cvFree(&cascade->ipp_stages[i]);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
cvFree( &cascade->ipp_stages );
|
||||
#endif
|
||||
cvFree( _cascade );
|
||||
}
|
||||
}
|
||||
@ -153,10 +135,6 @@ icvReleaseHidHaarClassifierCascade( CvHidHaarClassifierCascade** _cascade )
|
||||
static CvHidHaarClassifierCascade*
|
||||
icvCreateHidHaarClassifierCascade( CvHaarClassifierCascade* cascade )
|
||||
{
|
||||
CvRect* ipp_features = 0;
|
||||
float *ipp_weights = 0, *ipp_thresholds = 0, *ipp_val1 = 0, *ipp_val2 = 0;
|
||||
int* ipp_counts = 0;
|
||||
|
||||
CvHidHaarClassifierCascade* out = 0;
|
||||
|
||||
int i, j, k, l;
|
||||
@ -312,72 +290,9 @@ icvCreateHidHaarClassifierCascade( CvHaarClassifierCascade* cascade )
|
||||
}
|
||||
}
|
||||
|
||||
#if defined HAVE_IPP && !IPP_DISABLE_HAAR
|
||||
int can_use_ipp = CV_IPP_CHECK_COND && (!out->has_tilted_features && !out->is_tree && out->isStumpBased);
|
||||
|
||||
if( can_use_ipp )
|
||||
{
|
||||
int ipp_datasize = cascade->count*sizeof(out->ipp_stages[0]);
|
||||
float ipp_weight_scale=(float)(1./((orig_window_size.width-icv_object_win_border*2)*
|
||||
(orig_window_size.height-icv_object_win_border*2)));
|
||||
|
||||
out->ipp_stages = (void**)cvAlloc( ipp_datasize );
|
||||
memset( out->ipp_stages, 0, ipp_datasize );
|
||||
|
||||
ipp_features = (CvRect*)cvAlloc( max_count*3*sizeof(ipp_features[0]) );
|
||||
ipp_weights = (float*)cvAlloc( max_count*3*sizeof(ipp_weights[0]) );
|
||||
ipp_thresholds = (float*)cvAlloc( max_count*sizeof(ipp_thresholds[0]) );
|
||||
ipp_val1 = (float*)cvAlloc( max_count*sizeof(ipp_val1[0]) );
|
||||
ipp_val2 = (float*)cvAlloc( max_count*sizeof(ipp_val2[0]) );
|
||||
ipp_counts = (int*)cvAlloc( max_count*sizeof(ipp_counts[0]) );
|
||||
|
||||
for( i = 0; i < cascade->count; i++ )
|
||||
{
|
||||
CvHaarStageClassifier* stage_classifier = cascade->stage_classifier + i;
|
||||
for( j = 0, k = 0; j < stage_classifier->count; j++ )
|
||||
{
|
||||
CvHaarClassifier* classifier = stage_classifier->classifier + j;
|
||||
int rect_count = 2 + (classifier->haar_feature->rect[2].r.width != 0);
|
||||
|
||||
ipp_thresholds[j] = classifier->threshold[0];
|
||||
ipp_val1[j] = classifier->alpha[0];
|
||||
ipp_val2[j] = classifier->alpha[1];
|
||||
ipp_counts[j] = rect_count;
|
||||
|
||||
for( l = 0; l < rect_count; l++, k++ )
|
||||
{
|
||||
ipp_features[k] = classifier->haar_feature->rect[l].r;
|
||||
//ipp_features[k].y = orig_window_size.height - ipp_features[k].y - ipp_features[k].height;
|
||||
ipp_weights[k] = classifier->haar_feature->rect[l].weight*ipp_weight_scale;
|
||||
}
|
||||
}
|
||||
|
||||
if( ippiHaarClassifierInitAlloc_32f( (IppiHaarClassifier_32f**)&out->ipp_stages[i],
|
||||
(const IppiRect*)ipp_features, ipp_weights, ipp_thresholds,
|
||||
ipp_val1, ipp_val2, ipp_counts, stage_classifier->count ) < 0 )
|
||||
break;
|
||||
}
|
||||
|
||||
if( i < cascade->count )
|
||||
{
|
||||
for( j = 0; j < i; j++ )
|
||||
if( out->ipp_stages[i] )
|
||||
ippiHaarClassifierFree_32f( (IppiHaarClassifier_32f*)out->ipp_stages[i] );
|
||||
cvFree( &out->ipp_stages );
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
cascade->hid_cascade = out;
|
||||
assert( (char*)haar_node_ptr - (char*)out <= datasize );
|
||||
|
||||
cvFree( &ipp_features );
|
||||
cvFree( &ipp_weights );
|
||||
cvFree( &ipp_thresholds );
|
||||
cvFree( &ipp_val1 );
|
||||
cvFree( &ipp_val2 );
|
||||
cvFree( &ipp_counts );
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
@ -975,120 +890,54 @@ public:
|
||||
std::vector<int> rejectLevelsLocal;
|
||||
std::vector<double> levelWeightsLocal;
|
||||
|
||||
#ifdef HAVE_IPP
|
||||
if(CV_IPP_CHECK_COND && cascade->hid_cascade->ipp_stages )
|
||||
{
|
||||
IppiRect iequRect = {equRect.x, equRect.y, equRect.width, equRect.height};
|
||||
CV_INSTRUMENT_FUN_IPP(ippiRectStdDev_32f_C1R, sum1.ptr<float>(y1), (int)sum1.step,
|
||||
sqsum1.ptr<double>(y1), (int)sqsum1.step,
|
||||
norm1->ptr<float>(y1), (int)norm1->step,
|
||||
ippiSize(ssz.width, ssz.height), iequRect);
|
||||
|
||||
int positive = (ssz.width/ystep)*((ssz.height + ystep-1)/ystep);
|
||||
|
||||
if( ystep == 1 )
|
||||
(*mask1) = Scalar::all(1);
|
||||
else
|
||||
for( y = y1; y < y2; y++ )
|
||||
{
|
||||
uchar* mask1row = mask1->ptr(y);
|
||||
memset( mask1row, 0, ssz.width );
|
||||
|
||||
if( y % ystep == 0 )
|
||||
for( x = 0; x < ssz.width; x += ystep )
|
||||
mask1row[x] = (uchar)1;
|
||||
}
|
||||
|
||||
for( int j = 0; j < cascade->count; j++ )
|
||||
for( y = y1; y < y2; y += ystep )
|
||||
for( x = 0; x < ssz.width; x += ystep )
|
||||
{
|
||||
if (CV_INSTRUMENT_FUN_IPP(ippiApplyHaarClassifier_32f_C1R,
|
||||
sum1.ptr<float>(y1), (int)sum1.step,
|
||||
norm1->ptr<float>(y1), (int)norm1->step,
|
||||
mask1->ptr<uchar>(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 )
|
||||
positive = 0;
|
||||
if( positive <= 0 )
|
||||
break;
|
||||
double gypWeight;
|
||||
int result = cvRunHaarClassifierCascadeSum( cascade, cvPoint(x,y), gypWeight, 0 );
|
||||
if( rejectLevels )
|
||||
{
|
||||
if( result == 1 )
|
||||
result = -1*cascade->count;
|
||||
if( cascade->count + result < 4 )
|
||||
{
|
||||
vecLocal.push_back(Rect(cvRound(x*factor), cvRound(y*factor),
|
||||
winSize.width, winSize.height));
|
||||
rejectLevelsLocal.push_back(-result);
|
||||
levelWeightsLocal.push_back(gypWeight);
|
||||
|
||||
if (vecLocal.size() >= PARALLEL_LOOP_BATCH_SIZE)
|
||||
{
|
||||
mtx->lock();
|
||||
vec->insert(vec->end(), vecLocal.begin(), vecLocal.end());
|
||||
rejectLevels->insert(rejectLevels->end(), rejectLevelsLocal.begin(), rejectLevelsLocal.end());
|
||||
levelWeights->insert(levelWeights->end(), levelWeightsLocal.begin(), levelWeightsLocal.end());
|
||||
mtx->unlock();
|
||||
|
||||
vecLocal.clear();
|
||||
rejectLevelsLocal.clear();
|
||||
levelWeightsLocal.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( result > 0 )
|
||||
{
|
||||
vecLocal.push_back(Rect(cvRound(x*factor), cvRound(y*factor),
|
||||
winSize.width, winSize.height));
|
||||
|
||||
if (vecLocal.size() >= PARALLEL_LOOP_BATCH_SIZE)
|
||||
{
|
||||
mtx->lock();
|
||||
vec->insert(vec->end(), vecLocal.begin(), vecLocal.end());
|
||||
mtx->unlock();
|
||||
|
||||
vecLocal.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
CV_IMPL_ADD(CV_IMPL_IPP|CV_IMPL_MT);
|
||||
|
||||
if( positive > 0 )
|
||||
for( y = y1; y < y2; y += ystep )
|
||||
{
|
||||
uchar* mask1row = mask1->ptr(y);
|
||||
for( x = 0; x < ssz.width; x += ystep )
|
||||
if( mask1row[x] != 0 )
|
||||
{
|
||||
vecLocal.push_back(Rect(cvRound(x*factor), cvRound(y*factor),
|
||||
winSize.width, winSize.height));
|
||||
|
||||
if (vecLocal.size() >= PARALLEL_LOOP_BATCH_SIZE)
|
||||
{
|
||||
mtx->lock();
|
||||
vec->insert(vec->end(), vecLocal.begin(), vecLocal.end());
|
||||
mtx->unlock();
|
||||
|
||||
vecLocal.clear();
|
||||
}
|
||||
if( --positive == 0 )
|
||||
break;
|
||||
}
|
||||
if( positive == 0 )
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif // IPP
|
||||
for( y = y1; y < y2; y += ystep )
|
||||
for( x = 0; x < ssz.width; x += ystep )
|
||||
{
|
||||
double gypWeight;
|
||||
int result = cvRunHaarClassifierCascadeSum( cascade, cvPoint(x,y), gypWeight, 0 );
|
||||
if( rejectLevels )
|
||||
{
|
||||
if( result == 1 )
|
||||
result = -1*cascade->count;
|
||||
if( cascade->count + result < 4 )
|
||||
{
|
||||
vecLocal.push_back(Rect(cvRound(x*factor), cvRound(y*factor),
|
||||
winSize.width, winSize.height));
|
||||
rejectLevelsLocal.push_back(-result);
|
||||
levelWeightsLocal.push_back(gypWeight);
|
||||
|
||||
if (vecLocal.size() >= PARALLEL_LOOP_BATCH_SIZE)
|
||||
{
|
||||
mtx->lock();
|
||||
vec->insert(vec->end(), vecLocal.begin(), vecLocal.end());
|
||||
rejectLevels->insert(rejectLevels->end(), rejectLevelsLocal.begin(), rejectLevelsLocal.end());
|
||||
levelWeights->insert(levelWeights->end(), levelWeightsLocal.begin(), levelWeightsLocal.end());
|
||||
mtx->unlock();
|
||||
|
||||
vecLocal.clear();
|
||||
rejectLevelsLocal.clear();
|
||||
levelWeightsLocal.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( result > 0 )
|
||||
{
|
||||
vecLocal.push_back(Rect(cvRound(x*factor), cvRound(y*factor),
|
||||
winSize.width, winSize.height));
|
||||
|
||||
if (vecLocal.size() >= PARALLEL_LOOP_BATCH_SIZE)
|
||||
{
|
||||
mtx->lock();
|
||||
vec->insert(vec->end(), vecLocal.begin(), vecLocal.end());
|
||||
mtx->unlock();
|
||||
|
||||
vecLocal.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (rejectLevelsLocal.size())
|
||||
{
|
||||
@ -1283,12 +1132,6 @@ cvHaarDetectObjectsForROC( const CvArr* _img,
|
||||
if( flags & CV_HAAR_SCALE_IMAGE )
|
||||
{
|
||||
CvSize winSize0 = cascade->orig_window_size;
|
||||
#ifdef HAVE_IPP
|
||||
int use_ipp = CV_IPP_CHECK_COND && (cascade->hid_cascade->ipp_stages != 0);
|
||||
|
||||
if( use_ipp )
|
||||
normImg.reset(cvCreateMat( img->rows, img->cols, CV_32FC1));
|
||||
#endif
|
||||
imgSmall.reset(cvCreateMat( img->rows + 1, img->cols + 1, CV_8UC1 ));
|
||||
|
||||
for( factor = 1; ; factor *= scaleFactor )
|
||||
@ -1330,15 +1173,7 @@ cvHaarDetectObjectsForROC( const CvArr* _img,
|
||||
int stripCount = ((sz1.width/ystep)*(sz1.height + ystep-1)/ystep + LOCS_PER_THREAD/2)/LOCS_PER_THREAD;
|
||||
stripCount = std::min(std::max(stripCount, 1), 100);
|
||||
|
||||
#ifdef HAVE_IPP
|
||||
if( use_ipp )
|
||||
{
|
||||
cv::Mat fsum(sum1.rows, sum1.cols, CV_32F, sum1.data.ptr, sum1.step);
|
||||
cv::cvarrToMat(&sum1).convertTo(fsum, CV_32F, 1, -(1<<24));
|
||||
}
|
||||
else
|
||||
#endif
|
||||
cvSetImagesForHaarClassifierCascade( cascade, &sum1, &sqsum1, _tilted, 1. );
|
||||
cvSetImagesForHaarClassifierCascade( cascade, &sum1, &sqsum1, _tilted, 1. );
|
||||
|
||||
cv::Mat _norm1 = cv::cvarrToMat(&norm1), _mask1 = cv::cvarrToMat(&mask1);
|
||||
cv::parallel_for_(cv::Range(0, stripCount),
|
||||
|
@ -865,6 +865,20 @@ bool QRDecode::updatePerspective()
|
||||
return true;
|
||||
}
|
||||
|
||||
inline Point computeOffset(const vector<Point>& v)
|
||||
{
|
||||
// compute the width/height of convex hull
|
||||
Rect areaBox = boundingRect(v);
|
||||
|
||||
// compute the good offset
|
||||
// the box is consisted by 7 steps
|
||||
// to pick the middle of the stripe, it needs to be 1/14 of the size
|
||||
const int cStep = 7 * 2;
|
||||
Point offset = Point(areaBox.width, areaBox.height);
|
||||
offset /= cStep;
|
||||
return offset;
|
||||
}
|
||||
|
||||
bool QRDecode::versionDefinition()
|
||||
{
|
||||
LineIterator line_iter(intermediate, Point2f(0, 0), Point2f(test_perspective_size, test_perspective_size));
|
||||
@ -882,17 +896,18 @@ bool QRDecode::versionDefinition()
|
||||
Mat mask_roi = mask(Range(1, intermediate.rows - 1), Range(1, intermediate.cols - 1));
|
||||
findNonZero(mask_roi, non_zero_elem);
|
||||
convexHull(Mat(non_zero_elem), locations);
|
||||
Point offset = computeOffset(locations);
|
||||
|
||||
Point temp_remote = locations[0], remote_point;
|
||||
const Point delta_diff = Point(4, 4);
|
||||
const Point delta_diff = offset;
|
||||
for (size_t i = 0; i < locations.size(); i++)
|
||||
{
|
||||
if (norm(black_point - temp_remote) < norm(black_point - locations[i]))
|
||||
if (norm(black_point - temp_remote) <= norm(black_point - locations[i]))
|
||||
{
|
||||
const uint8_t value = intermediate.at<uint8_t>(temp_remote - delta_diff);
|
||||
if (value == 0) { remote_point = temp_remote - delta_diff; }
|
||||
else { remote_point = temp_remote; }
|
||||
temp_remote = locations[i];
|
||||
if (value == 0) { remote_point = temp_remote - delta_diff; }
|
||||
else { remote_point = temp_remote - (delta_diff / 2); }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -115,7 +115,8 @@ INSTANTIATE_TEST_CASE_P(/**/, Objdetect_QRCode, testing::ValuesIn(qrcode_images_
|
||||
|
||||
TEST(Objdetect_QRCode_basic, not_found_qrcode)
|
||||
{
|
||||
std::vector<Point> corners, straight_barcode;
|
||||
std::vector<Point> corners;
|
||||
Mat straight_barcode;
|
||||
std::string decoded_info;
|
||||
Mat zero_image = Mat::zeros(256, 256, CV_8UC1);
|
||||
EXPECT_FALSE(detectQRCode(zero_image, corners));
|
||||
|
@ -43,7 +43,11 @@ ocv_target_link_libraries(${the_module} LINK_PRIVATE ${deps})
|
||||
if(DEFINED ${PYTHON}_CVPY_SUFFIX)
|
||||
set(CVPY_SUFFIX "${${PYTHON}_CVPY_SUFFIX}")
|
||||
else()
|
||||
execute_process(COMMAND ${${PYTHON}_EXECUTABLE} -c "import distutils.sysconfig; print(distutils.sysconfig.get_config_var('SO'))"
|
||||
set(__python_ext_suffix_var "EXT_SUFFIX")
|
||||
if("${${PYTHON}_VERSION_MAJOR}" STREQUAL "2")
|
||||
set(__python_ext_suffix_var "SO")
|
||||
endif()
|
||||
execute_process(COMMAND ${${PYTHON}_EXECUTABLE} -c "import distutils.sysconfig; print(distutils.sysconfig.get_config_var('${__python_ext_suffix_var}'))"
|
||||
RESULT_VARIABLE PYTHON_CVPY_PROCESS
|
||||
OUTPUT_VARIABLE CVPY_SUFFIX
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
|
@ -723,7 +723,7 @@ public:
|
||||
|
||||
@note In @ref videoio_c "C API", functions cvRetrieveFrame() and cv.RetrieveFrame() return image stored inside the video
|
||||
capturing structure. It is not allowed to modify or release the image! You can copy the frame using
|
||||
:ocvcvCloneImage and then do whatever you want with the copy.
|
||||
cvCloneImage and then do whatever you want with the copy.
|
||||
*/
|
||||
CV_WRAP virtual bool retrieve(OutputArray image, int flag = 0);
|
||||
|
||||
@ -749,7 +749,7 @@ public:
|
||||
|
||||
@note In @ref videoio_c "C API", functions cvRetrieveFrame() and cv.RetrieveFrame() return image stored inside the video
|
||||
capturing structure. It is not allowed to modify or release the image! You can copy the frame using
|
||||
:ocvcvCloneImage and then do whatever you want with the copy.
|
||||
cvCloneImage and then do whatever you want with the copy.
|
||||
*/
|
||||
CV_WRAP virtual bool read(OutputArray image);
|
||||
|
||||
|
@ -31,8 +31,11 @@ from __future__ import print_function
|
||||
import glob, re, os, os.path, shutil, string, sys, argparse, traceback, multiprocessing
|
||||
from subprocess import check_call, check_output, CalledProcessError
|
||||
|
||||
IPHONEOS_DEPLOYMENT_TARGET='8.0' # default, can be changed via command line options or environemnt variable
|
||||
|
||||
def execute(cmd, cwd = None):
|
||||
print("Executing: %s in %s" % (cmd, cwd), file=sys.stderr)
|
||||
print('Executing: ' + ' '.join(cmd))
|
||||
retcode = check_call(cmd, cwd = cwd)
|
||||
if retcode != 0:
|
||||
raise Exception("Child returned:", retcode)
|
||||
@ -151,7 +154,7 @@ class Builder:
|
||||
|
||||
if self.dynamic:
|
||||
buildcmd += [
|
||||
"IPHONEOS_DEPLOYMENT_TARGET=8.0",
|
||||
"IPHONEOS_DEPLOYMENT_TARGET=" + os.environ['IPHONEOS_DEPLOYMENT_TARGET'],
|
||||
"ONLY_ACTIVE_ARCH=NO",
|
||||
]
|
||||
|
||||
@ -164,7 +167,7 @@ class Builder:
|
||||
else:
|
||||
arch = ";".join(archs)
|
||||
buildcmd += [
|
||||
"IPHONEOS_DEPLOYMENT_TARGET=8.0",
|
||||
"IPHONEOS_DEPLOYMENT_TARGET=" + os.environ['IPHONEOS_DEPLOYMENT_TARGET'],
|
||||
"ARCHS=%s" % arch,
|
||||
]
|
||||
|
||||
@ -186,7 +189,7 @@ class Builder:
|
||||
cmakecmd = self.getCMakeArgs(arch, target) + \
|
||||
(["-DCMAKE_TOOLCHAIN_FILE=%s" % toolchain] if toolchain is not None else [])
|
||||
if target.lower().startswith("iphoneos"):
|
||||
cmakecmd.append("-DCPU_BASELINE=NEON;FP16")
|
||||
cmakecmd.append("-DCPU_BASELINE=DETECT")
|
||||
cmakecmd.append(self.opencv)
|
||||
cmakecmd.extend(cmakeargs)
|
||||
execute(cmakecmd, cwd = builddir)
|
||||
@ -280,14 +283,21 @@ if __name__ == "__main__":
|
||||
parser.add_argument('--without', metavar='MODULE', default=[], action='append', help='OpenCV modules to exclude from the framework')
|
||||
parser.add_argument('--dynamic', default=False, action='store_true', help='build dynamic framework (default is "False" - builds static framework)')
|
||||
parser.add_argument('--disable-bitcode', default=False, dest='bitcodedisabled', action='store_true', help='disable bitcode (enabled by default)')
|
||||
parser.add_argument('--iphoneos_deployment_target', default=os.environ.get('IPHONEOS_DEPLOYMENT_TARGET', IPHONEOS_DEPLOYMENT_TARGET), help='specify IPHONEOS_DEPLOYMENT_TARGET')
|
||||
parser.add_argument('--iphoneos_archs', default='armv7,armv7s,arm64', help='select iPhoneOS target ARCHS')
|
||||
args = parser.parse_args()
|
||||
|
||||
os.environ['IPHONEOS_DEPLOYMENT_TARGET'] = args.iphoneos_deployment_target
|
||||
print('Using IPHONEOS_DEPLOYMENT_TARGET=' + os.environ['IPHONEOS_DEPLOYMENT_TARGET'])
|
||||
iphoneos_archs = args.iphoneos_archs.split(',')
|
||||
print('Using iPhoneOS ARCHS=' + str(iphoneos_archs))
|
||||
|
||||
b = iOSBuilder(args.opencv, args.contrib, args.dynamic, args.bitcodedisabled, args.without,
|
||||
[
|
||||
(["armv7s", "arm64"], "iPhoneOS"),
|
||||
(iphoneos_archs, "iPhoneOS"),
|
||||
] if os.environ.get('BUILD_PRECOMMIT', None) else
|
||||
[
|
||||
(["armv7", "armv7s", "arm64"], "iPhoneOS"),
|
||||
(iphoneos_archs, "iPhoneOS"),
|
||||
(["i386", "x86_64"], "iPhoneSimulator"),
|
||||
])
|
||||
b.build(args.out)
|
||||
|
@ -90,6 +90,13 @@ if(APPLE_FRAMEWORK AND NOT BUILD_SHARED_LIBS)
|
||||
set(CMAKE_OSX_ARCHITECTURES "${IOS_ARCH}" CACHE INTERNAL "Build architecture for iOS" FORCE)
|
||||
endif()
|
||||
|
||||
if(NOT DEFINED IPHONEOS_DEPLOYMENT_TARGET)
|
||||
if(NOT DEFINED ENV{IPHONEOS_DEPLOYMENT_TARGET})
|
||||
message(FATAL_ERROR "IPHONEOS_DEPLOYMENT_TARGET is not specified")
|
||||
endif()
|
||||
set(IPHONEOS_DEPLOYMENT_TARGET "$ENV{IPHONEOS_DEPLOYMENT_TARGET}")
|
||||
endif()
|
||||
|
||||
if(NOT __IN_TRY_COMPILE)
|
||||
set(_xcodebuild_wrapper "${CMAKE_BINARY_DIR}/xcodebuild_wrapper")
|
||||
if(NOT DEFINED CMAKE_MAKE_PROGRAM) # empty since CMake 3.10
|
||||
@ -103,14 +110,14 @@ if(NOT __IN_TRY_COMPILE)
|
||||
if(APPLE_FRAMEWORK AND BUILD_SHARED_LIBS)
|
||||
set(_xcodebuild_wrapper_tmp "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/xcodebuild_wrapper")
|
||||
file(WRITE "${_xcodebuild_wrapper_tmp}" "#!/bin/sh
|
||||
${CMAKE_MAKE_PROGRAM} IPHONEOS_DEPLOYMENT_TARGET=8.0 -sdk ${CMAKE_OSX_SYSROOT} \$*")
|
||||
${CMAKE_MAKE_PROGRAM} IPHONEOS_DEPLOYMENT_TARGET=${IPHONEOS_DEPLOYMENT_TARGET} -sdk ${CMAKE_OSX_SYSROOT} \$*")
|
||||
# Make executable
|
||||
file(COPY "${_xcodebuild_wrapper_tmp}" DESTINATION ${CMAKE_BINARY_DIR} FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
|
||||
set(CMAKE_MAKE_PROGRAM "${_xcodebuild_wrapper}" CACHE INTERNAL "" FORCE)
|
||||
else()
|
||||
set(_xcodebuild_wrapper_tmp "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/xcodebuild_wrapper")
|
||||
file(WRITE "${_xcodebuild_wrapper_tmp}" "#!/bin/sh
|
||||
${CMAKE_MAKE_PROGRAM} IPHONEOS_DEPLOYMENT_TARGET=8.0 ARCHS=${IOS_ARCH} -sdk ${CMAKE_OSX_SYSROOT} \$*")
|
||||
${CMAKE_MAKE_PROGRAM} IPHONEOS_DEPLOYMENT_TARGET=${IPHONEOS_DEPLOYMENT_TARGET} ARCHS=${IOS_ARCH} -sdk ${CMAKE_OSX_SYSROOT} \$*")
|
||||
# Make executable
|
||||
file(COPY "${_xcodebuild_wrapper_tmp}" DESTINATION ${CMAKE_BINARY_DIR} FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
|
||||
set(CMAKE_MAKE_PROGRAM "${_xcodebuild_wrapper}" CACHE INTERNAL "" FORCE)
|
||||
@ -162,4 +169,4 @@ set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
||||
|
||||
toolchain_save_config(IOS_ARCH)
|
||||
toolchain_save_config(IOS_ARCH IPHONEOS_DEPLOYMENT_TARGET)
|
||||
|
@ -0,0 +1,148 @@
|
||||
/**
|
||||
* @brief You will learn how to remove periodic noise in the Fourier domain
|
||||
* @author Karpushin Vladislav, karpushin@ngs.ru, https://github.com/VladKarpushin
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <opencv2/imgcodecs.hpp>
|
||||
#include <opencv2/imgproc.hpp>
|
||||
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
|
||||
void fftshift(const Mat& inputImg, Mat& outputImg);
|
||||
void filter2DFreq(const Mat& inputImg, Mat& outputImg, const Mat& H);
|
||||
void synthesizeFilterH(Mat& inputOutput_H, Point center, int radius);
|
||||
void calcPSD(const Mat& inputImg, Mat& outputImg, int flag = 0);
|
||||
|
||||
int main()
|
||||
{
|
||||
Mat imgIn = imread("input.jpg", IMREAD_GRAYSCALE);
|
||||
if (imgIn.empty()) //check whether the image is loaded or not
|
||||
{
|
||||
cout << "ERROR : Image cannot be loaded..!!" << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
imgIn.convertTo(imgIn, CV_32F);
|
||||
|
||||
//! [main]
|
||||
// it needs to process even image only
|
||||
Rect roi = Rect(0, 0, imgIn.cols & -2, imgIn.rows & -2);
|
||||
imgIn = imgIn(roi);
|
||||
|
||||
// PSD calculation (start)
|
||||
Mat imgPSD;
|
||||
calcPSD(imgIn, imgPSD);
|
||||
fftshift(imgPSD, imgPSD);
|
||||
normalize(imgPSD, imgPSD, 0, 255, NORM_MINMAX);
|
||||
// PSD calculation (stop)
|
||||
|
||||
//H calculation (start)
|
||||
Mat H = Mat(roi.size(), CV_32F, Scalar(1));
|
||||
const int r = 21;
|
||||
synthesizeFilterH(H, Point(705, 458), r);
|
||||
synthesizeFilterH(H, Point(850, 391), r);
|
||||
synthesizeFilterH(H, Point(993, 325), r);
|
||||
//H calculation (stop)
|
||||
// filtering (start)
|
||||
Mat imgOut;
|
||||
fftshift(H, H);
|
||||
filter2DFreq(imgIn, imgOut, H);
|
||||
// filtering (stop)
|
||||
//! [main]
|
||||
|
||||
imgOut.convertTo(imgOut, CV_8U);
|
||||
normalize(imgOut, imgOut, 0, 255, NORM_MINMAX);
|
||||
imwrite("result.jpg", imgOut);
|
||||
imwrite("PSD.jpg", imgPSD);
|
||||
fftshift(H, H);
|
||||
normalize(H, H, 0, 255, NORM_MINMAX);
|
||||
imwrite("filter.jpg", H);
|
||||
return 0;
|
||||
}
|
||||
|
||||
//! [fftshift]
|
||||
void fftshift(const Mat& inputImg, Mat& outputImg)
|
||||
{
|
||||
outputImg = inputImg.clone();
|
||||
int cx = outputImg.cols / 2;
|
||||
int cy = outputImg.rows / 2;
|
||||
Mat q0(outputImg, Rect(0, 0, cx, cy));
|
||||
Mat q1(outputImg, Rect(cx, 0, cx, cy));
|
||||
Mat q2(outputImg, Rect(0, cy, cx, cy));
|
||||
Mat q3(outputImg, Rect(cx, cy, cx, cy));
|
||||
Mat tmp;
|
||||
q0.copyTo(tmp);
|
||||
q3.copyTo(q0);
|
||||
tmp.copyTo(q3);
|
||||
q1.copyTo(tmp);
|
||||
q2.copyTo(q1);
|
||||
tmp.copyTo(q2);
|
||||
}
|
||||
//! [fftshift]
|
||||
|
||||
//! [filter2DFreq]
|
||||
void filter2DFreq(const Mat& inputImg, Mat& outputImg, const Mat& H)
|
||||
{
|
||||
Mat planes[2] = { Mat_<float>(inputImg.clone()), Mat::zeros(inputImg.size(), CV_32F) };
|
||||
Mat complexI;
|
||||
merge(planes, 2, complexI);
|
||||
dft(complexI, complexI, DFT_SCALE);
|
||||
|
||||
Mat planesH[2] = { Mat_<float>(H.clone()), Mat::zeros(H.size(), CV_32F) };
|
||||
Mat complexH;
|
||||
merge(planesH, 2, complexH);
|
||||
Mat complexIH;
|
||||
mulSpectrums(complexI, complexH, complexIH, 0);
|
||||
|
||||
idft(complexIH, complexIH);
|
||||
split(complexIH, planes);
|
||||
outputImg = planes[0];
|
||||
}
|
||||
//! [filter2DFreq]
|
||||
|
||||
//! [synthesizeFilterH]
|
||||
void synthesizeFilterH(Mat& inputOutput_H, Point center, int radius)
|
||||
{
|
||||
Point c2 = center, c3 = center, c4 = center;
|
||||
c2.y = inputOutput_H.rows - center.y;
|
||||
c3.x = inputOutput_H.cols - center.x;
|
||||
c4 = Point(c3.x,c2.y);
|
||||
circle(inputOutput_H, center, radius, 0, -1, 8);
|
||||
circle(inputOutput_H, c2, radius, 0, -1, 8);
|
||||
circle(inputOutput_H, c3, radius, 0, -1, 8);
|
||||
circle(inputOutput_H, c4, radius, 0, -1, 8);
|
||||
}
|
||||
//! [synthesizeFilterH]
|
||||
|
||||
// Function calculates PSD(Power spectrum density) by fft with two flags
|
||||
// flag = 0 means to return PSD
|
||||
// flag = 1 means to return log(PSD)
|
||||
//! [calcPSD]
|
||||
void calcPSD(const Mat& inputImg, Mat& outputImg, int flag)
|
||||
{
|
||||
Mat planes[2] = { Mat_<float>(inputImg.clone()), Mat::zeros(inputImg.size(), CV_32F) };
|
||||
Mat complexI;
|
||||
merge(planes, 2, complexI);
|
||||
dft(complexI, complexI);
|
||||
split(complexI, planes); // planes[0] = Re(DFT(I)), planes[1] = Im(DFT(I))
|
||||
|
||||
planes[0].at<float>(0) = 0;
|
||||
planes[1].at<float>(0) = 0;
|
||||
|
||||
// compute the PSD = sqrt(Re(DFT(I))^2 + Im(DFT(I))^2)^2
|
||||
Mat imgPSD;
|
||||
magnitude(planes[0], planes[1], imgPSD); //imgPSD = sqrt(Power spectrum density)
|
||||
pow(imgPSD, 2, imgPSD); //it needs ^2 in order to get PSD
|
||||
outputImg = imgPSD;
|
||||
|
||||
// logPSD = log(1 + PSD)
|
||||
if (flag)
|
||||
{
|
||||
Mat imglogPSD;
|
||||
imglogPSD = imgPSD + Scalar::all(1);
|
||||
log(imglogPSD, imglogPSD);
|
||||
outputImg = imglogPSD;
|
||||
}
|
||||
}
|
||||
//! [calcPSD]
|
@ -58,10 +58,12 @@ std::string findFile(const std::string& filename)
|
||||
if (filename.empty() || utils::fs::exists(filename))
|
||||
return filename;
|
||||
|
||||
std::string extraPaths[] = {getenv("OPENCV_DNN_TEST_DATA_PATH"),
|
||||
const char* extraPaths[] = {getenv("OPENCV_DNN_TEST_DATA_PATH"),
|
||||
getenv("OPENCV_TEST_DATA_PATH")};
|
||||
for (int i = 0; i < 2; ++i)
|
||||
{
|
||||
if (extraPaths[i] == NULL)
|
||||
continue;
|
||||
std::string absPath = utils::fs::join(extraPaths[i], utils::fs::join("dnn", filename));
|
||||
if (utils::fs::exists(absPath))
|
||||
return absPath;
|
||||
|
Loading…
Reference in New Issue
Block a user