From e4a80aee09e9ec2f3566a07efa8f4bdb39e40157 Mon Sep 17 00:00:00 2001 From: Dmitry Kurtaev Date: Wed, 14 Aug 2019 19:44:05 +0300 Subject: [PATCH 01/18] Fix #15296 --- modules/dnn/src/tensorflow/tf_importer.cpp | 13 ++++++------- modules/dnn/test/test_tf_importer.cpp | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/modules/dnn/src/tensorflow/tf_importer.cpp b/modules/dnn/src/tensorflow/tf_importer.cpp index e546d9e1da..bdbe7d1a15 100644 --- a/modules/dnn/src/tensorflow/tf_importer.cpp +++ b/modules/dnn/src/tensorflow/tf_importer.cpp @@ -1129,15 +1129,14 @@ void TFImporter::populateNet(Net dstNet) if (value_id.find(layer.input(1)) != value_id.end()) { Mat newShape = getTensorContent(getConstBlob(layer, value_id, 1)); - + if (newShape.total() == 4) + { + // NHWC->NCHW + std::swap(*newShape.ptr(0, 2), *newShape.ptr(0, 3)); + std::swap(*newShape.ptr(0, 1), *newShape.ptr(0, 2)); + } if (inpLayout == DATA_LAYOUT_NHWC) { - if (newShape.total() == 4) - { - // NHWC->NCHW - std::swap(*newShape.ptr(0, 2), *newShape.ptr(0, 3)); - std::swap(*newShape.ptr(0, 1), *newShape.ptr(0, 2)); - } if (newShape.total() != 4 || newShape.at(1) == 1) { LayerParams permLP; diff --git a/modules/dnn/test/test_tf_importer.cpp b/modules/dnn/test/test_tf_importer.cpp index fa98e745f5..dac55d60b0 100644 --- a/modules/dnn/test/test_tf_importer.cpp +++ b/modules/dnn/test/test_tf_importer.cpp @@ -279,7 +279,7 @@ TEST_P(Test_TensorFlow_layers, matmul) // Reference output values are in range [-5.688, 4.484] double l1 = target == DNN_TARGET_MYRIAD ? 6.1e-3 : default_l1; runTensorFlowNet("nhwc_reshape_matmul", false, l1); - + runTensorFlowNet("matmul_layout"); } TEST_P(Test_TensorFlow_layers, reshape) From a1e96a7deb7078fa4fa4efb65a51ace9c9a8c6ba Mon Sep 17 00:00:00 2001 From: Suleyman TURKMEN Date: Thu, 15 Aug 2019 21:49:02 +0300 Subject: [PATCH 02/18] Update seamless_cloning.cpp --- modules/photo/src/seamless_cloning.cpp | 1 + modules/photo/test/test_cloning.cpp | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/modules/photo/src/seamless_cloning.cpp b/modules/photo/src/seamless_cloning.cpp index 2c05d9abfb..ee0045334f 100644 --- a/modules/photo/src/seamless_cloning.cpp +++ b/modules/photo/src/seamless_cloning.cpp @@ -78,6 +78,7 @@ void cv::seamlessClone(InputArray _src, InputArray _dst, InputArray _mask, Point copyMakeBorder(mask_inner, mask, 1, 1, 1, 1, BORDER_ISOLATED | BORDER_CONSTANT, Scalar(0)); Rect roi_s = boundingRect(mask); + if (roi_s.empty()) return; Rect roi_d(p.x - roi_s.width / 2, p.y - roi_s.height / 2, roi_s.width, roi_s.height); Mat destinationROI = dest(roi_d).clone(); diff --git a/modules/photo/test/test_cloning.cpp b/modules/photo/test/test_cloning.cpp index 34642d4120..e4d806a7f9 100644 --- a/modules/photo/test/test_cloning.cpp +++ b/modules/photo/test/test_cloning.cpp @@ -86,6 +86,15 @@ TEST(Photo_SeamlessClone_normal, regression) EXPECT_LE(errorINF, 1); double errorL1 = cvtest::norm(reference, result, NORM_L1); EXPECT_LE(errorL1, reference.total() * numerical_precision) << "size=" << reference.size(); + + mask = Scalar(0, 0, 0); + seamlessClone(source, destination, mask, p, result, 1); + + reference = destination; + errorINF = cvtest::norm(reference, result, NORM_INF); + EXPECT_LE(errorINF, 1); + errorL1 = cvtest::norm(reference, result, NORM_L1); + EXPECT_LE(errorL1, reference.total() * numerical_precision) << "size=" << reference.size(); } TEST(Photo_SeamlessClone_mixed, regression) From 04f720d56a1f28450bd1a6eab9c8aa9bf061d126 Mon Sep 17 00:00:00 2001 From: craterkamath Date: Mon, 19 Aug 2019 02:06:31 +0530 Subject: [PATCH 03/18] Fixed Typo Closes #15148 --- samples/python/camshift.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/python/camshift.py b/samples/python/camshift.py index 101da85b31..0fcab728c5 100755 --- a/samples/python/camshift.py +++ b/samples/python/camshift.py @@ -8,7 +8,7 @@ This is a demo that shows mean-shift based tracking You select a color objects such as your face and it tracks it. This reads from video camera (0 by default, or the camera number the user enters) -http://www.robinhewitt.com/research/track/camshift.html +[1] http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.14.7673 Usage: ------ From b1a5c762151daac9e1751e2f19031ca376a22c70 Mon Sep 17 00:00:00 2001 From: xitong Date: Mon, 19 Aug 2019 16:08:53 +0800 Subject: [PATCH 04/18] Fix a typo --- .../py_core/py_optimization/py_optimization.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/py_tutorials/py_core/py_optimization/py_optimization.markdown b/doc/py_tutorials/py_core/py_optimization/py_optimization.markdown index 7623a8ff3a..4631d3bf58 100644 --- a/doc/py_tutorials/py_core/py_optimization/py_optimization.markdown +++ b/doc/py_tutorials/py_core/py_optimization/py_optimization.markdown @@ -40,7 +40,7 @@ goal): img1 = cv.imread('messi5.jpg') e1 = cv.getTickCount() -for i in xrange(5,49,2): +for i in range(5,49,2): img1 = cv.medianBlur(img1,i) e2 = cv.getTickCount() t = (e2 - e1)/cv.getTickFrequency() From 8ef80886866a36d257566b8185b071414bd68501 Mon Sep 17 00:00:00 2001 From: Zyrin Date: Wed, 21 Aug 2019 10:57:03 +0200 Subject: [PATCH 05/18] Fix stack overflow on gcc with c++17 (#15343) --- modules/core/include/opencv2/core/mat.inl.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/core/include/opencv2/core/mat.inl.hpp b/modules/core/include/opencv2/core/mat.inl.hpp index a2e7923b39..d74b6e67b2 100644 --- a/modules/core/include/opencv2/core/mat.inl.hpp +++ b/modules/core/include/opencv2/core/mat.inl.hpp @@ -1809,7 +1809,7 @@ Mat_<_Tp> Mat_<_Tp>::cross(const Mat_& m) const template template inline Mat_<_Tp>::operator Mat_() const { - return Mat_(*this); + return Mat_(static_cast(*this)); } template inline From 869ea22f34407998256d9a4a570e30e3ba48feb8 Mon Sep 17 00:00:00 2001 From: Zyrin Date: Wed, 21 Aug 2019 11:12:00 +0200 Subject: [PATCH 06/18] Use std::move in Mat_ move constructors --- modules/core/include/opencv2/core/mat.inl.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/core/include/opencv2/core/mat.inl.hpp b/modules/core/include/opencv2/core/mat.inl.hpp index d74b6e67b2..bfa28a1cdf 100644 --- a/modules/core/include/opencv2/core/mat.inl.hpp +++ b/modules/core/include/opencv2/core/mat.inl.hpp @@ -2103,7 +2103,7 @@ void Mat_<_Tp>::forEach(const Functor& operation) const { template inline Mat_<_Tp>::Mat_(Mat_&& m) - : Mat(m) + : Mat(std::move(m)) { } @@ -2119,7 +2119,7 @@ Mat_<_Tp>::Mat_(Mat&& m) : Mat() { flags = (flags & ~CV_MAT_TYPE_MASK) | traits::Type<_Tp>::value; - *this = m; + *this = std::move(m); } template inline From 58ca013b90e3ddc74917f60a9630ac8e9c08f4a4 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Wed, 21 Aug 2019 02:59:09 -0700 Subject: [PATCH 07/18] Merge pull request #15279 from neheb:patch-1 * jas_stream: Add definition for L_tmpnam if missing uClibc-ng for some reason does not provide a definition when some deprecated APIs are disabled. Value taken from the musl libc. * 3rdparty: move uClibc-ng workaround into config file --- 3rdparty/libjasper/jasper/jas_config.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/3rdparty/libjasper/jasper/jas_config.h b/3rdparty/libjasper/jasper/jas_config.h index 987fb81467..39f1424b9d 100644 --- a/3rdparty/libjasper/jasper/jas_config.h +++ b/3rdparty/libjasper/jasper/jas_config.h @@ -17,6 +17,12 @@ #if !defined(JAS_WIN_MSVC_BUILD) /* A configure-based build is being used. */ +#include + +// uClibc-ng workaround: https://github.com/opencv/opencv/pull/15279 +#ifndef L_tmpnam +#define L_tmpnam 20 +#endif /* Extra debugging support */ From 464972855e25f71667009b8fe88092d11aab0297 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Tue, 20 Aug 2019 16:19:37 +0300 Subject: [PATCH 08/18] cmake: add libatomic check --- CMakeLists.txt | 4 ++++ cmake/OpenCVDetectCXXCompiler.cmake | 18 ++++++++++++++++++ cmake/OpenCVUtils.cmake | 24 +++++++++++++++++++++++- cmake/checks/atomic_check.cpp | 12 ++++++++++++ 4 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 cmake/checks/atomic_check.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 4ac553bbde..894656c1ea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,6 +64,10 @@ if(POLICY CMP0068) cmake_policy(SET CMP0068 NEW) # CMake 3.9+: `RPATH` settings on macOS do not affect `install_name`. endif() +if(POLICY CMP0075) + cmake_policy(SET CMP0075 NEW) # CMake 3.12+: Include file check macros honor `CMAKE_REQUIRED_LIBRARIES` +endif() + # # Configure OpenCV CMake hooks diff --git a/cmake/OpenCVDetectCXXCompiler.cmake b/cmake/OpenCVDetectCXXCompiler.cmake index b17895ae16..be64e55286 100644 --- a/cmake/OpenCVDetectCXXCompiler.cmake +++ b/cmake/OpenCVDetectCXXCompiler.cmake @@ -194,3 +194,21 @@ if(NOT HAVE_CXX11) endif() endif() endif() + +if((HAVE_CXX11 + AND NOT MSVC + AND NOT (X86 OR X86_64) + AND NOT OPENCV_SKIP_LIBATOMIC_COMPILER_CHECK) + OR OPENCV_FORCE_LIBATOMIC_COMPILER_CHECK +) + ocv_check_compiler_flag(CXX "" HAVE_CXX_ATOMICS_WITHOUT_LIB "${OpenCV_SOURCE_DIR}/cmake/checks/atomic_check.cpp") + if(NOT HAVE_CXX_ATOMICS_WITHOUT_LIB) + list(APPEND CMAKE_REQUIRED_LIBRARIES atomic) + ocv_check_compiler_flag(CXX "" HAVE_CXX_ATOMICS_WITH_LIB "${OpenCV_SOURCE_DIR}/cmake/checks/atomic_check.cpp") + if(HAVE_CXX_ATOMICS_WITH_LIB) + list(APPEND OPENCV_LINKER_LIBS atomic) + else() + message(FATAL_ERROR "C++11 compiler must support std::atomic") + endif() + endif() +endif() diff --git a/cmake/OpenCVUtils.cmake b/cmake/OpenCVUtils.cmake index 7317398fb2..a876d9c02c 100644 --- a/cmake/OpenCVUtils.cmake +++ b/cmake/OpenCVUtils.cmake @@ -415,12 +415,34 @@ MACRO(ocv_check_compiler_flag LANG FLAG RESULT) else() set(__msg "") endif() + if(CMAKE_REQUIRED_LIBRARIES) + set(__link_libs LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}) + else() + set(__link_libs) + endif() + set(__cmake_flags "") + if(CMAKE_EXE_LINKER_FLAGS) # CMP0056 do this on new CMake + list(APPEND __cmake_flags "-DCMAKE_EXE_LINKER_FLAGS=${CMAKE_EXE_LINKER_FLAGS}") + endif() + + # CMP0067 do this on new CMake + if(DEFINED CMAKE_CXX_STANDARD) + list(APPEND __cmake_flags "-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}") + endif() + if(DEFINED CMAKE_CXX_STANDARD_REQUIRED) + list(APPEND __cmake_flags "-DCMAKE_CXX_STANDARD_REQUIRED=${CMAKE_CXX_STANDARD_REQUIRED}") + endif() + if(DEFINED CMAKE_CXX_EXTENSIONS) + list(APPEND __cmake_flags "-DCMAKE_CXX_EXTENSIONS=${CMAKE_CXX_EXTENSIONS}") + endif() + MESSAGE(STATUS "Performing Test ${RESULT}${__msg}") TRY_COMPILE(${RESULT} "${CMAKE_BINARY_DIR}" "${_fname}" - CMAKE_FLAGS "-DCMAKE_EXE_LINKER_FLAGS=${CMAKE_EXE_LINKER_FLAGS}" # CMP0056 do this on new CMake + CMAKE_FLAGS ${__cmake_flags} COMPILE_DEFINITIONS "${FLAG}" + ${__link_libs} OUTPUT_VARIABLE OUTPUT) if(${RESULT}) diff --git a/cmake/checks/atomic_check.cpp b/cmake/checks/atomic_check.cpp new file mode 100644 index 0000000000..c9770a0bfa --- /dev/null +++ b/cmake/checks/atomic_check.cpp @@ -0,0 +1,12 @@ +#include + +static int test() +{ + std::atomic x; + return x; +} + +int main() +{ + return test(); +} From 70ce2bbb9e6107247fe4a7a7771dfa1d962af7dc Mon Sep 17 00:00:00 2001 From: dab0bby <9976654+dab0bby@users.noreply.github.com> Date: Wed, 21 Aug 2019 14:52:31 +0200 Subject: [PATCH 09/18] fix typo and reference --- doc/py_tutorials/py_feature2d/py_matcher/py_matcher.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/py_tutorials/py_feature2d/py_matcher/py_matcher.markdown b/doc/py_tutorials/py_feature2d/py_matcher/py_matcher.markdown index ca7853d96a..d8ba8f856d 100644 --- a/doc/py_tutorials/py_feature2d/py_matcher/py_matcher.markdown +++ b/doc/py_tutorials/py_feature2d/py_matcher/py_matcher.markdown @@ -38,13 +38,13 @@ best matches. There is also **cv.drawMatchesKnn** which draws all the k best mat will draw two match-lines for each keypoint. So we have to pass a mask if we want to selectively draw it. -Let's see one example for each of SURF and ORB (Both use different distance measurements). +Let's see one example for each of SIFT and ORB (Both use different distance measurements). ### Brute-Force Matching with ORB Descriptors Here, we will see a simple example on how to match features between two images. In this case, I have a queryImage and a trainImage. We will try to find the queryImage in trainImage using feature -matching. ( The images are /samples/c/box.png and /samples/c/box_in_scene.png) +matching. ( The images are /samples/data/box.png and /samples/data/box_in_scene.png) We are using ORB descriptors to match features. So let's start with loading images, finding descriptors etc. From 3f7cc456860ecdebef13bb2f4969bcb0f0ac1415 Mon Sep 17 00:00:00 2001 From: Prakhar Varshney <31482164+prakhar9998@users.noreply.github.com> Date: Thu, 22 Aug 2019 14:55:27 +0530 Subject: [PATCH 10/18] Merge pull request #15345 from prakhar9998:patch-1 * fix broken code link resolves #15344 * Update stitcher.markdown * update 3.4 link --- doc/tutorials/stitching/stitcher/stitcher.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/tutorials/stitching/stitcher/stitcher.markdown b/doc/tutorials/stitching/stitcher/stitcher.markdown index f0e7731e51..4bd6dc4841 100644 --- a/doc/tutorials/stitching/stitcher/stitcher.markdown +++ b/doc/tutorials/stitching/stitcher/stitcher.markdown @@ -15,7 +15,7 @@ Code ---- This tutorial code's is shown lines below. You can also download it from -[here](https://github.com/opencv/opencv/tree/3.4/samples/cpp/samples/cpp/stitching.cpp). +[here](https://github.com/opencv/opencv/tree/3.4/samples/cpp/stitching.cpp). @include samples/cpp/stitching.cpp From 8b1fe8f6e0ef4bff4024d091131458ca83879797 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Thu, 22 Aug 2019 15:39:51 +0300 Subject: [PATCH 11/18] core: fix stat SIMD code --- modules/core/src/stat.simd.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/core/src/stat.simd.hpp b/modules/core/src/stat.simd.hpp index 34b784e12e..b8ae15dc91 100644 --- a/modules/core/src/stat.simd.hpp +++ b/modules/core/src/stat.simd.hpp @@ -110,7 +110,7 @@ int normHamming(const uchar* a, const uchar* b, int n) { v_uint64x2 t = v_setzero_u64(); for(; i <= n - v_uint8x16::nlanes; i += v_uint8x16::nlanes) - t += v_popcount(v_reinterpret_as_u64(vx_load(a + i) ^ vx_load(b + i))); + t += v_popcount(v_reinterpret_as_u64(v_load(a + i) ^ v_load(b + i))); result += (int)v_reduce_sum(t); } #endif From 8a0b93bc4dd3183eb63ff6eed42120463878058c Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Wed, 21 Aug 2019 22:21:53 +0000 Subject: [PATCH 12/18] core: update fastmath.hpp --- .../core/include/opencv2/core/fast_math.hpp | 190 ++++++++++++------ 1 file changed, 129 insertions(+), 61 deletions(-) diff --git a/modules/core/include/opencv2/core/fast_math.hpp b/modules/core/include/opencv2/core/fast_math.hpp index b1e8c4202d..0e8187cac0 100644 --- a/modules/core/include/opencv2/core/fast_math.hpp +++ b/modules/core/include/opencv2/core/fast_math.hpp @@ -47,12 +47,6 @@ #include "opencv2/core/cvdef.h" -#if ((defined _MSC_VER && defined _M_X64) || (defined __GNUC__ && defined __x86_64__ \ - && defined __SSE2__ && !defined __APPLE__)) && !defined(__CUDACC__) -#include -#endif - - //! @addtogroup core_utils //! @{ @@ -70,19 +64,24 @@ # endif #endif -#ifdef HAVE_TEGRA_OPTIMIZATION -# include "tegra_round.hpp" -#endif +#if defined(__CUDACC__) + // nothing, intrinsics/asm code is not supported +#else + #if ((defined _MSC_VER && defined _M_X64) \ + || (defined __GNUC__ && defined __x86_64__ && defined __SSE2__)) \ + && !defined(OPENCV_SKIP_INCLUDE_EMMINTRIN_H) + #include + #endif -#if defined __PPC64__ && defined __GNUC__ && defined _ARCH_PWR8 && !defined (__CUDACC__) -# include -#endif + #if defined __PPC64__ && defined __GNUC__ && defined _ARCH_PWR8 \ + && !defined(OPENCV_SKIP_INCLUDE_ALTIVEC_H) + #include + #endif -#if ((defined _MSC_VER && defined _M_ARM) || defined CV_ICC || \ - defined __GNUC__) && defined HAVE_TEGRA_OPTIMIZATION - #define CV_INLINE_ROUND_DBL(value) TEGRA_ROUND_DBL(value); - #define CV_INLINE_ROUND_FLT(value) TEGRA_ROUND_FLT(value); -#elif defined __GNUC__ && defined __arm__ && (defined __ARM_PCS_VFP || defined __ARM_VFPV3__ || defined __ARM_NEON__) && !defined __SOFTFP__ && !defined(__CUDACC__) + #if defined(CV_INLINE_ROUND_FLT) + // user-specified version + // CV_INLINE_ROUND_DBL should be defined too + #elif defined __GNUC__ && defined __arm__ && (defined __ARM_PCS_VFP || defined __ARM_VFPV3__ || defined __ARM_NEON__) && !defined __SOFTFP__ // 1. general scheme #define ARM_ROUND(_value, _asm_string) \ int res; \ @@ -98,7 +97,7 @@ #endif // 3. version for float #define CV_INLINE_ROUND_FLT(value) ARM_ROUND(value, "vcvtr.s32.f32 %[temp], %[value]\n vmov %[res], %[temp]") -#elif defined __PPC64__ && defined __GNUC__ && defined _ARCH_PWR8 && !defined (__CUDACC__) + #elif defined __PPC64__ && defined __GNUC__ && defined _ARCH_PWR8 // P8 and newer machines can convert fp32/64 to int quickly. #define CV_INLINE_ROUND_DBL(value) \ int out; \ @@ -108,40 +107,86 @@ // FP32 also works with FP64 routine above #define CV_INLINE_ROUND_FLT(value) CV_INLINE_ROUND_DBL(value) + #endif - #ifdef _ARCH_PWR9 - #define CV_INLINE_ISINF_DBL(value) return scalar_test_data_class(value, 0x30); - #define CV_INLINE_ISNAN_DBL(value) return scalar_test_data_class(value, 0x40); - #define CV_INLINE_ISINF_FLT(value) CV_INLINE_ISINF_DBL(value) - #define CV_INLINE_ISNAN_FLT(value) CV_INLINE_ISNAN_DBL(value) + #ifdef CV_INLINE_ISINF_FLT + // user-specified version + // CV_INLINE_ISINF_DBL should be defined too + #elif defined __PPC64__ && defined _ARCH_PWR9 && defined(scalar_test_data_class) + #define CV_INLINE_ISINF_DBL(value) return scalar_test_data_class(value, 0x30); + #define CV_INLINE_ISINF_FLT(value) CV_INLINE_ISINF_DBL(value) + #endif + + #ifdef CV_INLINE_ISNAN_FLT + // user-specified version + // CV_INLINE_ISNAN_DBL should be defined too + #elif defined __PPC64__ && defined _ARCH_PWR9 && defined(scalar_test_data_class) + #define CV_INLINE_ISNAN_DBL(value) return scalar_test_data_class(value, 0x40); + #define CV_INLINE_ISNAN_FLT(value) CV_INLINE_ISNAN_DBL(value) + #endif + + #if !defined(OPENCV_USE_FASTMATH_BUILTINS) \ + && ( \ + defined(__x86_64__) || defined(__i686__) \ + || defined(__arm__) \ + || defined(__PPC64__) \ + ) + /* Let builtin C math functions when available. Dedicated hardware is available to + round and convert FP values. */ + #define OPENCV_USE_FASTMATH_BUILTINS 1 + #endif + + /* Enable builtin math functions if possible, desired, and available. + Note, not all math functions inline equally. E.g lrint will not inline + without the -fno-math-errno option. */ + #if defined(CV_ICC) + // nothing + #elif defined(OPENCV_USE_FASTMATH_BUILTINS) && OPENCV_USE_FASTMATH_BUILTINS + #if defined(__clang__) + #define CV__FASTMATH_ENABLE_CLANG_MATH_BUILTINS + #if !defined(CV_INLINE_ISNAN_DBL) && __has_builtin(__builtin_isnan) + #define CV_INLINE_ISNAN_DBL(value) return __builtin_isnan(value); + #endif + #if !defined(CV_INLINE_ISNAN_FLT) && __has_builtin(__builtin_isnan) + #define CV_INLINE_ISNAN_FLT(value) return __builtin_isnan(value); + #endif + #if !defined(CV_INLINE_ISINF_DBL) && __has_builtin(__builtin_isinf) + #define CV_INLINE_ISINF_DBL(value) return __builtin_isinf(value); + #endif + #if !defined(CV_INLINE_ISINF_FLT) && __has_builtin(__builtin_isinf) + #define CV_INLINE_ISINF_FLT(value) return __builtin_isinf(value); + #endif + #elif defined(__GNUC__) + #define CV__FASTMATH_ENABLE_GCC_MATH_BUILTINS + #if !defined(CV_INLINE_ISNAN_DBL) + #define CV_INLINE_ISNAN_DBL(value) return __builtin_isnan(value); + #endif + #if !defined(CV_INLINE_ISNAN_FLT) + #define CV_INLINE_ISNAN_FLT(value) return __builtin_isnanf(value); + #endif + #if !defined(CV_INLINE_ISINF_DBL) + #define CV_INLINE_ISINF_DBL(value) return __builtin_isinf(value); + #endif + #if !defined(CV_INLINE_ISINF_FLT) + #define CV_INLINE_ISINF_FLT(value) return __builtin_isinff(value); + #endif + #elif defined(_MSC_VER) + #if !defined(CV_INLINE_ISNAN_DBL) + #define CV_INLINE_ISNAN_DBL(value) return isnan(value); + #endif + #if !defined(CV_INLINE_ISNAN_FLT) + #define CV_INLINE_ISNAN_FLT(value) return isnan(value); + #endif + #if !defined(CV_INLINE_ISINF_DBL) + #define CV_INLINE_ISINF_DBL(value) return isinf(value); + #endif + #if !defined(CV_INLINE_ISINF_FLT) + #define CV_INLINE_ISINF_FLT(value) return isinf(value); + #endif #endif -#elif defined CV_ICC || defined __GNUC__ - #define CV_INLINE_ROUND_DBL(value) return (int)(lrint(value)); - #define CV_INLINE_ROUND_FLT(value) return (int)(lrintf(value)); -#endif + #endif -#if defined __PPC64__ && !defined OPENCV_USE_FASTMATH_GCC_BUILTINS - /* Let GCC inline C math functions when available. Dedicated hardware is available to - round and covert FP values. */ - #define OPENCV_USE_FASTMATH_GCC_BUILTINS -#endif - -/* Enable GCC builtin math functions if possible, desired, and available. - Note, not all math functions inline equally. E.g lrint will not inline - without the -fno-math-errno option. */ -#if defined OPENCV_USE_FASTMATH_GCC_BUILTINS && defined __GNUC__ && !defined __clang__ && !defined (__CUDACC__) - #define _OPENCV_FASTMATH_ENABLE_GCC_MATH_BUILTINS -#endif - -/* Allow overrides for some functions which may benefit from tuning. Likewise, - note that isinf is not used as the return value is signed. */ -#if defined _OPENCV_FASTMATH_ENABLE_GCC_MATH_BUILTINS && !defined CV_INLINE_ISNAN_DBL - #define CV_INLINE_ISNAN_DBL(value) return __builtin_isnan(value); -#endif - -#if defined _OPENCV_FASTMATH_ENABLE_GCC_MATH_BUILTINS && !defined CV_INLINE_ISNAN_FLT - #define CV_INLINE_ISNAN_FLT(value) return __builtin_isnanf(value); -#endif +#endif // defined(__CUDACC__) /** @brief Rounds floating-point number to the nearest integer @@ -151,8 +196,11 @@ CV_INLINE int cvRound( double value ) { -#if ((defined _MSC_VER && defined _M_X64) || (defined __GNUC__ && defined __x86_64__ \ - && defined __SSE2__ && !defined __APPLE__) || CV_SSE2) && !defined(__CUDACC__) +#if defined CV_INLINE_ROUND_DBL + CV_INLINE_ROUND_DBL(value); +#elif ((defined _MSC_VER && defined _M_X64) || (defined __GNUC__ && defined __x86_64__ \ + && defined __SSE2__ && !defined __APPLE__) || CV_SSE2) \ + && !defined(__CUDACC__) __m128d t = _mm_set_sd( value ); return _mm_cvtsd_si32(t); #elif defined _MSC_VER && defined _M_IX86 @@ -163,8 +211,8 @@ cvRound( double value ) fistp t; } return t; -#elif defined CV_INLINE_ROUND_DBL - CV_INLINE_ROUND_DBL(value); +#elif defined CV_ICC || defined __GNUC__ + return (int)(lrint(value)); #else /* it's ok if round does not comply with IEEE754 standard; the tests should allow +/-1 difference when the tested functions use round */ @@ -182,7 +230,10 @@ cvRound( double value ) */ CV_INLINE int cvFloor( double value ) { -#if defined _OPENCV_FASTMATH_ENABLE_GCC_MATH_BUILTINS +#if (defined CV__FASTMATH_ENABLE_GCC_MATH_BUILTINS || defined CV__FASTMATH_ENABLE_CLANG_MATH_BUILTINS) \ + && ( \ + defined(__PPC64__) \ + ) return __builtin_floor(value); #else int i = (int)value; @@ -199,7 +250,10 @@ CV_INLINE int cvFloor( double value ) */ CV_INLINE int cvCeil( double value ) { -#if defined _OPENCV_FASTMATH_ENABLE_GCC_MATH_BUILTINS +#if (defined CV__FASTMATH_ENABLE_GCC_MATH_BUILTINS || defined CV__FASTMATH_ENABLE_CLANG_MATH_BUILTINS) \ + && ( \ + defined(__PPC64__) \ + ) return __builtin_ceil(value); #else int i = (int)value; @@ -235,6 +289,11 @@ CV_INLINE int cvIsInf( double value ) { #if defined CV_INLINE_ISINF_DBL CV_INLINE_ISINF_DBL(value); +#elif defined(__x86_64__) || defined(_M_X64) || defined(__aarch64__) || defined(__PPC64__) + Cv64suf ieee754; + ieee754.f = value; + return (ieee754.u & 0x7fffffff00000000) == + 0x7ff0000000000000; #else Cv64suf ieee754; ieee754.f = value; @@ -248,8 +307,11 @@ CV_INLINE int cvIsInf( double value ) /** @overload */ CV_INLINE int cvRound(float value) { -#if ((defined _MSC_VER && defined _M_X64) || (defined __GNUC__ && defined __x86_64__ \ - && defined __SSE2__ && !defined __APPLE__) || CV_SSE2) && !defined(__CUDACC__) +#if defined CV_INLINE_ROUND_FLT + CV_INLINE_ROUND_FLT(value); +#elif ((defined _MSC_VER && defined _M_X64) || (defined __GNUC__ && defined __x86_64__ \ + && defined __SSE2__ && !defined __APPLE__) || CV_SSE2) \ + && !defined(__CUDACC__) __m128 t = _mm_set_ss( value ); return _mm_cvtss_si32(t); #elif defined _MSC_VER && defined _M_IX86 @@ -260,8 +322,8 @@ CV_INLINE int cvRound(float value) fistp t; } return t; -#elif defined CV_INLINE_ROUND_FLT - CV_INLINE_ROUND_FLT(value); +#elif defined CV_ICC || defined __GNUC__ + return (int)(lrintf(value)); #else /* it's ok if round does not comply with IEEE754 standard; the tests should allow +/-1 difference when the tested functions use round */ @@ -278,7 +340,10 @@ CV_INLINE int cvRound( int value ) /** @overload */ CV_INLINE int cvFloor( float value ) { -#if defined _OPENCV_FASTMATH_ENABLE_GCC_MATH_BUILTINS +#if (defined CV__FASTMATH_ENABLE_GCC_MATH_BUILTINS || defined CV__FASTMATH_ENABLE_CLANG_MATH_BUILTINS) \ + && ( \ + defined(__PPC64__) \ + ) return __builtin_floorf(value); #else int i = (int)value; @@ -295,7 +360,10 @@ CV_INLINE int cvFloor( int value ) /** @overload */ CV_INLINE int cvCeil( float value ) { -#if defined _OPENCV_FASTMATH_ENABLE_GCC_MATH_BUILTINS +#if (defined CV__FASTMATH_ENABLE_GCC_MATH_BUILTINS || defined CV__FASTMATH_ENABLE_CLANG_MATH_BUILTINS) \ + && ( \ + defined(__PPC64__) \ + ) return __builtin_ceilf(value); #else int i = (int)value; From 8aca1934ff43ff0fb6f4ea861c8bf47658a2aace Mon Sep 17 00:00:00 2001 From: "Paul E. Murphy" Date: Thu, 22 Aug 2019 10:08:01 -0500 Subject: [PATCH 13/18] libpng: update check for VSX enablement The deprecated flag ENABLE_VSX should not be used to enable this feature. Instead, use the baseline cpu feature set to determine. --- 3rdparty/libpng/CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/3rdparty/libpng/CMakeLists.txt b/3rdparty/libpng/CMakeLists.txt index c0c2b133cb..69bc754048 100644 --- a/3rdparty/libpng/CMakeLists.txt +++ b/3rdparty/libpng/CMakeLists.txt @@ -47,7 +47,9 @@ if(";${CPU_BASELINE_FINAL};" MATCHES "SSE2" endif() if(PPC64LE OR PPC64) - if(ENABLE_VSX AND NOT PPC64) + # VSX3 features are backwards compatible + if(";${CPU_BASELINE_FINAL};" MATCHES "VSX.*" + AND NOT PPC64) list(APPEND lib_srcs powerpc/powerpc_init.c powerpc/filter_vsx_intrinsics.c) add_definitions(-DPNG_POWERPC_VSX_OPT=2) else() From 5a497077f109d543ab86dfdf8add1c76c0e47d29 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Fri, 23 Aug 2019 16:14:53 +0300 Subject: [PATCH 14/18] objdetect: add input check in HOG detector --- modules/objdetect/src/hog.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/modules/objdetect/src/hog.cpp b/modules/objdetect/src/hog.cpp index 9524851eeb..378bab3087 100644 --- a/modules/objdetect/src/hog.cpp +++ b/modules/objdetect/src/hog.cpp @@ -68,6 +68,7 @@ enum {DESCR_FORMAT_COL_BY_COL, DESCR_FORMAT_ROW_BY_ROW}; static int numPartsWithin(int size, int part_size, int stride) { + CV_Assert(stride != 0); return (size - part_size + stride) / stride; } @@ -80,13 +81,17 @@ static Size numPartsWithin(cv::Size size, cv::Size part_size, static size_t getBlockHistogramSize(Size block_size, Size cell_size, int nbins) { + CV_Assert(!cell_size.empty()); Size cells_per_block = Size(block_size.width / cell_size.width, - block_size.height / cell_size.height); + block_size.height / cell_size.height); return (size_t)(nbins * cells_per_block.area()); } size_t HOGDescriptor::getDescriptorSize() const { + CV_Assert(!cellSize.empty()); + CV_Assert(!blockStride.empty()); + CV_Assert(blockSize.width % cellSize.width == 0 && blockSize.height % cellSize.height == 0); CV_Assert((winSize.width - blockSize.width) % blockStride.width == 0 && @@ -144,20 +149,20 @@ bool HOGDescriptor::read(FileNode& obj) if( !obj.isMap() ) return false; FileNodeIterator it = obj["winSize"].begin(); - it >> winSize.width >> winSize.height; + it >> winSize.width >> winSize.height; CV_Assert(!winSize.empty()); it = obj["blockSize"].begin(); - it >> blockSize.width >> blockSize.height; + it >> blockSize.width >> blockSize.height; CV_Assert(!blockSize.empty()); it = obj["blockStride"].begin(); - it >> blockStride.width >> blockStride.height; + it >> blockStride.width >> blockStride.height; CV_Assert(!blockStride.empty()); it = obj["cellSize"].begin(); - it >> cellSize.width >> cellSize.height; - obj["nbins"] >> nbins; + it >> cellSize.width >> cellSize.height; CV_Assert(!cellSize.empty()); + obj["nbins"] >> nbins; CV_Assert(nbins > 0); obj["derivAperture"] >> derivAperture; obj["winSigma"] >> winSigma; obj["histogramNormType"] >> histogramNormType; obj["L2HysThreshold"] >> L2HysThreshold; obj["gammaCorrection"] >> gammaCorrection; - obj["nlevels"] >> nlevels; + obj["nlevels"] >> nlevels; CV_Assert(nlevels > 0); if (obj["signedGradient"].empty()) signedGradient = false; else From 29dbeb253c60de02e4289912ffe29e04e7caf46a Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Thu, 22 Aug 2019 16:26:58 +0300 Subject: [PATCH 15/18] build: fix build with ICC --- modules/imgproc/src/corner.avx.cpp | 6 +++--- modules/ts/include/opencv2/ts/ts_gtest.h | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/modules/imgproc/src/corner.avx.cpp b/modules/imgproc/src/corner.avx.cpp index a40b66d40a..1a62db3074 100644 --- a/modules/imgproc/src/corner.avx.cpp +++ b/modules/imgproc/src/corner.avx.cpp @@ -113,9 +113,9 @@ static void store_interleave(float* ptr, const __m256& a, const __m256& b, const v_pack4x3to3x4(u0.val, u1.val, u2.val, u3.val, a1, b1, c1); #if !defined(__GNUC__) || defined(__INTEL_COMPILER) - _mm256_storeu_ps(ptr, _mm256_setr_m128(_mm_castsi128_ps(a0), _mm_castsi128_ps(b0))); - _mm256_storeu_ps(ptr + 8, _mm256_setr_m128(_mm_castsi128_ps(c0), _mm_castsi128_ps(a1))); - _mm256_storeu_ps(ptr + 16, _mm256_setr_m128(_mm_castsi128_ps(b1), _mm_castsi128_ps(c1))); + _mm256_storeu_ps(ptr, _mm256_castsi256_ps(_mm256_setr_m128i(a0, b0))); + _mm256_storeu_ps(ptr + 8, _mm256_castsi256_ps(_mm256_setr_m128i(c0, a1))); + _mm256_storeu_ps(ptr + 16, _mm256_castsi256_ps(_mm256_setr_m128i(b1, c1))); #else // GCC: workaround for missing AVX intrinsic: "_mm256_setr_m128()" _mm256_storeu_ps(ptr, _mm256_insertf128_ps(_mm256_castps128_ps256(_mm_castsi128_ps(a0)), _mm_castsi128_ps(b0), 1)); diff --git a/modules/ts/include/opencv2/ts/ts_gtest.h b/modules/ts/include/opencv2/ts/ts_gtest.h index d41a846ad4..cd62024d58 100644 --- a/modules/ts/include/opencv2/ts/ts_gtest.h +++ b/modules/ts/include/opencv2/ts/ts_gtest.h @@ -21691,7 +21691,9 @@ class WithParamInterface { return *GetParameterPtrRef_(); } +#ifndef __INTEL_COMPILER // compilation workaround, templated friend is not handled properly by ICC (perhaps due using of anonymous namespaces) private: +#endif // Sets parameter value. The caller is responsible for making sure the value // remains alive and unchanged throughout the current test. static void SetParam(const ParamType* parameter) { From d7409604b5f8d96b460c4c6c0c118839fdb34734 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Fri, 23 Aug 2019 16:54:24 +0300 Subject: [PATCH 16/18] core: handle empty Mat in Mat_ assignment operators --- modules/core/include/opencv2/core/mat.inl.hpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/modules/core/include/opencv2/core/mat.inl.hpp b/modules/core/include/opencv2/core/mat.inl.hpp index bfa28a1cdf..4d8d6f059d 100644 --- a/modules/core/include/opencv2/core/mat.inl.hpp +++ b/modules/core/include/opencv2/core/mat.inl.hpp @@ -1744,6 +1744,11 @@ Mat_<_Tp>::Mat_(const std::array<_Tp, _Nm>& arr, bool copyData) template inline Mat_<_Tp>& Mat_<_Tp>::operator = (const Mat& m) { + if (m.empty()) + { + release(); + return *this; + } if( traits::Type<_Tp>::value == m.type() ) { Mat::operator = (m); @@ -2125,6 +2130,11 @@ Mat_<_Tp>::Mat_(Mat&& m) template inline Mat_<_Tp>& Mat_<_Tp>::operator = (Mat&& m) { + if (m.empty()) + { + release(); + return *this; + } if( traits::Type<_Tp>::value == m.type() ) { Mat::operator = ((Mat&&)m); From d0c4a92b4c06d03f11c07af3ecc9985e93f77100 Mon Sep 17 00:00:00 2001 From: Ilya Lavrenov Date: Fri, 23 Aug 2019 12:54:07 +0300 Subject: [PATCH 17/18] Adopted detection of Inference Engine --- CMakeLists.txt | 15 +++++++++------ cmake/OpenCVDetectInferenceEngine.cmake | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 894656c1ea..0cd7a56001 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1580,19 +1580,22 @@ endif() if(WITH_INF_ENGINE OR INF_ENGINE_TARGET) if(INF_ENGINE_TARGET) + list(GET INF_ENGINE_TARGET 0 ie_target) set(__msg "YES (${INF_ENGINE_RELEASE} / ${INF_ENGINE_VERSION})") - get_target_property(_lib ${INF_ENGINE_TARGET} IMPORTED_LOCATION) - get_target_property(_lib_imp_rel ${INF_ENGINE_TARGET} IMPORTED_IMPLIB_RELEASE) - get_target_property(_lib_imp_dbg ${INF_ENGINE_TARGET} IMPORTED_IMPLIB_DEBUG) - get_target_property(_lib_rel ${INF_ENGINE_TARGET} IMPORTED_LOCATION_RELEASE) - get_target_property(_lib_dbg ${INF_ENGINE_TARGET} IMPORTED_LOCATION_DEBUG) + get_target_property(_lib ${ie_target} IMPORTED_LOCATION) + get_target_property(_lib_imp_rel ${ie_target} IMPORTED_IMPLIB_RELEASE) + get_target_property(_lib_imp_dbg ${ie_target} IMPORTED_IMPLIB_DEBUG) + get_target_property(_lib_rel ${ie_target} IMPORTED_LOCATION_RELEASE) + get_target_property(_lib_dbg ${ie_target} IMPORTED_LOCATION_DEBUG) ocv_build_features_string(_lib IF _lib THEN "${_lib}" IF _lib_imp_rel AND _lib_imp_dbg THEN "${_lib_imp_rel} / ${_lib_imp_dbg}" IF _lib_rel AND _lib_dbg THEN "${_lib_rel} / ${_lib_dbg}" + IF _lib_rel THEN "${_lib_rel}" + IF _lib_dbg THEN "${_lib_dbg}" ELSE "unknown" ) - get_target_property(_inc ${INF_ENGINE_TARGET} INTERFACE_INCLUDE_DIRECTORIES) + get_target_property(_inc ${ie_target} INTERFACE_INCLUDE_DIRECTORIES) status(" Inference Engine:" "${__msg}") status(" libs:" "${_lib}") status(" includes:" "${_inc}") diff --git a/cmake/OpenCVDetectInferenceEngine.cmake b/cmake/OpenCVDetectInferenceEngine.cmake index a4d0bbddd3..fb49ee6ff4 100644 --- a/cmake/OpenCVDetectInferenceEngine.cmake +++ b/cmake/OpenCVDetectInferenceEngine.cmake @@ -52,7 +52,7 @@ endfunction() find_package(InferenceEngine QUIET) if(InferenceEngine_FOUND) - set(INF_ENGINE_TARGET IE::inference_engine) + set(INF_ENGINE_TARGET ${InferenceEngine_LIBRARIES}) set(INF_ENGINE_VERSION "${InferenceEngine_VERSION}" CACHE STRING "") message(STATUS "Detected InferenceEngine: cmake package") endif() From 96d5cbd0363ed216f97a6cea0700dc9f9839fbc1 Mon Sep 17 00:00:00 2001 From: Giles Payne Date: Sat, 24 Aug 2019 00:22:29 +0900 Subject: [PATCH 18/18] Merge pull request #15350 from komakai:apple-debug-build * Add debug build option to MacOs and iOS build scripts * osx: allow selection of MACOSX_DEPLOYMENT_TARGET * Add --debug_info flag to iOS and macOS builds for building with debug info --- platforms/ios/build_framework.py | 25 +++++++++++++++++-------- platforms/osx/build_framework.py | 15 ++++++++++++--- 2 files changed, 29 insertions(+), 11 deletions(-) mode change 100644 => 100755 platforms/osx/build_framework.py diff --git a/platforms/ios/build_framework.py b/platforms/ios/build_framework.py index 37c8fc046c..a863f41e34 100755 --- a/platforms/ios/build_framework.py +++ b/platforms/ios/build_framework.py @@ -49,7 +49,7 @@ def getXCodeMajor(): raise Exception("Failed to parse Xcode version") class Builder: - def __init__(self, opencv, contrib, dynamic, bitcodedisabled, exclude, enablenonfree, targets): + def __init__(self, opencv, contrib, dynamic, bitcodedisabled, exclude, enablenonfree, targets, debug, debug_info): self.opencv = os.path.abspath(opencv) self.contrib = None if contrib: @@ -63,6 +63,8 @@ class Builder: self.exclude = exclude self.enablenonfree = enablenonfree self.targets = targets + self.debug = debug + self.debug_info = debug_info def getBD(self, parent, t): @@ -125,6 +127,9 @@ class Builder: def getToolchain(self, arch, target): return None + def getConfiguration(self): + return "Debug" if self.debug else "Release" + def getCMakeArgs(self, arch, target): args = [ @@ -132,14 +137,16 @@ class Builder: "-GXcode", "-DAPPLE_FRAMEWORK=ON", "-DCMAKE_INSTALL_PREFIX=install", - "-DCMAKE_BUILD_TYPE=Release", + "-DCMAKE_BUILD_TYPE=%s" % self.getConfiguration(), ] + ([ "-DBUILD_SHARED_LIBS=ON", "-DCMAKE_MACOSX_BUNDLE=ON", "-DCMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED=NO", ] if self.dynamic else []) + ([ "-DOPENCV_ENABLE_NONFREE=ON" - ] if self.enablenonfree else []) + ] if self.enablenonfree else []) + ([ + "-DBUILD_WITH_DEBUG_INFO=ON" + ] if self.debug_info else []) if len(self.exclude) > 0: args += ["-DBUILD_opencv_world=OFF"] if not self.dynamic else [] @@ -174,7 +181,7 @@ class Builder: buildcmd += [ "-sdk", target.lower(), - "-configuration", "Release", + "-configuration", self.getConfiguration(), "-parallelizeTargets", "-jobs", str(multiprocessing.cpu_count()), ] + (["-target","ALL_BUILD"] if self.dynamic else []) @@ -201,10 +208,10 @@ class Builder: shutil.rmtree(clean_dir) buildcmd = self.getBuildCommand(arch, target) execute(buildcmd + ["-target", "ALL_BUILD", "build"], cwd = builddir) - execute(["cmake", "-P", "cmake_install.cmake"], cwd = builddir) + execute(["cmake", "-DBUILD_TYPE=%s" % self.getConfiguration(), "-P", "cmake_install.cmake"], cwd = builddir) def mergeLibs(self, builddir): - res = os.path.join(builddir, "lib", "Release", "libopencv_merged.a") + res = os.path.join(builddir, "lib", self.getConfiguration(), "libopencv_merged.a") libs = glob.glob(os.path.join(builddir, "install", "lib", "*.a")) libs3 = glob.glob(os.path.join(builddir, "install", "share", "OpenCV", "3rdparty", "lib", "*.a")) print("Merging libraries:\n\t%s" % "\n\t".join(libs + libs3), file=sys.stderr) @@ -230,7 +237,7 @@ class Builder: shutil.copytree(os.path.join(builddirs[0], "install", "include", "opencv2"), os.path.join(dstdir, "Headers")) # make universal static lib - libs = [os.path.join(d, "lib", "Release", libname) for d in builddirs] + libs = [os.path.join(d, "lib", self.getConfiguration(), libname) for d in builddirs] lipocmd = ["lipo", "-create"] lipocmd.extend(libs) lipocmd.extend(["-o", os.path.join(dstdir, name)]) @@ -288,6 +295,8 @@ if __name__ == "__main__": parser.add_argument('--iphoneos_archs', default='armv7,armv7s,arm64', help='select iPhoneOS target ARCHS') parser.add_argument('--iphonesimulator_archs', default='i386,x86_64', help='select iPhoneSimulator target ARCHS') parser.add_argument('--enable_nonfree', default=False, dest='enablenonfree', action='store_true', help='enable non-free modules (disabled by default)') + parser.add_argument('--debug', default=False, dest='debug', action='store_true', help='Build "Debug" binaries (disabled by default)') + parser.add_argument('--debug_info', default=False, dest='debug_info', action='store_true', help='Build with debug information (useful for Release mode: BUILD_WITH_DEBUG_INFO=ON)') args = parser.parse_args() os.environ['IPHONEOS_DEPLOYMENT_TARGET'] = args.iphoneos_deployment_target @@ -304,5 +313,5 @@ if __name__ == "__main__": [ (iphoneos_archs, "iPhoneOS"), (iphonesimulator_archs, "iPhoneSimulator"), - ]) + ], args.debug, args.debug_info) b.build(args.out) diff --git a/platforms/osx/build_framework.py b/platforms/osx/build_framework.py old mode 100644 new mode 100755 index 2425fa158a..5897192108 --- a/platforms/osx/build_framework.py +++ b/platforms/osx/build_framework.py @@ -10,6 +10,8 @@ import os, os.path, sys, argparse, traceback, multiprocessing sys.path.insert(0, os.path.abspath(os.path.abspath(os.path.dirname(__file__))+'/../ios')) from build_framework import Builder +MACOSX_DEPLOYMENT_TARGET='10.12' # default, can be changed via command line options or environment variable + class OSXBuilder(Builder): def getToolchain(self, arch, target): @@ -18,10 +20,10 @@ class OSXBuilder(Builder): def getBuildCommand(self, archs, target): buildcmd = [ "xcodebuild", - "MACOSX_DEPLOYMENT_TARGET=10.9", + "MACOSX_DEPLOYMENT_TARGET=" + os.environ['MACOSX_DEPLOYMENT_TARGET'], "ARCHS=%s" % archs[0], "-sdk", target.lower(), - "-configuration", "Release", + "-configuration", "Debug" if self.debug else "Release", "-parallelizeTargets", "-jobs", str(multiprocessing.cpu_count()) ] @@ -39,10 +41,17 @@ if __name__ == "__main__": parser.add_argument('--contrib', metavar='DIR', default=None, help='folder with opencv_contrib repository (default is "None" - build only main framework)') parser.add_argument('--without', metavar='MODULE', default=[], action='append', help='OpenCV modules to exclude from the framework') parser.add_argument('--enable_nonfree', default=False, dest='enablenonfree', action='store_true', help='enable non-free modules (disabled by default)') + parser.add_argument('--macosx_deployment_target', default=os.environ.get('MACOSX_DEPLOYMENT_TARGET', MACOSX_DEPLOYMENT_TARGET), help='specify MACOSX_DEPLOYMENT_TARGET') + parser.add_argument('--debug', action='store_true', help='Build "Debug" binaries (CMAKE_BUILD_TYPE=Debug)') + parser.add_argument('--debug_info', action='store_true', help='Build with debug information (useful for Release mode: BUILD_WITH_DEBUG_INFO=ON)') + args = parser.parse_args() + os.environ['MACOSX_DEPLOYMENT_TARGET'] = args.macosx_deployment_target + print('Using MACOSX_DEPLOYMENT_TARGET=' + os.environ['MACOSX_DEPLOYMENT_TARGET']) + b = OSXBuilder(args.opencv, args.contrib, False, False, args.without, args.enablenonfree, [ (["x86_64"], "MacOSX") - ]) + ], args.debug, args.debug_info) b.build(args.out)