diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3a3c9e2ee4..8f324dd3d8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1301,15 +1301,15 @@ endif()
 
 if(WITH_GTK OR HAVE_GTK)
   if(HAVE_GTK3)
-    status("    GTK+:" "YES (ver ${ALIASOF_gtk+-3.0_VERSION})")
+    status("    GTK+:" "YES (ver ${GTK3_VERSION})")
   elseif(HAVE_GTK)
-    status("    GTK+:" "YES (ver ${ALIASOF_gtk+-2.0_VERSION})")
+    status("    GTK+:" "YES (ver ${GTK2_VERSION})")
   else()
     status("    GTK+:" "NO")
   endif()
   if(HAVE_GTK)
-    status(  "      GThread :" HAVE_GTHREAD THEN "YES (ver ${ALIASOF_gthread-2.0_VERSION})" ELSE NO)
-    status(  "      GtkGlExt:" HAVE_GTKGLEXT THEN "YES (ver ${ALIASOF_gtkglext-1.0_VERSION})" ELSE NO)
+    status(  "      GThread :" HAVE_GTHREAD THEN "YES (ver ${GTHREAD_VERSION})" ELSE NO)
+    status(  "      GtkGlExt:" HAVE_GTKGLEXT THEN "YES (ver ${GTKGLEXT_VERSION})" ELSE NO)
   endif()
 endif()
 
@@ -1449,7 +1449,7 @@ if(WITH_XIMEA OR HAVE_XIMEA)
 endif()
 
 if(WITH_XINE OR HAVE_XINE)
-  status("    Xine:" HAVE_XINE THEN "YES (${XINE_VERSION})" ELSE NO)
+  status("    Xine:"           HAVE_XINE           THEN "YES (ver ${XINE_VERSION})"     ELSE NO)
 endif()
 
 if(WITH_LIBREALSENSE OR HAVE_LIBREALSENSE)
diff --git a/cmake/OpenCVDetectTBB.cmake b/cmake/OpenCVDetectTBB.cmake
index a9afe76950..403b446116 100644
--- a/cmake/OpenCVDetectTBB.cmake
+++ b/cmake/OpenCVDetectTBB.cmake
@@ -29,8 +29,10 @@ function(ocv_tbb_cmake_guess _found)
       message(STATUS "Found TBB (cmake): ${_lib}")
       get_target_property(_inc TBB::tbb INTERFACE_INCLUDE_DIRECTORIES)
       ocv_tbb_read_version("${_inc}")
-      add_library(tbb INTERFACE)
-      target_link_libraries(tbb INTERFACE TBB::tbb)
+      add_library(tbb INTERFACE IMPORTED)
+      set_target_properties(tbb PROPERTIES
+        INTERFACE_LINK_LIBRARIES TBB::tbb
+      )
       set(${_found} TRUE PARENT_SCOPE)
     endif()
 endfunction()
diff --git a/cmake/OpenCVFindLibsGUI.cmake b/cmake/OpenCVFindLibsGUI.cmake
index fd4d0c0d61..b1fba7138b 100644
--- a/cmake/OpenCVFindLibsGUI.cmake
+++ b/cmake/OpenCVFindLibsGUI.cmake
@@ -42,24 +42,34 @@ endif()
 ocv_clear_vars(HAVE_GTK HAVE_GTK3 HAVE_GTHREAD HAVE_GTKGLEXT)
 if(WITH_GTK AND NOT HAVE_QT)
   if(NOT WITH_GTK_2_X)
-    CHECK_MODULE(gtk+-3.0 HAVE_GTK3 HIGHGUI)
+    ocv_check_modules(GTK3 gtk+-3.0)
     if(HAVE_GTK3)
+      ocv_append_build_options(HIGHGUI GTK3)
       set(HAVE_GTK TRUE)
     endif()
   endif()
   if(NOT HAVE_GTK)
-    CHECK_MODULE(gtk+-2.0 HAVE_GTK HIGHGUI)
-    if(HAVE_GTK AND (ALIASOF_gtk+-2.0_VERSION VERSION_LESS MIN_VER_GTK))
-      message (FATAL_ERROR "GTK support requires a minimum version of ${MIN_VER_GTK} (${ALIASOF_gtk+-2.0_VERSION} found)")
-      set(HAVE_GTK FALSE)
+    ocv_check_modules(GTK2 gtk+-2.0)
+    if(HAVE_GTK2)
+      if (GTK2_VERSION VERSION_LESS MIN_VER_GTK)
+        message (FATAL_ERROR "GTK support requires a minimum version of ${MIN_VER_GTK} (${GTK2_VERSION} found)")
+      else()
+        ocv_append_build_options(HIGHGUI GTK2)
+        set(HAVE_GTK TRUE)
+      endif()
     endif()
   endif()
-  CHECK_MODULE(gthread-2.0 HAVE_GTHREAD HIGHGUI)
+  ocv_check_modules(GTHREAD gthread-2.0)
   if(HAVE_GTK AND NOT HAVE_GTHREAD)
     message(FATAL_ERROR "gthread not found. This library is required when building with GTK support")
+  else()
+    ocv_append_build_options(HIGHGUI GTHREAD)
   endif()
   if(WITH_OPENGL AND NOT HAVE_GTK3)
-    CHECK_MODULE(gtkglext-1.0 HAVE_GTKGLEXT HIGHGUI)
+    ocv_check_modules(GTKGLEXT gtkglext-1.0)
+    if(HAVE_GTKGLEXT)
+      ocv_append_build_options(GTKGLEXT GTHREAD)
+    endif()
   endif()
 endif()
 
diff --git a/cmake/OpenCVFindLibsPerf.cmake b/cmake/OpenCVFindLibsPerf.cmake
index 8b91a2d739..67978f9210 100644
--- a/cmake/OpenCVFindLibsPerf.cmake
+++ b/cmake/OpenCVFindLibsPerf.cmake
@@ -59,14 +59,13 @@ endif(WITH_EIGEN)
 ocv_clear_vars(HAVE_CLP)
 if(WITH_CLP)
   if(UNIX)
-    PKG_CHECK_MODULES(CLP clp)
+    ocv_check_modules(CLP clp)
     if(CLP_FOUND)
       set(HAVE_CLP TRUE)
       if(NOT ${CLP_INCLUDE_DIRS} STREQUAL "")
         ocv_include_directories(${CLP_INCLUDE_DIRS})
       endif()
-      link_directories(${CLP_LIBRARY_DIRS})
-      set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} ${CLP_LIBRARIES})
+      list(APPEND OPENCV_LINKER_LIBS ${CLP_LIBRARIES})
     endif()
   endif()
 
diff --git a/cmake/OpenCVPCHSupport.cmake b/cmake/OpenCVPCHSupport.cmake
index 59bc826ed0..0590793401 100644
--- a/cmake/OpenCVPCHSupport.cmake
+++ b/cmake/OpenCVPCHSupport.cmake
@@ -43,18 +43,9 @@ MACRO(_PCH_GET_COMPILE_FLAGS _out_compile_flags)
             LIST(APPEND ${_out_compile_flags} "-fPIC")
         ENDIF()
 
-        GET_PROPERTY(_definitions DIRECTORY PROPERTY COMPILE_DEFINITIONS)
-        if(_definitions)
-          foreach(_def ${_definitions})
-            LIST(APPEND ${_out_compile_flags} "\"-D${_def}\"")
-          endforeach()
-        endif()
-        GET_TARGET_PROPERTY(_target_definitions ${_PCH_current_target} COMPILE_DEFINITIONS)
-        if(_target_definitions)
-          foreach(_def ${_target_definitions})
-            LIST(APPEND ${_out_compile_flags} "\"-D${_def}\"")
-          endforeach()
-        endif()
+        # Processed via $<TARGET_PROPERTY:target,COMPILE_DEFINITIONS>
+        #GET_PROPERTY(_definitions DIRECTORY PROPERTY COMPILE_DEFINITIONS)
+        #GET_TARGET_PROPERTY(_target_definitions ${_PCH_current_target} COMPILE_DEFINITIONS)
 
         GET_TARGET_PROPERTY(_cxx_standard ${_PCH_current_target} CXX_STANDARD)
         if (_cxx_standard)
@@ -304,12 +295,22 @@ MACRO(ADD_PRECOMPILED_HEADER _targetName _input)
     #message("_command  ${_input} ${_output}")
     _PCH_GET_COMPILE_COMMAND(_command  ${CMAKE_CURRENT_BINARY_DIR}/${_name} ${_output} )
 
+    set(_pch_generate_file_cmd "${CMAKE_CURRENT_BINARY_DIR}/${_name}.command.sh")
+    string(REPLACE " " "\\ " _command "${_command}")
+    string(REPLACE ";" " " _command "${_command}")
+    file(GENERATE OUTPUT "${_pch_generate_file_cmd}" CONTENT "#!/bin/sh
+if [ -n \"$VERBOSE\" ]; then
+  tail -n1 \$0
+fi
+${_command} -D$<JOIN:$<TARGET_PROPERTY:${_targetName},COMPILE_DEFINITIONS>, -D>
+")
     GET_FILENAME_COMPONENT(_outdir ${_output} PATH)
     ADD_CUSTOM_COMMAND(
       OUTPUT "${_output}"
       COMMAND ${CMAKE_COMMAND} -E make_directory "${_outdir}"
-      COMMAND ${_command}
-      DEPENDS "${_input}"
+      COMMAND chmod +x "${_pch_generate_file_cmd}"
+      COMMAND "${_pch_generate_file_cmd}"
+      DEPENDS "${_input}" "${_pch_generate_file_cmd}"
       DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${_name}"
       DEPENDS ${_targetName}_pch_dephelp
       )
diff --git a/cmake/OpenCVUtils.cmake b/cmake/OpenCVUtils.cmake
index 4ec4eede85..18aabd150e 100644
--- a/cmake/OpenCVUtils.cmake
+++ b/cmake/OpenCVUtils.cmake
@@ -1,3 +1,7 @@
+if(COMMAND ocv_cmake_dump_vars)  # include guard
+  return()
+endif()
+
 include(CMakeParseArguments)
 
 # Debugging function
@@ -701,7 +705,7 @@ endfunction()
 
 # Usage: ocv_append_build_options(HIGHGUI FFMPEG)
 macro(ocv_append_build_options var_prefix pkg_prefix)
-  foreach(suffix INCLUDE_DIRS LIBRARIES LIBRARY_DIRS)
+  foreach(suffix INCLUDE_DIRS LIBRARIES LIBRARY_DIRS LINK_LIBRARIES)
     if(${pkg_prefix}_${suffix})
       list(APPEND ${var_prefix}_${suffix} ${${pkg_prefix}_${suffix}})
       list(REMOVE_DUPLICATES ${var_prefix}_${suffix})
@@ -739,7 +743,9 @@ macro(ocv_check_modules define)
     endif()
     unset(${define}_${__modname}_FOUND)
   endforeach()
-  pkg_check_modules(${define} ${ARGN})
+  if(COMMAND pkg_check_modules)
+    pkg_check_modules(${define} ${ARGN})
+  endif()
   if(${define}_FOUND)
     set(HAVE_${define} 1)
   endif()
@@ -753,29 +759,47 @@ macro(ocv_check_modules define)
       set(${define}_${__modname}_FOUND 1)
     endif()
   endforeach()
-endmacro()
-
-
-# Macro that checks if module has been installed.
-# After it adds module to build and define
-# constants passed as second arg
-macro(CHECK_MODULE module_name define cv_module)
-  set(${define} 0)
-  if(PKG_CONFIG_FOUND)
-    set(ALIAS               ALIASOF_${module_name})
-    set(ALIAS_FOUND                 ${ALIAS}_FOUND)
-    set(ALIAS_INCLUDE_DIRS   ${ALIAS}_INCLUDE_DIRS)
-    set(ALIAS_LIBRARY_DIRS   ${ALIAS}_LIBRARY_DIRS)
-    set(ALIAS_LIBRARIES         ${ALIAS}_LIBRARIES)
-
-    PKG_CHECK_MODULES(${ALIAS} ${module_name})
-    if(${ALIAS_FOUND})
-      set(${define} 1)
-      ocv_append_build_options(${cv_module} ${ALIAS})
+  if(${define}_FOUND AND ${define}_LIBRARIES)
+    if(${define}_LINK_LIBRARIES_XXXXX)  # CMake 3.12+: https://gitlab.kitware.com/cmake/cmake/merge_requests/2068
+      set(${define}_LIBRARIES "${${define}_LINK_LIBRARIES}" CACHE INTERNAL "")
+    else()
+      unset(_libs)          # absolute paths
+      unset(_libs_paths)  # -L args
+      foreach(flag ${${define}_LDFLAGS})
+        if(flag MATCHES "^-L(.*)")
+          list(APPEND _libs_paths ${CMAKE_MATCH_1})
+        elseif(IS_ABSOLUTE "${flag}")
+          list(APPEND _libs "${flag}")
+        elseif(flag MATCHES "^-l(.*)")
+          set(_lib "${CMAKE_MATCH_1}")
+          if(_libs_paths)
+            find_library(pkgcfg_lib_${define}_${_lib} NAMES ${_lib}
+                         HINTS ${_libs_paths} NO_DEFAULT_PATH)
+          endif()
+          find_library(pkgcfg_lib_${define}_${_lib} NAMES ${_lib})
+          mark_as_advanced(pkgcfg_lib_${define}_${_lib})
+          if(pkgcfg_lib_${define}_${_lib})
+            list(APPEND _libs "${pkgcfg_lib_${define}_${_lib}}")
+          else()
+            message(WARNING "ocv_check_modules(${define}): can't find library '${_lib}'. Specify 'pkgcfg_lib_${define}_${_lib}' manualy")
+            list(APPEND _libs "${_lib}")
+          endif()
+        else()
+          # -pthread
+          #message(WARNING "ocv_check_modules(${define}): unknown LDFLAG '${flag}'")
+        endif()
+      endforeach()
+      set(${define}_LINK_LIBRARIES "${_libs}")
+      set(${define}_LIBRARIES "${_libs}" CACHE INTERNAL "")
+      unset(_lib)
+      unset(_libs)
+      unset(_libs_paths)
     endif()
   endif()
 endmacro()
 
+
+
 if(NOT DEFINED CMAKE_ARGC) # Guard CMake standalone invocations
 
 # Use this option carefully, CMake's install() will install symlinks instead of real files
@@ -1091,15 +1115,6 @@ function(ocv_convert_to_lib_name var)
   set(${var} ${tmp} PARENT_SCOPE)
 endfunction()
 
-if(MSVC AND BUILD_SHARED_LIBS)  # no defaults for static libs (modern CMake is required)
-  if(NOT CMAKE_VERSION VERSION_LESS 3.6.0)
-    option(INSTALL_PDB_COMPONENT_EXCLUDE_FROM_ALL "Don't install PDB files by default" ON)
-    option(INSTALL_PDB "Add install PDB rules" ON)
-  elseif(NOT CMAKE_VERSION VERSION_LESS 3.1.0)
-    option(INSTALL_PDB_COMPONENT_EXCLUDE_FROM_ALL "Don't install PDB files by default (not supported)" OFF)
-    option(INSTALL_PDB "Add install PDB rules" OFF)
-  endif()
-endif()
 
 # add install command
 function(ocv_install_target)
@@ -1132,6 +1147,18 @@ function(ocv_install_target)
 
   if(MSVC)
     set(__target "${ARGV0}")
+
+    # don't move this into global scope of this file: compiler settings (like MSVC variable) are not available during processing
+    if(BUILD_SHARED_LIBS)  # no defaults for static libs (modern CMake is required)
+      if(NOT CMAKE_VERSION VERSION_LESS 3.6.0)
+        option(INSTALL_PDB_COMPONENT_EXCLUDE_FROM_ALL "Don't install PDB files by default" ON)
+        option(INSTALL_PDB "Add install PDB rules" ON)
+      elseif(NOT CMAKE_VERSION VERSION_LESS 3.1.0)
+        option(INSTALL_PDB_COMPONENT_EXCLUDE_FROM_ALL "Don't install PDB files by default (not supported)" OFF)
+        option(INSTALL_PDB "Add install PDB rules" OFF)
+      endif()
+    endif()
+
     if(INSTALL_PDB AND NOT INSTALL_IGNORE_PDB
         AND NOT OPENCV_${__target}_PDB_SKIP
     )
@@ -1176,7 +1203,7 @@ function(ocv_install_target)
           endif()
 
 #          message(STATUS "Adding PDB file installation rule: target=${__target} dst=${__dst} component=${__pdb_install_component}")
-          if("${__target_type}" STREQUAL "SHARED_LIBRARY")
+          if("${__target_type}" STREQUAL "SHARED_LIBRARY" OR "${__target_type}" STREQUAL "MODULE_LIBRARY")
             install(FILES "$<TARGET_PDB_FILE:${__target}>" DESTINATION "${__dst}"
                 COMPONENT ${__pdb_install_component} OPTIONAL ${__pdb_exclude_from_all})
           else()
diff --git a/cmake/templates/OpenCVConfig.cmake.in b/cmake/templates/OpenCVConfig.cmake.in
index fefa359e0a..c255fc2677 100644
--- a/cmake/templates/OpenCVConfig.cmake.in
+++ b/cmake/templates/OpenCVConfig.cmake.in
@@ -76,7 +76,7 @@ endif()
 
 # Extract the directory where *this* file has been installed (determined at cmake run-time)
 # Get the absolute path with no ../.. relative marks, to eliminate implicit linker warnings
-set(OpenCV_CONFIG_PATH "${CMAKE_CURRENT_LIST_DIR}")
+get_filename_component(OpenCV_CONFIG_PATH "${CMAKE_CURRENT_LIST_DIR}" REALPATH)
 get_filename_component(OpenCV_INSTALL_PATH "${OpenCV_CONFIG_PATH}/@OpenCV_INSTALL_PATH_RELATIVE_CONFIGCMAKE@" REALPATH)
 
 # Search packages for host system instead of packages for target system.
diff --git a/modules/calib3d/CMakeLists.txt b/modules/calib3d/CMakeLists.txt
index 67ea078246..e42c3800ba 100644
--- a/modules/calib3d/CMakeLists.txt
+++ b/modules/calib3d/CMakeLists.txt
@@ -1,2 +1,6 @@
 set(the_description "Camera Calibration and 3D Reconstruction")
-ocv_define_module(calib3d opencv_imgproc opencv_features2d opencv_flann WRAP java python)
+set(debug_modules "")
+if(DEBUG_opencv_calib3d)
+  list(APPEND debug_modules opencv_highgui)
+endif()
+ocv_define_module(calib3d opencv_imgproc opencv_features2d opencv_flann ${debug_modules} WRAP java python)
diff --git a/modules/calib3d/src/calibinit.cpp b/modules/calib3d/src/calibinit.cpp
index 34f564df0b..3ba631e97c 100644
--- a/modules/calib3d/src/calibinit.cpp
+++ b/modules/calib3d/src/calibinit.cpp
@@ -76,6 +76,7 @@
 
 //#define ENABLE_TRIM_COL_ROW
 
+// Requires CMake flag: DEBUG_opencv_calib3d=ON
 //#define DEBUG_CHESSBOARD
 #define DEBUG_CHESSBOARD_TIMEOUT 0  // 0 - wait for 'q'
 
diff --git a/modules/calib3d/src/circlesgrid.cpp b/modules/calib3d/src/circlesgrid.cpp
index 481fafd452..42e0e65c8c 100644
--- a/modules/calib3d/src/circlesgrid.cpp
+++ b/modules/calib3d/src/circlesgrid.cpp
@@ -43,6 +43,8 @@
 #include "precomp.hpp"
 #include "circlesgrid.hpp"
 #include <limits>
+
+ // Requires CMake flag: DEBUG_opencv_calib3d=ON
 //#define DEBUG_CIRCLES
 
 #ifdef DEBUG_CIRCLES
diff --git a/modules/dnn/include/opencv2/dnn/version.hpp b/modules/dnn/include/opencv2/dnn/version.hpp
index eb3a4f843d..8cd5d71de1 100644
--- a/modules/dnn/include/opencv2/dnn/version.hpp
+++ b/modules/dnn/include/opencv2/dnn/version.hpp
@@ -8,7 +8,7 @@
 /// Use with major OpenCV version only.
 #define OPENCV_DNN_API_VERSION 20190412
 
-#if !defined CV_DOXYGEN && !defined CV_DNN_DONT_ADD_INLINE_NS
+#if !defined CV_DOXYGEN && !defined CV_STATIC_ANALYSIS && !defined CV_DNN_DONT_ADD_INLINE_NS
 #define CV__DNN_INLINE_NS __CV_CAT(dnn4_v, OPENCV_DNN_API_VERSION)
 #define CV__DNN_INLINE_NS_BEGIN namespace CV__DNN_INLINE_NS {
 #define CV__DNN_INLINE_NS_END }
diff --git a/modules/dnn/src/layers/flatten_layer.cpp b/modules/dnn/src/layers/flatten_layer.cpp
index aa264a749b..72f67529fa 100644
--- a/modules/dnn/src/layers/flatten_layer.cpp
+++ b/modules/dnn/src/layers/flatten_layer.cpp
@@ -105,6 +105,16 @@ public:
         return true;
     }
 
+    void finalize(InputArrayOfArrays inputs_arr, OutputArrayOfArrays) CV_OVERRIDE
+    {
+        std::vector<Mat> inputs;
+        inputs_arr.getMatVector(inputs);
+
+        int numAxes = inputs[0].dims;
+        _startAxis = clamp(_startAxis, numAxes);
+        _endAxis = clamp(_endAxis, numAxes);
+    }
+
 #ifdef HAVE_OPENCL
     bool forward_ocl(InputArrayOfArrays inputs_arr, OutputArrayOfArrays outputs_arr, OutputArrayOfArrays internals_arr)
     {
diff --git a/modules/dnn/src/layers/normalize_bbox_layer.cpp b/modules/dnn/src/layers/normalize_bbox_layer.cpp
index 8760cad33b..65640b6905 100644
--- a/modules/dnn/src/layers/normalize_bbox_layer.cpp
+++ b/modules/dnn/src/layers/normalize_bbox_layer.cpp
@@ -275,13 +275,13 @@ public:
             InferenceEngine::Blob::Ptr weights;
             if (blobs.empty())
             {
-                auto onesBlob = InferenceEngine::make_shared_blob<float>(InferenceEngine::Precision::FP32,
-                                                                         InferenceEngine::Layout::C,
-                                                                         {(size_t)numChannels});
-                onesBlob->allocate();
-                std::vector<float> ones(numChannels, 1);
-                onesBlob->set(ones);
-                weights = onesBlob;
+                weights = InferenceEngine::make_shared_blob<float>(InferenceEngine::Precision::FP32,
+                                                                   InferenceEngine::Layout::C,
+                                                                   {(size_t)numChannels});
+                weights->allocate();
+
+                Mat weightsMat = infEngineBlobToMat(weights).reshape(1, numChannels);
+                Mat(numChannels, 1, CV_32F, Scalar(1)).copyTo(weightsMat);
                 l.getParameters()["channel_shared"] = false;
             }
             else
@@ -290,11 +290,7 @@ public:
                 weights = wrapToInfEngineBlob(blobs[0], {(size_t)numChannels}, InferenceEngine::Layout::C);
                 l.getParameters()["channel_shared"] = blobs[0].total() == 1;
             }
-#if INF_ENGINE_VER_MAJOR_GE(INF_ENGINE_RELEASE_2019R1)
-            l.getParameters()["weights"] = weights;
-#else
-            l.addConstantData("weights", weights);
-#endif
+            addConstantData("weights", weights, l);
             l.getParameters()["across_spatial"] = acrossSpatial;
             return Ptr<BackendNode>(new InfEngineBackendNode(l));
         }
diff --git a/modules/dnn/src/op_inf_engine.cpp b/modules/dnn/src/op_inf_engine.cpp
index e1d6cb4833..b9cebe3b0c 100644
--- a/modules/dnn/src/op_inf_engine.cpp
+++ b/modules/dnn/src/op_inf_engine.cpp
@@ -12,9 +12,6 @@
 #ifdef HAVE_INF_ENGINE
 #include <ie_extension.h>
 #include <ie_plugin_dispatcher.hpp>
-#if INF_ENGINE_VER_MAJOR_GE(INF_ENGINE_RELEASE_2018R5)
-#include <vpu/vpu_plugin_config.hpp>
-#endif
 #endif  // HAVE_INF_ENGINE
 
 #include <opencv2/core/utils/configuration.private.hpp>
@@ -737,8 +734,7 @@ static bool detectMyriadX_()
     auto plugin = InferenceEngine::InferencePlugin(enginePtr);
     try
     {
-        auto netExec = plugin.LoadNetwork(cnn, {{InferenceEngine::VPUConfigParams::KEY_VPU_PLATFORM,
-                                                 InferenceEngine::VPUConfigParams::VPU_2480}});
+        auto netExec = plugin.LoadNetwork(cnn, {{"VPU_PLATFORM", "VPU_2480"}});
         auto infRequest = netExec.CreateInferRequest();
     } catch(...) {
         return false;
diff --git a/modules/dnn/src/op_inf_engine.hpp b/modules/dnn/src/op_inf_engine.hpp
index 2b0e1caf2b..8e16236469 100644
--- a/modules/dnn/src/op_inf_engine.hpp
+++ b/modules/dnn/src/op_inf_engine.hpp
@@ -15,14 +15,6 @@
 #include "opencv2/dnn/utils/inference_engine.hpp"
 
 #ifdef HAVE_INF_ENGINE
-#if defined(__GNUC__) && __GNUC__ >= 5
-//#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wsuggest-override"
-#endif
-#include <inference_engine.hpp>
-#if defined(__GNUC__) && __GNUC__ >= 5
-//#pragma GCC diagnostic pop
-#endif
 
 #define INF_ENGINE_RELEASE_2018R3 2018030000
 #define INF_ENGINE_RELEASE_2018R4 2018040000
@@ -37,12 +29,32 @@
 #define INF_ENGINE_VER_MAJOR_GT(ver) (((INF_ENGINE_RELEASE) / 10000) > ((ver) / 10000))
 #define INF_ENGINE_VER_MAJOR_GE(ver) (((INF_ENGINE_RELEASE) / 10000) >= ((ver) / 10000))
 #define INF_ENGINE_VER_MAJOR_LT(ver) (((INF_ENGINE_RELEASE) / 10000) < ((ver) / 10000))
+#define INF_ENGINE_VER_MAJOR_LE(ver) (((INF_ENGINE_RELEASE) / 10000) <= ((ver) / 10000))
 #define INF_ENGINE_VER_MAJOR_EQ(ver) (((INF_ENGINE_RELEASE) / 10000) == ((ver) / 10000))
 
+#if defined(__GNUC__) && __GNUC__ >= 5
+//#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wsuggest-override"
+#endif
+
+#if defined(__GNUC__) && INF_ENGINE_VER_MAJOR_LE(INF_ENGINE_RELEASE_2019R1)
+#pragma GCC visibility push(default)
+#endif
+
+#include <inference_engine.hpp>
+
 #if INF_ENGINE_VER_MAJOR_GE(INF_ENGINE_RELEASE_2018R5)
 #include <ie_builders.hpp>
 #endif
 
+#if defined(__GNUC__) && INF_ENGINE_VER_MAJOR_LE(INF_ENGINE_RELEASE_2019R1)
+#pragma GCC visibility pop
+#endif
+
+#if defined(__GNUC__) && __GNUC__ >= 5
+//#pragma GCC diagnostic pop
+#endif
+
 #endif  // HAVE_INF_ENGINE
 
 namespace cv { namespace dnn {
diff --git a/modules/dnn/src/tensorflow/tf_graph_simplifier.cpp b/modules/dnn/src/tensorflow/tf_graph_simplifier.cpp
index d5364f9131..f26f667c94 100644
--- a/modules/dnn/src/tensorflow/tf_graph_simplifier.cpp
+++ b/modules/dnn/src/tensorflow/tf_graph_simplifier.cpp
@@ -646,6 +646,30 @@ public:
     }
 };
 
+class SoftMaxSlimV2Subgraph : public Subgraph
+{
+public:
+    SoftMaxSlimV2Subgraph()
+    {
+        int input = addNodeToMatch("");
+        int shape = addNodeToMatch("Shape", input);
+        int shape_2 = addNodeToMatch("Shape", input);
+        int rank = addNodeToMatch("Const");
+        int y = addNodeToMatch("Const");
+        int sub = addNodeToMatch("Sub", rank, y);
+        int begin = addNodeToMatch("Pack", sub);
+        int size = addNodeToMatch("Const");
+        int slice = addNodeToMatch("Slice", shape, begin, size);
+        int values = addNodeToMatch("Const");
+        int axis = addNodeToMatch("Const");
+        int concat = addNodeToMatch("ConcatV2", values, slice, axis);
+        int reshape = addNodeToMatch("Reshape", input, concat);
+        int softmax = addNodeToMatch("Softmax", reshape);
+        addNodeToMatch("Reshape", softmax, shape_2);
+        setFusedNode("Softmax", input);
+    }
+};
+
 void simplifySubgraphs(tensorflow::GraphDef& net)
 {
     std::vector<Ptr<Subgraph> > subgraphs;
@@ -663,6 +687,7 @@ void simplifySubgraphs(tensorflow::GraphDef& net)
     subgraphs.push_back(Ptr<Subgraph>(new UpsamplingKerasSubgraph()));
     subgraphs.push_back(Ptr<Subgraph>(new ReshapeAsShapeSubgraph()));
     subgraphs.push_back(Ptr<Subgraph>(new SoftMaxSlimSubgraph()));
+    subgraphs.push_back(Ptr<Subgraph>(new SoftMaxSlimV2Subgraph()));
 
     int numNodes = net.node_size();
     std::vector<int> matchedNodesIds;
diff --git a/modules/dnn/src/tensorflow/tf_importer.cpp b/modules/dnn/src/tensorflow/tf_importer.cpp
index 470d3c2471..95c1d5fdd0 100644
--- a/modules/dnn/src/tensorflow/tf_importer.cpp
+++ b/modules/dnn/src/tensorflow/tf_importer.cpp
@@ -1125,18 +1125,25 @@ void TFImporter::populateNet(Net dstNet)
             {
                 CV_Assert(hasLayerAttr(layer, "squeeze_dims"));
                 const tensorflow::AttrValue& dims = getLayerAttr(layer, "squeeze_dims");
-                if (inpLayout == DATA_LAYOUT_NHWC)
+                std::vector<int> dimsVector(dims.list().i_size());
+                for (int i = 0; i < dimsVector.size(); ++i)
+                    dimsVector[i] = dims.list().i(i);
+
+                // Flatten layer can squeeze dimensions range into one.
+                std::sort(dimsVector.begin(), dimsVector.end());
+                for (int i = 1; i < dimsVector.size(); ++i)
                 {
-                    if (dims.list().i_size() != 2 || dims.list().i(0) != 1 || dims.list().i(1) != 2)
+                    if (dimsVector[i] != dimsVector[i - 1] + 1)
                         CV_Error(Error::StsNotImplemented, "Unsupported squeeze configuration");
                 }
-                else if (inpLayout == DATA_LAYOUT_NCHW)
+                int start = dimsVector.front() - 1, end = dimsVector.back();
+                if (start == -1 && end == 0)  // squeeze 0th dimension
                 {
-                    if (dims.list().i_size() != 2 || dims.list().i(0) != 2 || dims.list().i(1) != 3)
-                        CV_Error(Error::StsNotImplemented, "Unsupported squeeze configuration");
+                    start = 0;
+                    end = 1;
                 }
-                else
-                    CV_Error(Error::StsNotImplemented, "Unsupported squeeze configuration");
+                layerParams.set("axis", start);
+                layerParams.set("end_axis", end);
             }
             if (inpLayout == DATA_LAYOUT_NHWC)
             {
diff --git a/modules/dnn/test/test_tf_importer.cpp b/modules/dnn/test/test_tf_importer.cpp
index 8abe02064c..8b750bbb44 100644
--- a/modules/dnn/test/test_tf_importer.cpp
+++ b/modules/dnn/test/test_tf_importer.cpp
@@ -637,6 +637,17 @@ TEST_P(Test_TensorFlow_layers, softmax)
     runTensorFlowNet("slim_softmax");
 }
 
+TEST_P(Test_TensorFlow_layers, slim_softmax_v2)
+{
+#if defined(INF_ENGINE_RELEASE)
+    if (backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_MYRIAD &&
+        getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_2
+    )
+        throw SkipTestException("Test is disabled for Myriad2");
+#endif
+    runTensorFlowNet("slim_softmax_v2");
+}
+
 TEST_P(Test_TensorFlow_layers, relu6)
 {
     runTensorFlowNet("keras_relu6");
@@ -654,6 +665,44 @@ TEST_P(Test_TensorFlow_layers, resize_bilinear)
     runTensorFlowNet("resize_bilinear_factor");
 }
 
+TEST_P(Test_TensorFlow_layers, squeeze)
+{
+#if defined(INF_ENGINE_RELEASE)
+    if (backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_MYRIAD
+            && getInferenceEngineVPUType() == CV_DNN_INFERENCE_ENGINE_VPU_TYPE_MYRIAD_2
+    )
+        throw SkipTestException("Test is disabled for Myriad2");
+#endif
+    int inpShapes[][4] = {{1, 3, 4, 2}, {1, 3, 1, 2}, {1, 3, 4, 1}, {1, 3, 4, 1}};  // TensorFlow's shape (NHWC)
+    int outShapes[][3] = {{3, 4, 2}, {1, 3, 2}, {1, 3, 4}, {1, 3, 4}};
+    int squeeze_dims[] = {0, 2, 3, -1};
+    for (int i = 0; i < 4; ++i)
+    {
+        SCOPED_TRACE(format("i=%d", i));
+        std::string pbtxt =
+            "node { name: \"input\" op: \"Placeholder\""
+            "attr { key: \"data_format\" value { s: \"NHWC\" } } }"
+            "node { name: \"squeeze\" op: \"Squeeze\" input: \"input\""
+              "attr { key: \"squeeze_dims\" value { list { i:" + format("%d", squeeze_dims[i]) + "}}}}";
+        Net net = readNetFromTensorflow(0, 0, pbtxt.c_str(), pbtxt.size());
+        net.setPreferableBackend(backend);
+        net.setPreferableTarget(target);
+        Mat tfInp(4, &inpShapes[i][0], CV_32F);
+        randu(tfInp, -1, 1);
+
+        // NHWC to NCHW
+        CV_Assert(inpShapes[i][0] == 1);
+        std::swap(inpShapes[i][2], inpShapes[i][3]);
+        std::swap(inpShapes[i][1], inpShapes[i][2]);
+        Mat cvInp = tfInp.reshape(1, tfInp.total() / inpShapes[i][1]).t();
+        cvInp = cvInp.reshape(1, 4, &inpShapes[i][0]);
+
+        net.setInput(cvInp);
+        Mat out = net.forward();
+        normAssert(tfInp.reshape(1, 3, &outShapes[i][0]), out, "", default_l1, default_lInf);
+    }
+}
+
 INSTANTIATE_TEST_CASE_P(/**/, Test_TensorFlow_layers, dnnBackendsAndTargets());
 
 TEST(Test_TensorFlow, two_inputs)
diff --git a/modules/features2d/CMakeLists.txt b/modules/features2d/CMakeLists.txt
index f18f69edb3..e92309db0f 100644
--- a/modules/features2d/CMakeLists.txt
+++ b/modules/features2d/CMakeLists.txt
@@ -1,2 +1,6 @@
 set(the_description "2D Features Framework")
-ocv_define_module(features2d opencv_imgproc OPTIONAL opencv_flann opencv_highgui WRAP java python js)
+set(debug_modules "")
+if(DEBUG_opencv_features2d)
+  list(APPEND debug_modules opencv_highgui)
+endif()
+ocv_define_module(features2d opencv_imgproc ${debug_modules} OPTIONAL opencv_flann WRAP java python js)
diff --git a/modules/features2d/src/blobdetector.cpp b/modules/features2d/src/blobdetector.cpp
index f1e8b63799..403a8974cc 100644
--- a/modules/features2d/src/blobdetector.cpp
+++ b/modules/features2d/src/blobdetector.cpp
@@ -44,15 +44,11 @@
 #include <iterator>
 #include <limits>
 
+// Requires CMake flag: DEBUG_opencv_features2d=ON
 //#define DEBUG_BLOB_DETECTOR
 
 #ifdef DEBUG_BLOB_DETECTOR
-#  include "opencv2/opencv_modules.hpp"
-#  ifdef HAVE_OPENCV_HIGHGUI
-#    include "opencv2/highgui.hpp"
-#  else
-#    undef DEBUG_BLOB_DETECTOR
-#  endif
+#include "opencv2/highgui.hpp"
 #endif
 
 namespace cv
@@ -200,13 +196,13 @@ void SimpleBlobDetectorImpl::findBlobs(InputArray _image, InputArray _binaryImag
     findContours(binaryImage, contours, RETR_LIST, CHAIN_APPROX_NONE);
 
 #ifdef DEBUG_BLOB_DETECTOR
-    //  Mat keypointsImage;
-    //  cvtColor( binaryImage, keypointsImage, CV_GRAY2RGB );
-    //
-    //  Mat contoursImage;
-    //  cvtColor( binaryImage, contoursImage, CV_GRAY2RGB );
-    //  drawContours( contoursImage, contours, -1, Scalar(0,255,0) );
-    //  imshow("contours", contoursImage );
+    Mat keypointsImage;
+    cvtColor(binaryImage, keypointsImage, COLOR_GRAY2RGB);
+
+    Mat contoursImage;
+    cvtColor(binaryImage, contoursImage, COLOR_GRAY2RGB);
+    drawContours( contoursImage, contours, -1, Scalar(0,255,0) );
+    imshow("contours", contoursImage );
 #endif
 
     for (size_t contourIdx = 0; contourIdx < contours.size(); contourIdx++)
@@ -296,12 +292,12 @@ void SimpleBlobDetectorImpl::findBlobs(InputArray _image, InputArray _binaryImag
 
 
 #ifdef DEBUG_BLOB_DETECTOR
-        //    circle( keypointsImage, center.location, 1, Scalar(0,0,255), 1 );
+        circle( keypointsImage, center.location, 1, Scalar(0,0,255), 1 );
 #endif
     }
 #ifdef DEBUG_BLOB_DETECTOR
-    //  imshow("bk", keypointsImage );
-    //  waitKey();
+    imshow("bk", keypointsImage );
+    waitKey();
 #endif
 }
 
diff --git a/modules/highgui/CMakeLists.txt b/modules/highgui/CMakeLists.txt
index 2dcd158145..986a9c2326 100644
--- a/modules/highgui/CMakeLists.txt
+++ b/modules/highgui/CMakeLists.txt
@@ -125,8 +125,8 @@ elseif(HAVE_COCOA)
   list(APPEND HIGHGUI_LIBRARIES "-framework Cocoa")
 endif()
 
-if(UNIX)
-  #these variables are set by CHECK_MODULE macro
+if(TRUE)
+  # these variables are set by 'ocv_append_build_options(HIGHGUI ...)'
   foreach(P ${HIGHGUI_INCLUDE_DIRS})
     ocv_include_directories(${P})
   endforeach()
diff --git a/modules/imgcodecs/CMakeLists.txt b/modules/imgcodecs/CMakeLists.txt
index c7ff7e7975..30e8a9d3d0 100644
--- a/modules/imgcodecs/CMakeLists.txt
+++ b/modules/imgcodecs/CMakeLists.txt
@@ -116,8 +116,8 @@ if(APPLE_FRAMEWORK)
   list(APPEND IMGCODECS_LIBRARIES "-framework UIKit")
 endif()
 
-if(UNIX)
-  #these variables are set by CHECK_MODULE macro
+if(TRUE)
+  # these variables are set by 'ocv_append_build_options(IMGCODECS ...)'
   foreach(P ${IMGCODECS_INCLUDE_DIRS})
     ocv_include_directories(${P})
   endforeach()
diff --git a/modules/imgproc/test/test_canny.cpp b/modules/imgproc/test/test_canny.cpp
index 161b839f48..f4d277a386 100644
--- a/modules/imgproc/test/test_canny.cpp
+++ b/modules/imgproc/test/test_canny.cpp
@@ -75,8 +75,6 @@ CV_CannyTest::CV_CannyTest(bool custom_deriv)
     aperture_size = 0;
     use_true_gradient = false;
     threshold1 = threshold2 = 0;
-
-    test_cpp = false;
     test_custom_deriv = custom_deriv;
 
     const char imgPath[] = "shared/fruits.png";
@@ -158,11 +156,6 @@ void CV_CannyTest::run_func()
         cvtest::filter2D(src, dy, CV_16S, dykernel, anchor, 0, BORDER_REPLICATE);
         cv::Canny(dx, dy, _out, threshold1, threshold2, use_true_gradient);
     }
-    else if(!test_cpp)
-    {
-        cvCanny( test_array[INPUT][0], test_array[OUTPUT][0], threshold1, threshold2,
-                aperture_size + (use_true_gradient ? CV_CANNY_L2_GRADIENT : 0));
-    }
     else
     {
         cv::Mat _out = cv::cvarrToMat(test_array[OUTPUT][0]);
diff --git a/modules/imgproc/test/test_drawing.cpp b/modules/imgproc/test/test_drawing.cpp
index c42d7aa572..f18709448c 100644
--- a/modules/imgproc/test/test_drawing.cpp
+++ b/modules/imgproc/test/test_drawing.cpp
@@ -245,176 +245,6 @@ int CV_DrawingTest_CPP::checkLineIterator( Mat& img )
     return 0;
 }
 
-class CV_DrawingTest_C : public CV_DrawingTest
-{
-public:
-    CV_DrawingTest_C() {}
-protected:
-    virtual void draw( Mat& img );
-    virtual int checkLineIterator( Mat& img);
-};
-
-void CV_DrawingTest_C::draw( Mat& _img )
-{
-    CvSize imgSize = cvSize(600, 400);
-    _img.create( imgSize, CV_8UC3 );
-    CvMat img = cvMat(_img);
-
-    vector<CvPoint> polyline(4);
-    polyline[0] = cvPoint(0, 0);
-    polyline[1] = cvPoint(imgSize.width, 0);
-    polyline[2] = cvPoint(imgSize.width, imgSize.height);
-    polyline[3] = cvPoint(0, imgSize.height);
-    CvPoint* pts = &polyline[0];
-    int n = (int)polyline.size();
-    int actualSize = 0;
-    cvFillPoly( &img, &pts, &n, 1, cvScalar(255,255,255) );
-
-    CvPoint p1 = cvPoint(1,1), p2 = cvPoint(3,3);
-    if( cvClipLine(imgSize, &p1, &p2) )
-        cvCircle( &img, cvPoint(300,100), 40, cvScalar(0,0,255), 3 ); // draw
-
-    p1 = cvPoint(1,1), p2 = cvPoint(3,imgSize.height+1000);
-    if( cvClipLine(imgSize, &p1, &p2) )
-        cvCircle( &img, cvPoint(500,300), 50, cvScalar(255,0,0), 5, 8, 1 ); // draw
-
-    p1 = cvPoint(imgSize.width,1), p2 = cvPoint(imgSize.width,3);
-    if( cvClipLine(imgSize, &p1, &p2) )
-        cvCircle( &img, cvPoint(390,100), 10, cvScalar(0,0,255), 3 ); // not draw
-
-    p1 = cvPoint(imgSize.width-1,1), p2 = cvPoint(imgSize.width,3);
-    if( cvClipLine(imgSize, &p1, &p2) )
-        cvEllipse( &img, cvPoint(390,100), cvSize(20,30), 60, 0, 220.0, cvScalar(0,200,0), 4 ); //draw
-
-    CvBox2D box;
-    box.center.x = 100;
-    box.center.y = 200;
-    box.size.width = 200;
-    box.size.height = 100;
-    box.angle = 160;
-    cvEllipseBox( &img, box, cvScalar(200,200,255), 5 );
-
-    polyline.resize(9);
-    pts = &polyline[0];
-    n = (int)polyline.size();
-    actualSize = cvEllipse2Poly( cvPoint(430,180), cvSize(100,150), 30, 0, 150, &polyline[0], 20 );
-    CV_Assert(actualSize == n);
-    cvPolyLine( &img, &pts, &n, 1, false, cvScalar(0,0,150), 4, CV_AA );
-    n = 0;
-    for( vector<CvPoint>::const_iterator it = polyline.begin(); n < (int)polyline.size()-1; ++it, n++ )
-    {
-        cvLine( &img, *it, *(it+1), cvScalar(50,250,100) );
-    }
-
-    polyline.resize(19);
-    pts = &polyline[0];
-    n = (int)polyline.size();
-    actualSize = cvEllipse2Poly( cvPoint(500,300), cvSize(50,80), 0, 0, 180, &polyline[0], 10 );
-    CV_Assert(actualSize == n);
-    cvPolyLine( &img, &pts, &n, 1, true, cvScalar(100,200,100), 20 );
-    cvFillConvexPoly( &img, pts, n, cvScalar(0, 80, 0) );
-
-    polyline.resize(8);
-    // external rectengular
-    polyline[0] = cvPoint(500, 20);
-    polyline[1] = cvPoint(580, 20);
-    polyline[2] = cvPoint(580, 100);
-    polyline[3] = cvPoint(500, 100);
-    // internal rectangular
-    polyline[4] = cvPoint(520, 40);
-    polyline[5] = cvPoint(560, 40);
-    polyline[6] = cvPoint(560, 80);
-    polyline[7] = cvPoint(520, 80);
-    CvPoint* ppts[] = {&polyline[0], &polyline[0]+4};
-    int pn[] = {4, 4};
-    cvFillPoly( &img, ppts, pn, 2, cvScalar(100, 100, 0), 8, 0 );
-
-    cvRectangle( &img, cvPoint(0, 300), cvPoint(50, 398), cvScalar(0,0,255) );
-
-    string text1 = "OpenCV";
-    CvFont font;
-    cvInitFont( &font, FONT_HERSHEY_SCRIPT_SIMPLEX, 2, 2, 0, 3 );
-    int baseline = 0;
-    CvSize textSize = {0, 0};
-    cvGetTextSize( text1.c_str(), &font, &textSize, &baseline );
-    baseline += font.thickness;
-    CvPoint textOrg = cvPoint((imgSize.width - textSize.width)/2, (imgSize.height + textSize.height)/2);
-    cvRectangle( &img, cvPoint( textOrg.x, textOrg.y + baseline),
-                 cvPoint(textOrg.x + textSize.width, textOrg.y - textSize.height), cvScalar(0,0,255));
-    cvLine( &img, cvPoint(textOrg.x, textOrg.y + font.thickness),
-            cvPoint(textOrg.x + textSize.width, textOrg.y + font.thickness), cvScalar(0, 0, 255));
-    cvPutText( &img, text1.c_str(), textOrg, &font, cvScalar(150,0,150) );
-
-    int dist = 5;
-    string text2 = "abcdefghijklmnopqrstuvwxyz1234567890";
-    CvScalar color = cvScalar(200,0,0);
-    cvInitFont( &font, FONT_HERSHEY_SIMPLEX, 0.5, 0.5, 0, 1, CV_AA );
-    cvGetTextSize( text2.c_str(), &font, &textSize, &baseline );
-    textOrg = cvPoint(5, 5+textSize.height+dist);
-    cvPutText(&img, text2.c_str(), textOrg, &font, color );
-
-    cvInitFont( &font, FONT_HERSHEY_PLAIN, 1, 1, 0, 1, CV_AA );
-    cvGetTextSize( text2.c_str(), &font, &textSize, &baseline );
-    textOrg = cvPoint(textOrg.x,textOrg.y+textSize.height+dist);
-    cvPutText(&img, text2.c_str(), textOrg, &font, color );
-
-    cvInitFont( &font, FONT_HERSHEY_DUPLEX, 0.5, 0.5, 0, 1, CV_AA );
-    cvGetTextSize( text2.c_str(), &font, &textSize, &baseline );
-    textOrg = cvPoint(textOrg.x,textOrg.y+textSize.height+dist);
-    cvPutText(&img, text2.c_str(), textOrg, &font, color );
-
-    cvInitFont( &font, FONT_HERSHEY_COMPLEX, 0.5, 0.5, 0, 1, CV_AA );
-    cvGetTextSize( text2.c_str(), &font, &textSize, &baseline );
-    textOrg = cvPoint(textOrg.x,textOrg.y+textSize.height+dist);
-    cvPutText(&img, text2.c_str(), textOrg, &font, color );
-
-    cvInitFont( &font, FONT_HERSHEY_TRIPLEX, 0.5, 0.5, 0, 1, CV_AA );
-    cvGetTextSize( text2.c_str(), &font, &textSize, &baseline );
-    textOrg = cvPoint(textOrg.x,textOrg.y+textSize.height+dist);
-    cvPutText(&img, text2.c_str(), textOrg, &font, color );
-
-    cvInitFont( &font, FONT_HERSHEY_COMPLEX_SMALL, 1, 1, 0, 1, CV_AA );
-    cvGetTextSize( text2.c_str(), &font, &textSize, &baseline );
-    textOrg = cvPoint(textOrg.x,textOrg.y+textSize.height+dist + 180);
-    cvPutText(&img, text2.c_str(), textOrg, &font, color );
-
-    cvInitFont( &font, FONT_HERSHEY_SCRIPT_SIMPLEX, 1, 1, 0, 1, CV_AA );
-    cvGetTextSize( text2.c_str(), &font, &textSize, &baseline );
-    textOrg = cvPoint(textOrg.x,textOrg.y+textSize.height+dist);
-    cvPutText(&img, text2.c_str(), textOrg, &font, color );
-
-    cvInitFont( &font, FONT_HERSHEY_SCRIPT_COMPLEX, 1, 1, 0, 1, CV_AA );
-    cvGetTextSize( text2.c_str(), &font, &textSize, &baseline );
-    textOrg = cvPoint(textOrg.x,textOrg.y+textSize.height+dist);
-    cvPutText(&img, text2.c_str(), textOrg, &font, color );
-
-    dist = 15;
-    cvInitFont( &font, FONT_ITALIC, 0.5, 0.5, 0, 1, CV_AA );
-    cvGetTextSize( text2.c_str(), &font, &textSize, &baseline );
-    textOrg = cvPoint(textOrg.x,textOrg.y+textSize.height+dist);
-    cvPutText(&img, text2.c_str(), textOrg, &font, color );
-}
-
-int CV_DrawingTest_C::checkLineIterator( Mat& _img )
-{
-    CvLineIterator it;
-    CvMat img = cvMat(_img);
-    int count = cvInitLineIterator( &img, cvPoint(0,300), cvPoint(1000, 300), &it );
-    for(int i = 0; i < count; i++ )
-    {
-        Vec3b v = (Vec3b)(*(it.ptr)) - _img.at<Vec3b>(300,i);
-        float err = (float)cvtest::norm( v, NORM_L2 );
-        if( err != 0 )
-        {
-            ts->printf( ts->LOG, "CvLineIterator works incorrect" );
-            ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_OUTPUT);
-        }
-        CV_NEXT_LINE_POINT(it);
-    }
-    ts->set_failed_test_info(cvtest::TS::OK);
-    return 0;
-}
-
 class CV_DrawingTest_Far : public CV_DrawingTest_CPP
 {
 public:
@@ -549,7 +379,6 @@ void CV_DrawingTest_Far::draw(Mat& img)
 }
 
 TEST(Drawing,    cpp_regression) { CV_DrawingTest_CPP test; test.safe_run(); }
-TEST(Drawing,      c_regression) { CV_DrawingTest_C   test; test.safe_run(); }
 TEST(Drawing,    far_regression) { CV_DrawingTest_Far test; test.safe_run(); }
 
 class CV_FillConvexPolyTest : public cvtest::BaseTest
diff --git a/modules/imgproc/test/test_filter.cpp b/modules/imgproc/test/test_filter.cpp
index 5dcedeee14..cb7ae97d9d 100644
--- a/modules/imgproc/test/test_filter.cpp
+++ b/modules/imgproc/test/test_filter.cpp
@@ -536,11 +536,9 @@ void CV_SobelTest::get_test_array_types_and_sizes( int test_case_idx,
 
 void CV_SobelTest::run_func()
 {
-    cvSobel( test_array[inplace ? OUTPUT : INPUT][0],
-             test_array[OUTPUT][0], dx, dy, _aperture_size );
-    /*cv::Sobel( test_mat[inplace ? OUTPUT : INPUT][0],
+    cv::Sobel( test_mat[inplace ? OUTPUT : INPUT][0],
                test_mat[OUTPUT][0], test_mat[OUTPUT][0].depth(),
-               dx, dy, _aperture_size, 1, 0, border );*/
+               dx, dy, _aperture_size, 1, 0, border );
 }
 
 
@@ -655,8 +653,9 @@ void CV_LaplaceTest::get_test_array_types_and_sizes( int test_case_idx,
 
 void CV_LaplaceTest::run_func()
 {
-    cvLaplace( test_array[inplace ? OUTPUT : INPUT][0],
-               test_array[OUTPUT][0], _aperture_size );
+    cv::Laplacian( test_mat[inplace ? OUTPUT : INPUT][0],
+                   test_mat[OUTPUT][0],test_mat[OUTPUT][0].depth(),
+                   _aperture_size, 1, 0, cv::BORDER_REPLICATE );
 }
 
 
diff --git a/modules/java/test/pure_test/build.xml b/modules/java/test/pure_test/build.xml
index 7729b41b2b..870dd44d74 100644
--- a/modules/java/test/pure_test/build.xml
+++ b/modules/java/test/pure_test/build.xml
@@ -41,6 +41,7 @@
     <junit printsummary="true" haltonfailure="false" haltonerror="false" showoutput="true" logfailedtests="true" maxmemory="256m">
       <sysproperty key="java.library.path" path="${opencv.lib.path}"/>
       <env key="PATH" path="${opencv.lib.path}:${env.PATH}:${env.Path}"/>
+      <env key="DYLD_LIBRARY_PATH" path="${env.OPENCV_SAVED_DYLD_LIBRARY_PATH}"/>  <!-- https://github.com/opencv/opencv/issues/14353 -->
       <classpath refid="master-classpath"/>
       <classpath>
         <pathelement location="build/classes"/>
diff --git a/modules/ml/include/opencv2/ml.hpp b/modules/ml/include/opencv2/ml.hpp
index f1258fdcb6..a1d68446ce 100644
--- a/modules/ml/include/opencv2/ml.hpp
+++ b/modules/ml/include/opencv2/ml.hpp
@@ -505,6 +505,14 @@ public:
     The static method creates empty %KNearest classifier. It should be then trained using StatModel::train method.
      */
     CV_WRAP static Ptr<KNearest> create();
+    /** @brief Loads and creates a serialized knearest from a file
+     *
+     * Use KNearest::save to serialize and store an KNearest to disk.
+     * Load the KNearest from this file again, by calling this function with the path to the file.
+     *
+     * @param filepath path to serialized KNearest
+     */
+    CV_WRAP static Ptr<KNearest> load(const String& filepath);
 };
 
 /****************************************************************************************\
diff --git a/modules/ml/misc/python/test/test_knearest.py b/modules/ml/misc/python/test/test_knearest.py
new file mode 100644
index 0000000000..8ae0be5f73
--- /dev/null
+++ b/modules/ml/misc/python/test/test_knearest.py
@@ -0,0 +1,13 @@
+#!/usr/bin/env python
+import cv2 as cv
+
+from tests_common import NewOpenCVTests
+
+class knearest_test(NewOpenCVTests):
+    def test_load(self):
+        k_nearest = cv.ml.KNearest_load(self.find_file("ml/opencv_ml_knn.xml"))
+        self.assertFalse(k_nearest.empty())
+        self.assertTrue(k_nearest.isTrained())
+
+if __name__ == '__main__':
+    NewOpenCVTests.bootstrap()
diff --git a/modules/ml/src/knearest.cpp b/modules/ml/src/knearest.cpp
index cee7bdfdb0..dcc201158d 100644
--- a/modules/ml/src/knearest.cpp
+++ b/modules/ml/src/knearest.cpp
@@ -515,6 +515,17 @@ Ptr<KNearest> KNearest::create()
     return makePtr<KNearestImpl>();
 }
 
+Ptr<KNearest> KNearest::load(const String& filepath)
+{
+    FileStorage fs;
+    fs.open(filepath, FileStorage::READ);
+
+    Ptr<KNearest> knearest = makePtr<KNearestImpl>();
+
+    ((KNearestImpl*)knearest.get())->read(fs.getFirstTopLevelNode());
+    return knearest;
+}
+
 }
 }
 
diff --git a/modules/ts/misc/run_utils.py b/modules/ts/misc/run_utils.py
index 4fc84cc8ef..8c942ba9d1 100644
--- a/modules/ts/misc/run_utils.py
+++ b/modules/ts/misc/run_utils.py
@@ -37,6 +37,13 @@ def execute(cmd, silent=False, cwd=".", env=None):
             new_env = os.environ.copy()
             new_env.update(env)
             env = new_env
+
+        if sys.platform == 'darwin':  # https://github.com/opencv/opencv/issues/14351
+            if env is None:
+                env = os.environ.copy()
+            if 'DYLD_LIBRARY_PATH' in env:
+                env['OPENCV_SAVED_DYLD_LIBRARY_PATH'] = env['DYLD_LIBRARY_PATH']
+
         if silent:
             return check_output(cmd, stderr=STDOUT, cwd=cwd, env=env).decode("latin-1")
         else:
diff --git a/modules/ts/src/ts.cpp b/modules/ts/src/ts.cpp
index 0d6e0368db..2ef0326294 100644
--- a/modules/ts/src/ts.cpp
+++ b/modules/ts/src/ts.cpp
@@ -755,6 +755,7 @@ static uint64_t memory_usage_base_opencl = 0;
 
 void testSetUp()
 {
+    fflush(stdout); fflush(stderr);
     cv::ipp::setIppStatus(0);
     cv::theRNG().state = cvtest::param_seed;
     cv::setNumThreads(cvtest::testThreads);
diff --git a/modules/videoio/cmake/detect_aravis.cmake b/modules/videoio/cmake/detect_aravis.cmake
index 9994df8339..79d6a217db 100644
--- a/modules/videoio/cmake/detect_aravis.cmake
+++ b/modules/videoio/cmake/detect_aravis.cmake
@@ -1,6 +1,6 @@
 # --- Aravis SDK ---
 if(NOT HAVE_ARAVIS_API AND PKG_CONFIG_FOUND)
-  pkg_check_modules(ARAVIS aravis-0.6 QUIET)
+  ocv_check_modules(ARAVIS aravis-0.6 QUIET)
   if(ARAVIS_FOUND)
     set(HAVE_ARAVIS_API TRUE)
   endif()
diff --git a/modules/videoio/cmake/detect_dc1394.cmake b/modules/videoio/cmake/detect_dc1394.cmake
index ab12964581..51ab2dd80e 100644
--- a/modules/videoio/cmake/detect_dc1394.cmake
+++ b/modules/videoio/cmake/detect_dc1394.cmake
@@ -1,6 +1,6 @@
 # --- Dc1394 ---
 if(NOT HAVE_DC1394_2 AND PKG_CONFIG_FOUND)
-  pkg_check_modules(DC1394_2 libdc1394-2 QUIET)
+  ocv_check_modules(DC1394_2 libdc1394-2)
   if(DC1394_2_FOUND)
     set(DC1394_2_VERSION "${DC1394_2_VERSION}" PARENT_SCOPE) # informational
     set(HAVE_DC1394_2 TRUE)
diff --git a/modules/videoio/cmake/detect_ffmpeg.cmake b/modules/videoio/cmake/detect_ffmpeg.cmake
index ea1295d820..57dd95cc55 100644
--- a/modules/videoio/cmake/detect_ffmpeg.cmake
+++ b/modules/videoio/cmake/detect_ffmpeg.cmake
@@ -25,23 +25,12 @@ if(NOT HAVE_FFMPEG AND WIN32 AND NOT ARM AND NOT OPENCV_FFMPEG_SKIP_DOWNLOAD)
 endif()
 
 if(NOT HAVE_FFMPEG AND PKG_CONFIG_FOUND)
-  pkg_check_modules(FFMPEG libavcodec libavformat libavutil libswscale QUIET)
-  pkg_check_modules(FFMPEG_libavresample libavresample QUIET) # optional
+  ocv_check_modules(FFMPEG libavcodec libavformat libavutil libswscale)
   if(FFMPEG_FOUND)
+    ocv_check_modules(FFMPEG_libavresample libavresample) # optional
     if(FFMPEG_libavresample_FOUND)
       list(APPEND FFMPEG_LIBRARIES ${FFMPEG_libavresample_LIBRARIES})
     endif()
-    # rewrite libraries to absolute paths
-    foreach(lib ${FFMPEG_LIBRARIES})
-      find_library(FFMPEG_ABSOLUTE_${lib} "${lib}" PATHS "${FFMPEG_lib${lib}_LIBDIR}" "${FFMPEG_LIBRARY_DIRS}" NO_DEFAULT_PATH)
-      if(FFMPEG_ABSOLUTE_${lib})
-        list(APPEND ffmpeg_abs_libs "${FFMPEG_ABSOLUTE_${lib}}")
-      else()
-        list(APPEND ffmpeg_abs_libs "${lib}")
-      endif()
-    endforeach()
-    set(FFMPEG_LIBRARIES "${ffmpeg_abs_libs}" CACHE INTERNAL "" FORCE)
-
     set(HAVE_FFMPEG TRUE)
   endif()
 endif()
diff --git a/modules/videoio/cmake/detect_gphoto.cmake b/modules/videoio/cmake/detect_gphoto.cmake
index 3837bef92e..0d6f1212eb 100644
--- a/modules/videoio/cmake/detect_gphoto.cmake
+++ b/modules/videoio/cmake/detect_gphoto.cmake
@@ -1,6 +1,6 @@
 # --- gPhoto2 ---
 if(NOT HAVE_GPHOTO2 AND PKG_CONFIG_FOUND)
-  pkg_check_modules(GPHOTO2 libgphoto2 QUIET)
+  ocv_check_modules(GPHOTO2 libgphoto2)
   if(GPHOTO2_FOUND)
     set(HAVE_GPHOTO2 TRUE)
   endif()
diff --git a/modules/videoio/cmake/detect_gstreamer.cmake b/modules/videoio/cmake/detect_gstreamer.cmake
index 1d7abaf1f2..7b74693f5e 100644
--- a/modules/videoio/cmake/detect_gstreamer.cmake
+++ b/modules/videoio/cmake/detect_gstreamer.cmake
@@ -82,10 +82,10 @@ if(NOT HAVE_GSTREAMER AND WIN32)
 endif()
 
 if(NOT HAVE_GSTREAMER AND PKG_CONFIG_FOUND)
-  pkg_check_modules(GSTREAMER_base gstreamer-base-1.0 QUIET)
-  pkg_check_modules(GSTREAMER_app gstreamer-app-1.0 QUIET)
-  pkg_check_modules(GSTREAMER_riff gstreamer-riff-1.0 QUIET)
-  pkg_check_modules(GSTREAMER_pbutils gstreamer-pbutils-1.0 QUIET)
+  ocv_check_modules(GSTREAMER_base gstreamer-base-1.0)
+  ocv_check_modules(GSTREAMER_app gstreamer-app-1.0)
+  ocv_check_modules(GSTREAMER_riff gstreamer-riff-1.0)
+  ocv_check_modules(GSTREAMER_pbutils gstreamer-pbutils-1.0)
   if(GSTREAMER_base_FOUND AND GSTREAMER_app_FOUND AND GSTREAMER_riff_FOUND AND GSTREAMER_pbutils_FOUND)
     set(HAVE_GSTREAMER TRUE)
     set(GSTREAMER_VERSION ${GSTREAMER_base_VERSION} PARENT_SCOPE) # informational
diff --git a/modules/videoio/cmake/detect_xine.cmake b/modules/videoio/cmake/detect_xine.cmake
index 14d61a4b3f..3e1f3010a4 100644
--- a/modules/videoio/cmake/detect_xine.cmake
+++ b/modules/videoio/cmake/detect_xine.cmake
@@ -1,8 +1,5 @@
 if(NOT HAVE_XINE AND PKG_CONFIG_FOUND)
-  pkg_check_modules(XINE libxine QUIET)
-  if(XINE_FOUND)
-    set(HAVE_XINE TRUE)
-  endif()
+  ocv_check_modules(XINE libxine QUIET)
 endif()
 
 if(HAVE_XINE)
diff --git a/modules/videoio/cmake/plugin.cmake b/modules/videoio/cmake/plugin.cmake
index b3e2d8ab5d..adc52f89f5 100644
--- a/modules/videoio/cmake/plugin.cmake
+++ b/modules/videoio/cmake/plugin.cmake
@@ -1,5 +1,6 @@
 #=============================================
 # build with OpenCV
+include("${OpenCV_SOURCE_DIR}/cmake/OpenCVUtils.cmake")
 
 function(ocv_create_builtin_videoio_plugin name target videoio_src_file)
 
diff --git a/modules/videoio/misc/build_plugins.sh b/modules/videoio/misc/build_plugins.sh
index 938ae7643b..9a7090e907 100755
--- a/modules/videoio/misc/build_plugins.sh
+++ b/modules/videoio/misc/build_plugins.sh
@@ -3,7 +3,7 @@
 set -e
 
 if [ -z $1 ] ; then
-    echo "<script> <destination directory>"
+    echo "$0 <destination directory>"
     exit 1
 fi
 
diff --git a/samples/dnn/README.md b/samples/dnn/README.md
index 9072ddb2a8..d470e9c6d8 100644
--- a/samples/dnn/README.md
+++ b/samples/dnn/README.md
@@ -2,19 +2,22 @@
 
 ## Model Zoo
 
-### Object detection
-
-|    Model | Scale |   Size WxH|   Mean subtraction | Channels order |
-|---------------|-------|-----------|--------------------|-------|
-| [MobileNet-SSD, Caffe](https://github.com/chuanqi305/MobileNet-SSD/) | `0.00784 (2/255)` | `300x300` | `127.5 127.5 127.5` | BGR |
-| [OpenCV face detector](https://github.com/opencv/opencv/tree/master/samples/dnn/face_detector) | `1.0` | `300x300` | `104 177 123` | BGR |
-| [SSDs from TensorFlow](https://github.com/tensorflow/models/tree/master/research/object_detection/) | `0.00784 (2/255)` | `300x300` | `127.5 127.5 127.5` | RGB |
-| [YOLO](https://pjreddie.com/darknet/yolo/) | `0.00392 (1/255)` | `416x416` | `0 0 0` | RGB |
-| [VGG16-SSD](https://github.com/weiliu89/caffe/tree/ssd) | `1.0` | `300x300` | `104 117 123` | BGR |
-| [Faster-RCNN](https://github.com/rbgirshick/py-faster-rcnn) | `1.0` | `800x600` | `102.9801 115.9465 122.7717` | BGR |
-| [R-FCN](https://github.com/YuwenXiong/py-R-FCN) | `1.0` | `800x600` | `102.9801 115.9465 122.7717` | BGR |
-| [Faster-RCNN, ResNet backbone](https://github.com/tensorflow/models/tree/master/research/object_detection/) | `1.0` | `300x300` | `103.939 116.779 123.68` | RGB |
-| [Faster-RCNN, InceptionV2 backbone](https://github.com/tensorflow/models/tree/master/research/object_detection/) | `0.00784 (2/255)` | `300x300` | `127.5 127.5 127.5` | RGB |
+Check [a wiki](https://github.com/opencv/opencv/wiki/Deep-Learning-in-OpenCV) for a list of tested models.
+
+If OpenCV is built with [Intel's Inference Engine support](https://github.com/opencv/opencv/wiki/Intel%27s-Deep-Learning-Inference-Engine-backend) you can use [Intel's pre-trained](https://github.com/opencv/open_model_zoo) models.
+
+There are different preprocessing parameters such mean subtraction or scale factors for different models.
+You may check the most popular models and their parameters at [models.yml](https://github.com/opencv/opencv/blob/master/samples/dnn/models.yml) configuration file. It might be also used for aliasing samples parameters. In example,
+
+```bash
+python object_detection.py opencv_fd --model /path/to/caffemodel --config /path/to/prototxt
+```
+
+Check `-h` option to know which values are used by default:
+
+```bash
+python object_detection.py opencv_fd -h
+```
 
 #### Face detection
 [An origin model](https://github.com/opencv/opencv/tree/master/samples/dnn/face_detector)
@@ -44,18 +47,6 @@ AR @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] | 0.481     | 0.480 (-0.001) |
 AR @[ IoU=0.50:0.95 | area= large | maxDets=100 ] | 0.528     | 0.528          | 0.520     | 0.462 (-0.058) |
 ```
 
-### Classification
-|    Model | Scale |   Size WxH|   Mean subtraction | Channels order |
-|---------------|-------|-----------|--------------------|-------|
-| GoogLeNet | `1.0` | `224x224` | `104 117 123` | BGR |
-| [SqueezeNet](https://github.com/DeepScale/SqueezeNet) | `1.0` | `227x227` | `0 0 0` | BGR |
-
-### Semantic segmentation
-|    Model | Scale |   Size WxH|   Mean subtraction | Channels order |
-|---------------|-------|-----------|--------------------|-------|
-| [ENet](https://github.com/e-lab/ENet-training) | `0.00392 (1/255)` | `1024x512` | `0 0 0` | RGB |
-| FCN8s | `1.0` | `500x500` | `0 0 0` | BGR |
-
 ## References
 * [Models downloading script](https://github.com/opencv/opencv_extra/blob/master/testdata/dnn/download_models.py)
 * [Configuration files adopted for OpenCV](https://github.com/opencv/opencv_extra/tree/master/testdata/dnn)