Merge remote-tracking branch 'upstream/3.4' into merge-3.4
authorAlexander Alekhin <alexander.a.alekhin@gmail.com>
Tue, 5 Mar 2019 17:26:46 +0000 (17:26 +0000)
committerAlexander Alekhin <alexander.alekhin@intel.com>
Wed, 6 Mar 2019 08:43:16 +0000 (11:43 +0300)
15 files changed:
1  2 
cmake/OpenCVDetectCXXCompiler.cmake
modules/calib3d/include/opencv2/calib3d.hpp
modules/core/include/opencv2/core/mat.hpp
modules/core/src/opengl.cpp
modules/core/test/test_mat.cpp
modules/dnn/src/ocl4dnn/src/ocl4dnn_conv_spatial.cpp
modules/highgui/src/window_QT.cpp
modules/imgproc/include/opencv2/imgproc.hpp
modules/imgproc/src/lsd.cpp
modules/imgproc/src/pyramids.cpp
modules/java/generator/gen_java.py
modules/ml/src/svm.cpp
modules/python/src2/cv2.cpp
modules/videoio/src/cap_v4l.cpp
platforms/android/build_sdk.py

Simple merge
Simple merge
Simple merge
Simple merge
  #include "precomp.hpp"
  #include <vector>
  
- /////////////////////////////////////////////////////////////////////////////////////////
- // Default LSD parameters
- // SIGMA_SCALE 0.6    - Sigma for Gaussian filter is computed as sigma = sigma_scale/scale.
- // QUANT       2.0    - Bound to the quantization error on the gradient norm.
- // ANG_TH      22.5   - Gradient angle tolerance in degrees.
- // LOG_EPS     0.0    - Detection threshold: -log10(NFA) > log_eps
- // DENSITY_TH  0.7    - Minimal density of region points in rectangle.
- // N_BINS      1024   - Number of bins in pseudo-ordering of gradient modulus.
- #define M_3_2_PI    (3 * CV_PI) / 2   // 3/2 pi
- #define M_2__PI     (2 * CV_PI)         // 2 pi
- #ifndef M_LN10
- #define M_LN10      2.30258509299404568402
++#if defined(_MSC_VER)
++#   pragma warning(disable:4702)  // unreachable code
 +#endif
 +
- #define NOTDEF      double(-1024.0) // Label for pixels with undefined gradient.
- #define NOTUSED     0   // Label for pixels not used in yet.
- #define USED        1   // Label for pixels already used in detection.
- #define RELATIVE_ERROR_FACTOR 100.0
- const double DEG_TO_RADS = CV_PI / 180;
- #define log_gamma(x) ((x)>15.0?log_gamma_windschitl(x):log_gamma_lanczos(x))
- struct edge
- {
-     cv::Point p;
-     bool taken;
- };
- /////////////////////////////////////////////////////////////////////////////////////////
- inline double distSq(const double x1, const double y1,
-                      const double x2, const double y2)
- {
-     return (x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1);
- }
- inline double dist(const double x1, const double y1,
-                    const double x2, const double y2)
- {
-     return sqrt(distSq(x1, y1, x2, y2));
- }
- // Signed angle difference
- inline double angle_diff_signed(const double& a, const double& b)
- {
-     double diff = a - b;
-     while(diff <= -CV_PI) diff += M_2__PI;
-     while(diff >   CV_PI) diff -= M_2__PI;
-     return diff;
- }
- // Absolute value angle difference
- inline double angle_diff(const double& a, const double& b)
- {
-     return std::fabs(angle_diff_signed(a, b));
- }
- // Compare doubles by relative error.
- inline bool double_equal(const double& a, const double& b)
- {
-     // trivial case
-     if(a == b) return true;
-     double abs_diff = fabs(a - b);
-     double aa = fabs(a);
-     double bb = fabs(b);
-     double abs_max = (aa > bb)? aa : bb;
-     if(abs_max < DBL_MIN) abs_max = DBL_MIN;
-     return (abs_diff / abs_max) <= (RELATIVE_ERROR_FACTOR * DBL_EPSILON);
- }
- inline bool AsmallerB_XoverY(const edge& a, const edge& b)
- {
-     if (a.p.x == b.p.x) return a.p.y < b.p.y;
-     else return a.p.x < b.p.x;
- }
- /**
-  *   Computes the natural logarithm of the absolute value of
-  *   the gamma function of x using Windschitl method.
-  *   See http://www.rskey.org/gamma.htm
-  */
- inline double log_gamma_windschitl(const double& x)
- {
-     return 0.918938533204673 + (x-0.5)*log(x) - x
-          + 0.5*x*log(x*sinh(1/x) + 1/(810.0*pow(x, 6.0)));
- }
- /**
-  *   Computes the natural logarithm of the absolute value of
-  *   the gamma function of x using the Lanczos approximation.
-  *   See http://www.rskey.org/gamma.htm
-  */
- inline double log_gamma_lanczos(const double& x)
- {
-     static double q[7] = { 75122.6331530, 80916.6278952, 36308.2951477,
-                          8687.24529705, 1168.92649479, 83.8676043424,
-                          2.50662827511 };
-     double a = (x + 0.5) * log(x + 5.5) - (x + 5.5);
-     double b = 0;
-     for(int n = 0; n < 7; ++n)
-     {
-         a -= log(x + double(n));
-         b += q[n] * pow(x, double(n));
-     }
-     return a + log(b);
- }
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
- namespace cv{
+ namespace cv {
  
  class LineSegmentDetectorImpl CV_FINAL : public LineSegmentDetector
  {
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
@@@ -50,14 -50,18 +50,14 @@@ def check_dir(d, create=False, clean=Fa
  
  def check_executable(cmd):
      try:
-         FNULL = open(os.devnull, 'w')
-         retcode = subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT)
-         if retcode < 0:
-             return False
+         log.debug("Executing: %s" % cmd)
+         result = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
+         log.debug("Result: %s" % (result+'\n').split('\n')[0])
          return True
-     except:
+     except Exception as e:
+         log.debug('Failed: %s' % e)
          return False
  
 -def determine_engine_version(manifest_path):
 -    with open(manifest_path, "rt") as f:
 -        return re.search(r'android:versionName="(\d+\.\d+)"', f.read(), re.MULTILINE).group(1)
 -
  def determine_opencv_version(version_hpp_path):
      # version in 2.4 - CV_VERSION_EPOCH.CV_VERSION_MAJOR.CV_VERSION_MINOR.CV_VERSION_REVISION
      # version in master - CV_VERSION_MAJOR.CV_VERSION_MINOR.CV_VERSION_REVISION-CV_VERSION_STATUS
@@@ -139,10 -143,13 +139,12 @@@ class Builder
          self.docdest = check_dir(os.path.join(self.workdir, 'OpenCV-android-sdk', 'sdk', 'java', 'javadoc'), create=True, clean=True)
          self.extra_packs = []
          self.opencv_version = determine_opencv_version(os.path.join(self.opencvdir, "modules", "core", "include", "opencv2", "core", "version.hpp"))
 -        self.engine_version = determine_engine_version(os.path.join(self.opencvdir, "platforms", "android", "service", "engine", "AndroidManifest.xml"))
          self.use_ccache = False if config.no_ccache else True
+         self.cmake_path = self.get_cmake()
+         self.ninja_path = self.get_ninja()
  
      def get_cmake(self):
-         if check_executable(['cmake', '--version']):
+         if not self.config.use_android_buildtools and check_executable(['cmake', '--version']):
              log.info("Using cmake from PATH")
              return 'cmake'
          # look to see if Android SDK's cmake is installed
          cmd += [ "-D%s='%s'" % (k, v) for (k, v) in cmake_vars.items() if v is not None]
          cmd.append(self.opencvdir)
          execute(cmd)
-         execute([self.get_ninja(), "install/strip"])
 -        if do_install:
 -            execute([self.ninja_path])
 -            for c in ["libs", "dev", "java", "samples"]:
 -                execute([self.cmake_path, "-DCOMPONENT=%s" % c, "-P", "cmake_install.cmake"])
 -        else:
 -            execute([self.ninja_path, "install/strip"])
 -
 -    def build_engine(self, abi, engdest):
 -        cmd = [self.cmake_path, "-GNinja"]
 -        cmake_vars = dict(
 -            CMAKE_TOOLCHAIN_FILE=self.get_toolchain_file(),
 -            WITH_OPENCL="OFF",
 -            WITH_IPP="OFF",
 -            BUILD_ANDROID_SERVICE = 'ON'
 -        )
 -        if self.ninja_path != 'ninja':
 -            cmake_vars['CMAKE_MAKE_PROGRAM'] = self.ninja_path
 -        cmake_vars.update(abi.cmake_vars)
 -        cmd += [ "-D%s='%s'" % (k, v) for (k, v) in cmake_vars.items() if v is not None]
 -        cmd.append(self.opencvdir)
 -        execute(cmd)
 -        apkdest = self.get_engine_apk_dest(engdest)
 -        assert os.path.exists(apkdest), apkdest
 -        # Add extra data
 -        apkxmldest = check_dir(os.path.join(apkdest, "res", "xml"), create=True)
 -        apklibdest = check_dir(os.path.join(apkdest, "libs", abi.name), create=True)
 -        for ver, d in self.extra_packs + [("3.4.5", os.path.join(self.libdest, "lib"))]:
 -            r = ET.Element("library", attrib={"version": ver})
 -            log.info("Adding libraries from %s", d)
 -
 -            for f in glob.glob(os.path.join(d, abi.name, "*.so")):
 -                log.info("Copy file: %s", f)
 -                shutil.copy2(f, apklibdest)
 -                if "libnative_camera" in f:
 -                    continue
 -                log.info("Register file: %s", os.path.basename(f))
 -                n = ET.SubElement(r, "file", attrib={"name": os.path.basename(f)})
 -
 -            if len(list(r)) > 0:
 -                xmlname = os.path.join(apkxmldest, "config%s.xml" % ver.replace(".", ""))
 -                log.info("Generating XML config: %s", xmlname)
 -                ET.ElementTree(r).write(xmlname, encoding="utf-8")
 -
 -        execute([self.ninja_path, "opencv_engine"])
 -        execute(["ant", "-f", os.path.join(apkdest, "build.xml"), "debug"],
 -            shell=(sys.platform == 'win32'))
 -        # TODO: Sign apk
++        execute([self.ninja_path, "install/strip"])
  
      def build_javadoc(self):
          classpaths = []
@@@ -270,9 -343,10 +273,10 @@@ if __name__ == "__main__"
      parser = argparse.ArgumentParser(description='Build OpenCV for Android SDK')
      parser.add_argument("work_dir", nargs='?', default='.', help="Working directory (and output)")
      parser.add_argument("opencv_dir", nargs='?', default=os.path.join(SCRIPT_DIR, '../..'), help="Path to OpenCV source dir")
 -    parser.add_argument('--config', default='ndk-10.config.py', type=str, help="Package build configuration", )
 +    parser.add_argument('--config', default='ndk-18.config.py', type=str, help="Package build configuration", )
      parser.add_argument('--ndk_path', help="Path to Android NDK to use for build")
      parser.add_argument('--sdk_path', help="Path to Android SDK to use for build")
+     parser.add_argument('--use_android_buildtools', action="store_true", help='Use cmake/ninja build tools from Android SDK')
      parser.add_argument("--extra_modules_path", help="Path to extra modules to use for build")
      parser.add_argument('--sign_with', help="Certificate to sign the Manager apk")
      parser.add_argument('--build_doc', action="store_true", help="Build javadoc")