From fab0eb0d755ac9a972d53b81a53b7bc3870b55d2 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Wed, 28 Nov 2018 14:02:30 +0300 Subject: [PATCH 1/7] cmake: fix compiler flags (CPU_BASELINE_REQUIRED=xxx + CPU_BASELINE=DETECT) --- cmake/OpenCVCompilerOptimizations.cmake | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cmake/OpenCVCompilerOptimizations.cmake b/cmake/OpenCVCompilerOptimizations.cmake index 4c115f0e53..f82159ea3a 100644 --- a/cmake/OpenCVCompilerOptimizations.cmake +++ b/cmake/OpenCVCompilerOptimizations.cmake @@ -30,6 +30,8 @@ # CPU_DISPATCH_FINAL= - final list of dispatched optimizations # # CPU_DISPATCH_FLAGS_${opt} - flags for source files compiled separately (.avx2.cpp) +# +# CPU_{opt}_ENABLED_DEFAULT=ON/OFF - has compiler support without additional flag (CPU_BASELINE_DETECT=ON only) set(CPU_ALL_OPTIMIZATIONS "SSE;SSE2;SSE3;SSSE3;SSE4_1;SSE4_2;POPCNT;AVX;FP16;AVX2;FMA3;AVX_512F;AVX512_SKX") list(APPEND CPU_ALL_OPTIMIZATIONS NEON VFPV3 FP16) @@ -345,6 +347,7 @@ macro(ocv_check_compiler_optimization OPT) ocv_check_compiler_flag(CXX "${CPU_BASELINE_FLAGS}" "${_varname}" "${CPU_${OPT}_TEST_FILE}") if(${_varname}) list(APPEND CPU_BASELINE_FINAL ${OPT}) + set(CPU_${OPT}_ENABLED_DEFAULT ON) set(__available 1) endif() endif() @@ -462,7 +465,7 @@ foreach(OPT ${CPU_KNOWN_OPTIMIZATIONS}) if(NOT ";${CPU_BASELINE_FINAL};" MATCHES ";${OPT};") list(APPEND CPU_BASELINE_FINAL ${OPT}) endif() - if(NOT CPU_BASELINE_DETECT) # Don't change compiler flags in 'detection' mode + if(NOT CPU_${OPT}_ENABLED_DEFAULT) # Don't change compiler flags in 'detection' mode ocv_append_optimization_flag(CPU_BASELINE_FLAGS ${OPT}) endif() endif() From 3868cb44f188657368ab5674aa12f3dca9594841 Mon Sep 17 00:00:00 2001 From: Dmitry Kurtaev Date: Thu, 6 Dec 2018 09:08:50 +0300 Subject: [PATCH 2/7] Exclude Input layer from list of outputs for IE networks --- modules/dnn/src/op_inf_engine.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/dnn/src/op_inf_engine.cpp b/modules/dnn/src/op_inf_engine.cpp index 144369063e..de8447d2be 100644 --- a/modules/dnn/src/op_inf_engine.cpp +++ b/modules/dnn/src/op_inf_engine.cpp @@ -418,6 +418,8 @@ void InfEngineBackendNet::init(int targetId) InferenceEngine::OutputsDataMap unconnectedOuts; for (const auto& l : layers) { + if (l->type == "Input") + continue; // Add all outputs. for (const InferenceEngine::DataPtr& out : l->outData) { From d77612fe70ce69013d9bd9350881dc02319896c8 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Fri, 7 Dec 2018 05:14:08 +0000 Subject: [PATCH 3/7] cmake: hide 'junk' dir from the root of build directory moved to CMakeFiles (no conflicts are expected) --- cmake/OpenCVVersion.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/OpenCVVersion.cmake b/cmake/OpenCVVersion.cmake index 226db7a45f..a2b4926cf0 100644 --- a/cmake/OpenCVVersion.cmake +++ b/cmake/OpenCVVersion.cmake @@ -15,7 +15,7 @@ set(OPENCV_LIBVERSION "${OPENCV_VERSION_MAJOR}.${OPENCV_VERSION_MINOR}.${OPENCV_ # create a dependency on the version file # we never use the output of the following command but cmake will rerun automatically if the version file changes -configure_file("${OPENCV_VERSION_FILE}" "${CMAKE_BINARY_DIR}/junk/version.junk" COPYONLY) +configure_file("${OPENCV_VERSION_FILE}" "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/opencv_junk/version.junk" COPYONLY) ocv_update(OPENCV_VS_VER_FILEVERSION_QUAD "${OPENCV_VERSION_MAJOR},${OPENCV_VERSION_MINOR},${OPENCV_VERSION_PATCH},0") ocv_update(OPENCV_VS_VER_PRODUCTVERSION_QUAD "${OPENCV_VERSION_MAJOR},${OPENCV_VERSION_MINOR},${OPENCV_VERSION_PATCH},0") From 606622ab364b566b02914c548244431b9a759831 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Fri, 7 Dec 2018 13:22:39 +0300 Subject: [PATCH 4/7] stitching(perf): increase threshold of transform vector --- modules/stitching/perf/perf_matchers.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/stitching/perf/perf_matchers.cpp b/modules/stitching/perf/perf_matchers.cpp index 378d92a8dc..0ab4340673 100644 --- a/modules/stitching/perf/perf_matchers.cpp +++ b/modules/stitching/perf/perf_matchers.cpp @@ -102,7 +102,7 @@ PERF_TEST_P( match, bestOf2Nearest, TEST_DETECTORS) Mat dist (pairwise_matches.H, Range::all(), Range(2, 3)); Mat R (pairwise_matches.H, Range::all(), Range(0, 2)); // separate transform matrix, use lower error on rotations - SANITY_CHECK(dist, 1., ERROR_ABSOLUTE); + SANITY_CHECK(dist, 3., ERROR_ABSOLUTE); SANITY_CHECK(R, .06, ERROR_ABSOLUTE); } From 8422dda2c7f5848e6355a5497fdbd9524292c18c Mon Sep 17 00:00:00 2001 From: Dmitry Kurtaev Date: Fri, 7 Dec 2018 13:38:05 +0300 Subject: [PATCH 5/7] Element-wise subtraction from TensorFlow --- modules/dnn/src/layers/eltwise_layer.cpp | 4 ++- modules/dnn/src/tensorflow/tf_importer.cpp | 40 +++++----------------- modules/dnn/test/test_tf_importer.cpp | 3 +- 3 files changed, 14 insertions(+), 33 deletions(-) diff --git a/modules/dnn/src/layers/eltwise_layer.cpp b/modules/dnn/src/layers/eltwise_layer.cpp index 03aaf8b3ec..c038eb19e0 100644 --- a/modules/dnn/src/layers/eltwise_layer.cpp +++ b/modules/dnn/src/layers/eltwise_layer.cpp @@ -98,7 +98,8 @@ public: { return backendId == DNN_BACKEND_OPENCV || backendId == DNN_BACKEND_HALIDE || - (backendId == DNN_BACKEND_INFERENCE_ENGINE && (op != SUM || coeffs.empty())); + (backendId == DNN_BACKEND_INFERENCE_ENGINE && + (preferableTarget != DNN_TARGET_MYRIAD || coeffs.empty())); } bool getMemoryShapes(const std::vector &inputs, @@ -427,6 +428,7 @@ public: lp.type = "Eltwise"; lp.precision = InferenceEngine::Precision::FP32; std::shared_ptr ieLayer(new InferenceEngine::EltwiseLayer(lp)); + ieLayer->coeff = coeffs; if (op == SUM) ieLayer->_operation = InferenceEngine::EltwiseLayer::Sum; else if (op == PROD) diff --git a/modules/dnn/src/tensorflow/tf_importer.cpp b/modules/dnn/src/tensorflow/tf_importer.cpp index a465b7d363..6ce99d6610 100644 --- a/modules/dnn/src/tensorflow/tf_importer.cpp +++ b/modules/dnn/src/tensorflow/tf_importer.cpp @@ -939,7 +939,7 @@ void TFImporter::populateNet(Net dstNet) if (getDataLayout(name, data_layouts) == DATA_LAYOUT_UNKNOWN) data_layouts[name] = DATA_LAYOUT_NHWC; } - else if (type == "BiasAdd" || type == "Add") + else if (type == "BiasAdd" || type == "Add" || type == "Sub") { bool haveConst = false; for(int ii = 0; !haveConst && ii < layer.input_size(); ++ii) @@ -953,6 +953,8 @@ void TFImporter::populateNet(Net dstNet) { Mat values = getTensorContent(getConstBlob(layer, value_id)); CV_Assert(values.type() == CV_32FC1); + if (type == "Sub") + values *= -1.0f; int id; if (values.total() == 1) // is a scalar. @@ -973,6 +975,12 @@ void TFImporter::populateNet(Net dstNet) else { layerParams.set("operation", "sum"); + if (type == "Sub") + { + static float subCoeffs[] = {1.f, -1.f}; + layerParams.set("coeff", DictValue::arrayReal(subCoeffs, 2)); + } + int id = dstNet.addLayer(name, "Eltwise", layerParams); layer_id[name] = id; @@ -985,36 +993,6 @@ void TFImporter::populateNet(Net dstNet) } } } - else if (type == "Sub") - { - bool haveConst = false; - for(int ii = 0; !haveConst && ii < layer.input_size(); ++ii) - { - Pin input = parsePin(layer.input(ii)); - haveConst = value_id.find(input.name) != value_id.end(); - } - CV_Assert(haveConst); - - Mat values = getTensorContent(getConstBlob(layer, value_id)); - CV_Assert(values.type() == CV_32FC1); - values *= -1.0f; - - int id; - if (values.total() == 1) // is a scalar. - { - layerParams.set("shift", values.at(0)); - id = dstNet.addLayer(name, "Power", layerParams); - } - else // is a vector - { - layerParams.blobs.resize(1, values); - id = dstNet.addLayer(name, "Shift", layerParams); - } - layer_id[name] = id; - - // one input only - connect(layer_id, dstNet, parsePin(layer.input(0)), id, 0); - } else if (type == "MatMul") { CV_Assert(layer.input_size() == 2); diff --git a/modules/dnn/test/test_tf_importer.cpp b/modules/dnn/test/test_tf_importer.cpp index 5f944776dc..7c53f8a93f 100644 --- a/modules/dnn/test/test_tf_importer.cpp +++ b/modules/dnn/test/test_tf_importer.cpp @@ -139,9 +139,10 @@ TEST_P(Test_TensorFlow_layers, padding) runTensorFlowNet("keras_pad_concat"); } -TEST_P(Test_TensorFlow_layers, eltwise_add_mul) +TEST_P(Test_TensorFlow_layers, eltwise) { runTensorFlowNet("eltwise_add_mul"); + runTensorFlowNet("eltwise_sub"); } TEST_P(Test_TensorFlow_layers, pad_and_concat) From 05131af8da563d3302a1d8112df94d16a7f0794a Mon Sep 17 00:00:00 2001 From: Maksim Shabunin Date: Fri, 7 Dec 2018 15:57:25 +0300 Subject: [PATCH 6/7] Merge pull request #13367 from mshabunin:cmake-verify * Added dependency verification mechanism for cmake --- CMakeLists.txt | 276 ++++++++++++++++++++++++++++++---------- cmake/OpenCVUtils.cmake | 47 ++++++- 2 files changed, 253 insertions(+), 70 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6298f4438c..3206edb179 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -220,74 +220,209 @@ OCV_OPTION(BUILD_ITT "Build Intel ITT from source" (NOT MI # Optional 3rd party components # =================================================== -OCV_OPTION(WITH_1394 "Include IEEE1394 support" ON IF (NOT ANDROID AND NOT IOS AND NOT WINRT) ) -OCV_OPTION(WITH_AVFOUNDATION "Use AVFoundation for Video I/O (iOS/Mac)" ON IF APPLE) -OCV_OPTION(WITH_CARBON "Use Carbon for UI instead of Cocoa (OBSOLETE)" OFF IF APPLE ) -OCV_OPTION(WITH_CAROTENE "Use NVidia carotene acceleration library for ARM platform" ON IF (ARM OR AARCH64) AND NOT IOS AND NOT (CMAKE_VERSION VERSION_LESS "2.8.11")) -OCV_OPTION(WITH_CPUFEATURES "Use cpufeatures Android library" ON IF ANDROID) -OCV_OPTION(WITH_VTK "Include VTK library support (and build opencv_viz module eiher)" ON IF (NOT ANDROID AND NOT IOS AND NOT WINRT AND NOT CMAKE_CROSSCOMPILING) ) -OCV_OPTION(WITH_CUDA "Include NVidia Cuda Runtime support" OFF IF (NOT IOS AND NOT WINRT) ) -OCV_OPTION(WITH_CUFFT "Include NVidia Cuda Fast Fourier Transform (FFT) library support" ON IF (NOT IOS AND NOT WINRT) ) -OCV_OPTION(WITH_CUBLAS "Include NVidia Cuda Basic Linear Algebra Subprograms (BLAS) library support" ON IF (NOT IOS AND NOT WINRT) ) -OCV_OPTION(WITH_NVCUVID "Include NVidia Video Decoding library support" ON IF (NOT IOS AND NOT APPLE) ) -OCV_OPTION(WITH_EIGEN "Include Eigen2/Eigen3 support" (NOT CV_DISABLE_OPTIMIZATION) IF (NOT WINRT AND NOT CMAKE_CROSSCOMPILING) ) -OCV_OPTION(WITH_VFW "Include Video for Windows support (deprecated, consider using MSMF)" OFF IF WIN32 ) -OCV_OPTION(WITH_FFMPEG "Include FFMPEG support" ON IF (NOT ANDROID AND NOT IOS AND NOT WINRT) ) -OCV_OPTION(WITH_GSTREAMER "Include Gstreamer support" ON IF (NOT ANDROID AND NOT IOS AND NOT WINRT) ) -OCV_OPTION(WITH_GSTREAMER_0_10 "Enable Gstreamer 0.10 support (instead of 1.x)" OFF ) -OCV_OPTION(WITH_GTK "Include GTK support" ON IF (UNIX AND NOT APPLE AND NOT ANDROID) ) -OCV_OPTION(WITH_GTK_2_X "Use GTK version 2" OFF IF (UNIX AND NOT APPLE AND NOT ANDROID) ) -OCV_OPTION(WITH_IPP "Include Intel IPP support" (NOT MINGW AND NOT CV_DISABLE_OPTIMIZATION) IF (X86_64 OR X86) AND NOT WINRT AND NOT IOS ) -OCV_OPTION(WITH_HALIDE "Include Halide support" OFF) -OCV_OPTION(WITH_INF_ENGINE "Include Intel Inference Engine support" OFF) -OCV_OPTION(WITH_JASPER "Include JPEG2K support" ON IF (NOT IOS) ) -OCV_OPTION(WITH_JPEG "Include JPEG support" ON) -OCV_OPTION(WITH_WEBP "Include WebP support" ON IF (NOT WINRT) ) -OCV_OPTION(WITH_OPENEXR "Include ILM support via OpenEXR" ON IF (NOT IOS AND NOT WINRT) ) -OCV_OPTION(WITH_OPENGL "Include OpenGL support" OFF IF (NOT ANDROID AND NOT WINRT) ) -OCV_OPTION(WITH_OPENVX "Include OpenVX support" OFF) -OCV_OPTION(WITH_OPENNI "Include OpenNI support" OFF IF (NOT ANDROID AND NOT IOS AND NOT WINRT) ) -OCV_OPTION(WITH_OPENNI2 "Include OpenNI2 support" OFF IF (NOT ANDROID AND NOT IOS AND NOT WINRT) ) -OCV_OPTION(WITH_PNG "Include PNG support" ON) -OCV_OPTION(WITH_GDCM "Include DICOM support" OFF) -OCV_OPTION(WITH_PVAPI "Include Prosilica GigE support" OFF IF (NOT ANDROID AND NOT IOS AND NOT WINRT) ) -OCV_OPTION(WITH_GIGEAPI "Include Smartek GigE support" OFF IF (NOT ANDROID AND NOT IOS AND NOT WINRT) ) -OCV_OPTION(WITH_ARAVIS "Include Aravis GigE support" OFF IF (NOT ANDROID AND NOT IOS AND NOT WINRT AND NOT WIN32) ) -OCV_OPTION(WITH_QT "Build with Qt Backend support" OFF IF (NOT ANDROID AND NOT IOS AND NOT WINRT) ) -OCV_OPTION(WITH_WIN32UI "Build with Win32 UI Backend support" ON IF WIN32 AND NOT WINRT) -OCV_OPTION(WITH_QUICKTIME "Use QuickTime for Video I/O (OBSOLETE)" OFF IF APPLE ) -OCV_OPTION(WITH_QTKIT "Use QTKit Video I/O backend" OFF IF APPLE ) -OCV_OPTION(WITH_TBB "Include Intel TBB support" OFF IF (NOT IOS AND NOT WINRT) ) -OCV_OPTION(WITH_OPENMP "Include OpenMP support" OFF) -OCV_OPTION(WITH_CSTRIPES "Include C= support" OFF IF (WIN32 AND NOT WINRT) ) -OCV_OPTION(WITH_PTHREADS_PF "Use pthreads-based parallel_for" ON IF (NOT WIN32 OR MINGW) ) -OCV_OPTION(WITH_TIFF "Include TIFF support" ON IF (NOT IOS) ) -OCV_OPTION(WITH_UNICAP "Include Unicap support (GPL)" OFF IF (UNIX AND NOT APPLE AND NOT ANDROID) ) -OCV_OPTION(WITH_V4L "Include Video 4 Linux support" ON IF (UNIX AND NOT ANDROID AND NOT APPLE) ) -OCV_OPTION(WITH_LIBV4L "Use libv4l for Video 4 Linux support" OFF IF (UNIX AND NOT ANDROID AND NOT APPLE) ) -OCV_OPTION(WITH_DSHOW "Build VideoIO with DirectShow support" ON IF (WIN32 AND NOT ARM AND NOT WINRT) ) -OCV_OPTION(WITH_MSMF "Build VideoIO with Media Foundation support" ON IF WIN32 ) -OCV_OPTION(WITH_XIMEA "Include XIMEA cameras support" OFF IF (NOT ANDROID AND NOT WINRT) ) -OCV_OPTION(WITH_XINE "Include Xine support (GPL)" OFF IF (UNIX AND NOT APPLE AND NOT ANDROID) ) -OCV_OPTION(WITH_CLP "Include Clp support (EPL)" OFF) -OCV_OPTION(WITH_OPENCL "Include OpenCL Runtime support" (NOT ANDROID AND NOT CV_DISABLE_OPTIMIZATION) IF (NOT IOS AND NOT WINRT) ) -OCV_OPTION(WITH_OPENCL_SVM "Include OpenCL Shared Virtual Memory support" OFF ) # experimental -OCV_OPTION(WITH_OPENCLAMDFFT "Include AMD OpenCL FFT library support" ON IF (NOT ANDROID AND NOT IOS AND NOT WINRT) ) -OCV_OPTION(WITH_OPENCLAMDBLAS "Include AMD OpenCL BLAS library support" ON IF (NOT ANDROID AND NOT IOS AND NOT WINRT) ) -OCV_OPTION(WITH_DIRECTX "Include DirectX support" ON IF (WIN32 AND NOT WINRT) ) -OCV_OPTION(WITH_INTELPERC "Include Intel Perceptual Computing support" OFF IF (WIN32 AND NOT WINRT) ) -OCV_OPTION(WITH_VA "Include VA support" OFF IF (UNIX AND NOT ANDROID) ) -OCV_OPTION(WITH_VA_INTEL "Include Intel VA-API/OpenCL support" OFF IF (UNIX AND NOT ANDROID) ) -OCV_OPTION(WITH_MFX "Include Intel Media SDK support" OFF IF ((UNIX AND NOT ANDROID) OR (WIN32 AND NOT WINRT AND NOT MINGW)) ) -OCV_OPTION(WITH_GDAL "Include GDAL Support" OFF IF (NOT ANDROID AND NOT IOS AND NOT WINRT) ) -OCV_OPTION(WITH_GPHOTO2 "Include gPhoto2 library support" OFF IF (UNIX AND NOT ANDROID AND NOT IOS) ) -OCV_OPTION(WITH_LAPACK "Include Lapack library support" (NOT CV_DISABLE_OPTIMIZATION) IF (NOT ANDROID AND NOT IOS) ) -OCV_OPTION(WITH_ITT "Include Intel ITT support" ON IF (NOT APPLE_FRAMEWORK) ) -OCV_OPTION(WITH_PROTOBUF "Enable libprotobuf" ON ) -OCV_OPTION(WITH_IMGCODEC_HDR "Include HDR support" ON) -OCV_OPTION(WITH_IMGCODEC_SUNRASTER "Include SUNRASTER support" ON) -OCV_OPTION(WITH_IMGCODEC_PXM "Include PNM (PBM,PGM,PPM) and PAM formats support" ON) -OCV_OPTION(WITH_QUIRC "Include library QR-code decoding" ON) +OCV_OPTION(WITH_1394 "Include IEEE1394 support" ON + VISIBLE_IF NOT ANDROID AND NOT IOS AND NOT WINRT + VERIFY HAVE_DC1394) +OCV_OPTION(WITH_AVFOUNDATION "Use AVFoundation for Video I/O (iOS/Mac)" ON + VISIBLE_IF APPLE + VERIFY HAVE_AVFOUNDATION) +OCV_OPTION(WITH_CARBON "Use Carbon for UI instead of Cocoa (OBSOLETE)" OFF + VISIBLE_IF APPLE + VERIFY HAVE_CARBON OR HAVE_COCOA) +OCV_OPTION(WITH_CAROTENE "Use NVidia carotene acceleration library for ARM platform" ON + VISIBLE_IF (ARM OR AARCH64) AND NOT IOS AND NOT (CMAKE_VERSION VERSION_LESS "2.8.11")) +OCV_OPTION(WITH_CPUFEATURES "Use cpufeatures Android library" ON + VISIBLE_IF ANDROID + VERIFY HAVE_CPUFEATURES) +OCV_OPTION(WITH_VTK "Include VTK library support (and build opencv_viz module eiher)" ON + VISIBLE_IF NOT ANDROID AND NOT IOS AND NOT WINRT AND NOT CMAKE_CROSSCOMPILING + VERIFY HAVE_VTK) +OCV_OPTION(WITH_CUDA "Include NVidia Cuda Runtime support" OFF + VISIBLE_IF NOT IOS AND NOT WINRT + VERIFY HAVE_CUDA) +OCV_OPTION(WITH_CUFFT "Include NVidia Cuda Fast Fourier Transform (FFT) library support" WITH_CUDA + VISIBLE_IF WITH_CUDA + VERIFY HAVE_CUFFT) +OCV_OPTION(WITH_CUBLAS "Include NVidia Cuda Basic Linear Algebra Subprograms (BLAS) library support" WITH_CUDA + VISIBLE_IF WITH_CUDA + VERIFY HAVE_CUBLAS) +OCV_OPTION(WITH_NVCUVID "Include NVidia Video Decoding library support" WITH_CUDA + VISIBLE_IF WITH_CUDA + VERIFY HAVE_NVCUVID) +OCV_OPTION(WITH_EIGEN "Include Eigen2/Eigen3 support" (NOT CV_DISABLE_OPTIMIZATION) + VISIBLE_IF NOT WINRT AND NOT CMAKE_CROSSCOMPILING + VERIFY HAVE_EIGEN) +OCV_OPTION(WITH_VFW "Include Video for Windows support (deprecated, consider using MSMF)" OFF + VISIBLE_IF WIN32 + VERIFY HAVE_VFW) +OCV_OPTION(WITH_FFMPEG "Include FFMPEG support" ON + VISIBLE_IF NOT ANDROID AND NOT IOS AND NOT WINRT + VERIFY HAVE_FFMPEG) +OCV_OPTION(WITH_GSTREAMER "Include Gstreamer support" ON + VISIBLE_IF NOT ANDROID AND NOT IOS AND NOT WINRT + VERIFY HAVE_GSTREAMER AND GSTREAMER_BASE_VERSION VERSION_GREATER "0.99") +OCV_OPTION(WITH_GSTREAMER_0_10 "Enable Gstreamer 0.10 support (instead of 1.x)" OFF + VISIBLE_IF TRUE + VERIFY HAVE_GSTREAMER AND GSTREAMER_BASE_VERSION VERSION_LESS "1.0") +OCV_OPTION(WITH_GTK "Include GTK support" ON + VISIBLE_IF UNIX AND NOT APPLE AND NOT ANDROID + VERIFY HAVE_GTK) +OCV_OPTION(WITH_GTK_2_X "Use GTK version 2" OFF + VISIBLE_IF UNIX AND NOT APPLE AND NOT ANDROID + VERIFY HAVE_GTK AND NOT HAVE_GTK3) +OCV_OPTION(WITH_IPP "Include Intel IPP support" (NOT MINGW AND NOT CV_DISABLE_OPTIMIZATION) + VISIBLE_IF (X86_64 OR X86) AND NOT WINRT AND NOT IOS + VERIFY HAVE_IPP) +OCV_OPTION(WITH_HALIDE "Include Halide support" OFF + VISIBLE_IF TRUE + VERIFY HAVE_HALIDE) +OCV_OPTION(WITH_INF_ENGINE "Include Intel Inference Engine support" OFF + VISIBLE_IF TRUE + VERIFY INF_ENGINE_TARGET) +OCV_OPTION(WITH_JASPER "Include JPEG2K support" ON + VISIBLE_IF NOT IOS + VERIFY HAVE_JASPER) +OCV_OPTION(WITH_JPEG "Include JPEG support" ON + VISIBLE_IF TRUE + VERIFY HAVE_JPEG) +OCV_OPTION(WITH_WEBP "Include WebP support" ON + VISIBLE_IF NOT WINRT + VERIFY HAVE_WEBP) +OCV_OPTION(WITH_OPENEXR "Include ILM support via OpenEXR" ON + VISIBLE_IF NOT IOS AND NOT WINRT + VERIFY HAVE_OPENEXR) +OCV_OPTION(WITH_OPENGL "Include OpenGL support" OFF + VISIBLE_IF NOT ANDROID AND NOT WINRT + VERIFY HAVE_OPENGL) +OCV_OPTION(WITH_OPENVX "Include OpenVX support" OFF + VISIBLE_IF TRUE + VERIFY HAVE_OPENVX) +OCV_OPTION(WITH_OPENNI "Include OpenNI support" OFF + VISIBLE_IF NOT ANDROID AND NOT IOS AND NOT WINRT + VERIFY HAVE_OPENNI) +OCV_OPTION(WITH_OPENNI2 "Include OpenNI2 support" OFF + VISIBLE_IF NOT ANDROID AND NOT IOS AND NOT WINRT + VERIFY HAVE_OPENNI2) +OCV_OPTION(WITH_PNG "Include PNG support" ON + VISIBLE_IF TRUE + VERIFY HAVE_PNG) +OCV_OPTION(WITH_GDCM "Include DICOM support" OFF + VISIBLE_IF TRUE + VERIFY HAVE_GDCM) +OCV_OPTION(WITH_PVAPI "Include Prosilica GigE support" OFF + VISIBLE_IF NOT ANDROID AND NOT IOS AND NOT WINRT + VERIFY HAVE_PVAPI) +OCV_OPTION(WITH_GIGEAPI "Include Smartek GigE support" OFF + VISIBLE_IF NOT ANDROID AND NOT IOS AND NOT WINRT + VERIFY HAVE_GIGE_API) +OCV_OPTION(WITH_ARAVIS "Include Aravis GigE support" OFF + VISIBLE_IF NOT ANDROID AND NOT IOS AND NOT WINRT AND NOT WIN32 + VERIFY HAVE_ARAVIS_API) +OCV_OPTION(WITH_QT "Build with Qt Backend support" OFF + VISIBLE_IF NOT ANDROID AND NOT IOS AND NOT WINRT + VERIFY HAVE_QT) +OCV_OPTION(WITH_WIN32UI "Build with Win32 UI Backend support" ON + VISIBLE_IF WIN32 AND NOT WINRT + VERIFY HAVE_WIN32UI) +OCV_OPTION(WITH_QUICKTIME "Use QuickTime for Video I/O (OBSOLETE)" OFF + VISIBLE_IF APPLE + VERIFY HAVE_QUICKTIME) +OCV_OPTION(WITH_QTKIT "Use QTKit Video I/O backend" OFF + VISIBLE_IF APPLE + VERIFY HAVE_QTKIT) +OCV_OPTION(WITH_TBB "Include Intel TBB support" OFF + VISIBLE_IF NOT IOS AND NOT WINRT + VERIFY HAVE_TBB) +OCV_OPTION(WITH_OPENMP "Include OpenMP support" OFF + VISIBLE_IF TRUE + VERIFY HAVE_OPENMP) +OCV_OPTION(WITH_CSTRIPES "Include C= support" OFF + VISIBLE_IF WIN32 AND NOT WINRT + VERIFY HAVE_CSTRIPES) +OCV_OPTION(WITH_PTHREADS_PF "Use pthreads-based parallel_for" ON + VISIBLE_IF NOT WIN32 OR MINGW + VERIFY HAVE_PTHREADS_PF) +OCV_OPTION(WITH_TIFF "Include TIFF support" ON + VISIBLE_IF NOT IOS + VERIFY HAVE_TIFF) +OCV_OPTION(WITH_UNICAP "Include Unicap support (GPL)" OFF + VISIBLE_IF UNIX AND NOT APPLE AND NOT ANDROID + VERIFY HAVE_UNICAP) +OCV_OPTION(WITH_V4L "Include Video 4 Linux support" ON + VISIBLE_IF UNIX AND NOT ANDROID AND NOT APPLE + VERIFY HAVE_CAMV4L OR HAVE_CAMV4L2 OR HAVE_VIDEOIO) +OCV_OPTION(WITH_LIBV4L "Use libv4l for Video 4 Linux support" OFF + VISIBLE_IF UNIX AND NOT ANDROID AND NOT APPLE + VERIFY HAVE_LIBV4L) +OCV_OPTION(WITH_DSHOW "Build VideoIO with DirectShow support" ON + VISIBLE_IF WIN32 AND NOT ARM AND NOT WINRT + VERIFY HAVE_DSHOW) +OCV_OPTION(WITH_MSMF "Build VideoIO with Media Foundation support" ON + VISIBLE_IF WIN32 + VERIFY HAVE_MSMF) +OCV_OPTION(WITH_XIMEA "Include XIMEA cameras support" OFF + VISIBLE_IF NOT ANDROID AND NOT WINRT + VERIFY HAVE_XIMEA) +OCV_OPTION(WITH_XINE "Include Xine support (GPL)" OFF + VISIBLE_IF UNIX AND NOT APPLE AND NOT ANDROID + VERIFY HAVE_XINE) +OCV_OPTION(WITH_CLP "Include Clp support (EPL)" OFF + VISIBLE_IF TRUE + VERIFY HAVE_CLP) +OCV_OPTION(WITH_OPENCL "Include OpenCL Runtime support" (NOT ANDROID AND NOT CV_DISABLE_OPTIMIZATION) + VISIBLE_IF NOT IOS AND NOT WINRT + VERIFY HAVE_OPENCL) +OCV_OPTION(WITH_OPENCL_SVM "Include OpenCL Shared Virtual Memory support" OFF + VISIBLE_IF TRUE + VERIFY HAVE_OPENCL_SVM) # experimental +OCV_OPTION(WITH_OPENCLAMDFFT "Include AMD OpenCL FFT library support" ON + VISIBLE_IF NOT ANDROID AND NOT IOS AND NOT WINRT + VERIFY HAVE_CLAMDFFT) +OCV_OPTION(WITH_OPENCLAMDBLAS "Include AMD OpenCL BLAS library support" ON + VISIBLE_IF NOT ANDROID AND NOT IOS AND NOT WINRT + VERIFY HAVE_CLAMDBLAS) +OCV_OPTION(WITH_DIRECTX "Include DirectX support" ON + VISIBLE_IF WIN32 AND NOT WINRT + VERIFY HAVE_DIRECTX) +OCV_OPTION(WITH_INTELPERC "Include Intel Perceptual Computing support" OFF + VISIBLE_IF WIN32 AND NOT WINRT + VERIFY HAVE_INTELPERC) +OCV_OPTION(WITH_VA "Include VA support" OFF + VISIBLE_IF UNIX AND NOT ANDROID + VERIFY HAVE_VA) +OCV_OPTION(WITH_VA_INTEL "Include Intel VA-API/OpenCL support" OFF + VISIBLE_IF UNIX AND NOT ANDROID + VERIFY HAVE_VA_INTEL) +OCV_OPTION(WITH_MFX "Include Intel Media SDK support" OFF + VISIBLE_IF (UNIX AND NOT ANDROID) OR (WIN32 AND NOT WINRT AND NOT MINGW) + VERIFY HAVE_MFX) +OCV_OPTION(WITH_GDAL "Include GDAL Support" OFF + VISIBLE_IF NOT ANDROID AND NOT IOS AND NOT WINRT + VERIFY HAVE_GDAL) +OCV_OPTION(WITH_GPHOTO2 "Include gPhoto2 library support" OFF + VISIBLE_IF UNIX AND NOT ANDROID AND NOT IOS + VERIFY HAVE_GPHOTO2) +OCV_OPTION(WITH_LAPACK "Include Lapack library support" (NOT CV_DISABLE_OPTIMIZATION) + VISIBLE_IF NOT ANDROID AND NOT IOS + VERIFY HAVE_LAPACK) +OCV_OPTION(WITH_ITT "Include Intel ITT support" ON + VISIBLE_IF NOT APPLE_FRAMEWORK + VERIFY HAVE_ITT) +OCV_OPTION(WITH_PROTOBUF "Enable libprotobuf" ON + VISIBLE_IF TRUE + VERIFY HAVE_PROTOBUF) +OCV_OPTION(WITH_IMGCODEC_HDR "Include HDR support" ON + VISIBLE_IF TRUE + VERIFY HAVE_IMGCODEC_HDR) +OCV_OPTION(WITH_IMGCODEC_SUNRASTER "Include SUNRASTER support" ON + VISIBLE_IF TRUE + VERIFY HAVE_IMGCODEC_SUNRASTER) +OCV_OPTION(WITH_IMGCODEC_PXM "Include PNM (PBM,PGM,PPM) and PAM formats support" ON + VISIBLE_IF TRUE + VERIFY HAVE_IMGCODEC_PXM) +OCV_OPTION(WITH_QUIRC "Include library QR-code decoding" ON + VISIBLE_IF TRUE + VERIFY HAVE_QUIRC) # OpenCV build components # =================================================== @@ -347,6 +482,7 @@ OCV_OPTION(CV_ENABLE_INTRINSICS "Use intrinsic-based optimized code" ON ) OCV_OPTION(CV_DISABLE_OPTIMIZATION "Disable explicit optimized code (dispatched code/intrinsics/loop unrolling/etc)" OFF ) OCV_OPTION(CV_TRACE "Enable OpenCV code trace" ON) OCV_OPTION(OPENCV_GENERATE_SETUPVARS "Generate setup_vars* scripts" ON IF (NOT ANDROID AND NOT APPLE_FRAMEWORK) ) +OCV_OPTION(ENABLE_CONFIG_VERIFICATION "Fail build if actual configuration doesn't match requested (WITH_XXX != HAVE_XXX)" OFF) OCV_OPTION(ENABLE_PYLINT "Add target with Pylint checks" (BUILD_DOCS OR BUILD_EXAMPLES) IF (NOT CMAKE_CROSSCOMPILING AND NOT APPLE_FRAMEWORK) ) OCV_OPTION(ENABLE_FLAKE8 "Add target with Python flake8 checker" (BUILD_DOCS OR BUILD_EXAMPLES) IF (NOT CMAKE_CROSSCOMPILING AND NOT APPLE_FRAMEWORK) ) @@ -1542,6 +1678,10 @@ status("") ocv_finalize_status() +if(ENABLE_CONFIG_VERIFICATION) + ocv_verify_config() +endif() + ocv_cmake_hook(POST_FINALIZE) # ---------------------------------------------------------------------------- diff --git a/cmake/OpenCVUtils.cmake b/cmake/OpenCVUtils.cmake index 6847715bc1..7596b5009a 100644 --- a/cmake/OpenCVUtils.cmake +++ b/cmake/OpenCVUtils.cmake @@ -571,14 +571,21 @@ endmacro() # Provides an option that the user can optionally select. # Can accept condition to control when option is available for user. # Usage: -# option( "help string describing the option" [IF ]) +# option( +# "help string describing the option" +# +# [VISIBLE_IF ] +# [VERIFY ]) macro(OCV_OPTION variable description value) set(__value ${value}) set(__condition "") + set(__verification) set(__varname "__value") foreach(arg ${ARGN}) - if(arg STREQUAL "IF" OR arg STREQUAL "if") + if(arg STREQUAL "IF" OR arg STREQUAL "if" OR arg STREQUAL "VISIBLE_IF") set(__varname "__condition") + elseif(arg STREQUAL "VERIFY") + set(__varname "__verification") else() list(APPEND ${__varname} ${arg}) endif() @@ -614,10 +621,46 @@ macro(OCV_OPTION variable description value) unset(${variable} CACHE) endif() endif() + if(__verification) + set(OPENCV_VERIFY_${variable} "${__verification}") # variable containing condition to verify + list(APPEND OPENCV_VERIFICATIONS "${variable}") # list of variable names (WITH_XXX;WITH_YYY;...) + endif() unset(__condition) unset(__value) endmacro() + +# Check that each variable stored in OPENCV_VERIFICATIONS list +# is consistent with actual detection result (stored as condition in OPENCV_VERIFY_...) variables +function(ocv_verify_config) + set(broken_options) + foreach(var ${OPENCV_VERIFICATIONS}) + set(evaluated FALSE) + if(${OPENCV_VERIFY_${var}}) + set(evaluated TRUE) + endif() + status("Verifying ${var}=${${var}} => '${OPENCV_VERIFY_${var}}'=${evaluated}") + if (${var} AND NOT evaluated) + list(APPEND broken_options ${var}) + message(WARNING + "Option ${var} is enabled but corresponding dependency " + "have not been found: \"${OPENCV_VERIFY_${var}}\" is FALSE") + elseif(NOT ${var} AND evaluated) + list(APPEND broken_options ${var}) + message(WARNING + "Option ${var} is disabled or unset but corresponding dependency " + "have been explicitly turned on: \"${OPENCV_VERIFY_${var}}\" is TRUE") + endif() + endforeach() + if(broken_options) + string(REPLACE ";" "\n" broken_options "${broken_options}") + message(FATAL_ERROR + "Some dependencies have not been found or have been forced, " + "unset ENABLE_CONFIG_VERIFICATION option to ignore these failures " + "or change following options:\n${broken_options}") + endif() +endfunction() + # Usage: ocv_append_build_options(HIGHGUI FFMPEG) macro(ocv_append_build_options var_prefix pkg_prefix) foreach(suffix INCLUDE_DIRS LIBRARIES LIBRARY_DIRS) From f1dc26d7ce52cee18b94855876a142e88d2b1a59 Mon Sep 17 00:00:00 2001 From: LaurentBerger Date: Sun, 9 Dec 2018 13:05:27 +0100 Subject: [PATCH 7/7] Merge pull request #13382 from LaurentBerger:imreadsize * try to solve #13381 * Add note --- .../imgcodecs/include/opencv2/imgcodecs.hpp | 2 ++ modules/imgcodecs/src/loadsave.cpp | 19 ++++++++++--------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/modules/imgcodecs/include/opencv2/imgcodecs.hpp b/modules/imgcodecs/include/opencv2/imgcodecs.hpp index a27d4be74e..4e79518ae1 100644 --- a/modules/imgcodecs/include/opencv2/imgcodecs.hpp +++ b/modules/imgcodecs/include/opencv2/imgcodecs.hpp @@ -171,6 +171,8 @@ Currently, the following file formats are supported: [Vector](http://www.gdal.org/ogr_formats.html). - If EXIF information are embedded in the image file, the EXIF orientation will be taken into account and thus the image will be rotated accordingly except if the flag @ref IMREAD_IGNORE_ORIENTATION is passed. +- By default number of pixels must be less than 2^30. Limit can be set using system + variable OPENCV_IO_MAX_IMAGE_PIXELS @param filename Name of file to be loaded. @param flags Flag that can take values of cv::ImreadModes diff --git a/modules/imgcodecs/src/loadsave.cpp b/modules/imgcodecs/src/loadsave.cpp index cb7481872e..7a610af614 100644 --- a/modules/imgcodecs/src/loadsave.cpp +++ b/modules/imgcodecs/src/loadsave.cpp @@ -51,6 +51,8 @@ #undef max #include #include +#include + /****************************************************************************************\ * Image Codecs * @@ -58,18 +60,17 @@ namespace cv { -// TODO Add runtime configuration -#define CV_IO_MAX_IMAGE_PARAMS (50) -#define CV_IO_MAX_IMAGE_WIDTH (1<<20) -#define CV_IO_MAX_IMAGE_HEIGHT (1<<20) -#define CV_IO_MAX_IMAGE_PIXELS (1<<30) // 1 Gigapixel +static const size_t CV_IO_MAX_IMAGE_PARAMS = cv::utils::getConfigurationParameterSizeT("OPENCV_IO_MAX_IMAGE_PARAMS", 50); +static const size_t CV_IO_MAX_IMAGE_WIDTH = utils::getConfigurationParameterSizeT("OPENCV_IO_MAX_IMAGE_WIDTH", 1 << 20); +static const size_t CV_IO_MAX_IMAGE_HEIGHT = utils::getConfigurationParameterSizeT("OPENCV_IO_MAX_IMAGE_HEIGHT", 1 << 20); +static const size_t CV_IO_MAX_IMAGE_PIXELS = utils::getConfigurationParameterSizeT("OPENCV_IO_MAX_IMAGE_PIXELS", 1 << 30); static Size validateInputImageSize(const Size& size) { CV_Assert(size.width > 0); - CV_Assert(size.width <= CV_IO_MAX_IMAGE_WIDTH); + CV_Assert(static_cast(size.width) <= CV_IO_MAX_IMAGE_WIDTH); CV_Assert(size.height > 0); - CV_Assert(size.height <= CV_IO_MAX_IMAGE_HEIGHT); + CV_Assert(static_cast(size.height) <= CV_IO_MAX_IMAGE_HEIGHT); uint64 pixels = (uint64)size.width * (uint64)size.height; CV_Assert(pixels <= CV_IO_MAX_IMAGE_PIXELS); return size; @@ -998,7 +999,7 @@ cvSaveImage( const char* filename, const CvArr* arr, const int* _params ) if( _params ) { for( ; _params[i] > 0; i += 2 ) - CV_Assert(i < CV_IO_MAX_IMAGE_PARAMS*2); // Limit number of params for security reasons + CV_Assert(static_cast(i) < cv::CV_IO_MAX_IMAGE_PARAMS*2); // Limit number of params for security reasons } return cv::imwrite_(filename, cv::cvarrToMat(arr), i > 0 ? std::vector(_params, _params+i) : std::vector(), @@ -1029,7 +1030,7 @@ cvEncodeImage( const char* ext, const CvArr* arr, const int* _params ) if( _params ) { for( ; _params[i] > 0; i += 2 ) - CV_Assert(i < CV_IO_MAX_IMAGE_PARAMS*2); // Limit number of params for security reasons + CV_Assert(static_cast(i) < cv::CV_IO_MAX_IMAGE_PARAMS*2); // Limit number of params for security reasons } cv::Mat img = cv::cvarrToMat(arr); if( CV_IS_IMAGE(arr) && ((const IplImage*)arr)->origin == IPL_ORIGIN_BL )