Merge remote-tracking branch 'upstream/3.4' into merge-3.4
authorAlexander Alekhin <alexander.alekhin@intel.com>
Thu, 5 Dec 2019 14:29:22 +0000 (17:29 +0300)
committerAlexander Alekhin <alexander.alekhin@intel.com>
Thu, 5 Dec 2019 15:27:45 +0000 (18:27 +0300)
14 files changed:
1  2 
modules/calib3d/include/opencv2/calib3d.hpp
modules/calib3d/misc/java/test/Calib3dTest.java
modules/calib3d/src/calibration.cpp
modules/calib3d/src/solvepnp.cpp
modules/calib3d/test/test_cameracalibration.cpp
modules/core/include/opencv2/core/types_c.h
modules/core/src/norm.cpp
modules/core/src/system.cpp
modules/dnn/src/dnn.cpp
modules/dnn/src/op_inf_engine.cpp
modules/dnn/src/op_inf_engine.hpp
modules/dnn/test/test_caffe_importer.cpp
modules/dnn/test/test_tf_importer.cpp
modules/python/src2/hdr_parser.py

@@@ -1,7 -1,8 +1,9 @@@
  package org.opencv.test.calib3d;
  
+ import java.util.ArrayList;
  import org.opencv.calib3d.Calib3d;
 +import org.opencv.core.Core;
  import org.opencv.core.CvType;
  import org.opencv.core.Mat;
  import org.opencv.core.MatOfDouble;
@@@ -650,130 -642,44 +652,170 @@@ public class Calib3dTest extends OpenCV
          assertEquals((1 << 22), Calib3d.CALIB_USE_EXTRINSIC_GUESS);
      }
  
+     public void testSolvePnPGeneric_regression_16040() {
+         Mat intrinsics = Mat.eye(3, 3, CvType.CV_64F);
+         intrinsics.put(0, 0, 400);
+         intrinsics.put(1, 1, 400);
+         intrinsics.put(0, 2, 640 / 2);
+         intrinsics.put(1, 2, 480 / 2);
+         final int minPnpPointsNum = 4;
+         MatOfPoint3f points3d = new MatOfPoint3f();
+         points3d.alloc(minPnpPointsNum);
+         MatOfPoint2f points2d = new MatOfPoint2f();
+         points2d.alloc(minPnpPointsNum);
+         for (int i = 0; i < minPnpPointsNum; i++) {
+             double x = Math.random() * 100 - 50;
+             double y = Math.random() * 100 - 50;
+             points2d.put(i, 0, x, y); //add(new Point(x, y));
+             points3d.put(i, 0, 0, y, x); // add(new Point3(0, y, x));
+         }
+         ArrayList<Mat> rvecs = new ArrayList<Mat>();
+         ArrayList<Mat> tvecs = new ArrayList<Mat>();
+         Mat rvec = new Mat();
+         Mat tvec = new Mat();
+         Mat reprojectionError = new Mat(2, 1, CvType.CV_64FC1);
+         Calib3d.solvePnPGeneric(points3d, points2d, intrinsics, new MatOfDouble(), rvecs, tvecs, false, Calib3d.SOLVEPNP_IPPE, rvec, tvec, reprojectionError);
+         Mat truth_rvec = new Mat(3, 1, CvType.CV_64F);
+         truth_rvec.put(0, 0, 0, Math.PI / 2, 0);
+         Mat truth_tvec = new Mat(3, 1, CvType.CV_64F);
+         truth_tvec.put(0, 0, -320, -240, 400);
+         assertMatEqual(truth_rvec, rvecs.get(0), 10 * EPS);
+         assertMatEqual(truth_tvec, tvecs.get(0), 1000 * EPS);
+     }
++
 +    public void testGetDefaultNewCameraMatrixMat() {
 +        Mat mtx = Calib3d.getDefaultNewCameraMatrix(gray0);
 +
 +        assertFalse(mtx.empty());
 +        assertEquals(0, Core.countNonZero(mtx));
 +    }
 +
 +    public void testGetDefaultNewCameraMatrixMatSizeBoolean() {
 +        Mat mtx = Calib3d.getDefaultNewCameraMatrix(gray0, size, true);
 +
 +        assertFalse(mtx.empty());
 +        assertFalse(0 == Core.countNonZero(mtx));
 +        // TODO_: write better test
 +    }
 +
 +    public void testInitUndistortRectifyMap() {
 +        fail("Not yet implemented");
 +        Mat cameraMatrix = new Mat(3, 3, CvType.CV_32F);
 +        cameraMatrix.put(0, 0, 1, 0, 1);
 +        cameraMatrix.put(1, 0, 0, 1, 1);
 +        cameraMatrix.put(2, 0, 0, 0, 1);
 +
 +        Mat R = new Mat(3, 3, CvType.CV_32F, new Scalar(2));
 +        Mat newCameraMatrix = new Mat(3, 3, CvType.CV_32F, new Scalar(3));
 +
 +        Mat distCoeffs = new Mat();
 +        Mat map1 = new Mat();
 +        Mat map2 = new Mat();
 +
 +        // TODO: complete this test
 +        Calib3d.initUndistortRectifyMap(cameraMatrix, distCoeffs, R, newCameraMatrix, size, CvType.CV_32F, map1, map2);
 +    }
 +
 +    public void testInitWideAngleProjMapMatMatSizeIntIntMatMat() {
 +        fail("Not yet implemented");
 +        Mat cameraMatrix = new Mat(3, 3, CvType.CV_32F);
 +        Mat distCoeffs = new Mat(1, 4, CvType.CV_32F);
 +        // Size imageSize = new Size(2, 2);
 +
 +        cameraMatrix.put(0, 0, 1, 0, 1);
 +        cameraMatrix.put(1, 0, 0, 1, 2);
 +        cameraMatrix.put(2, 0, 0, 0, 1);
 +
 +        distCoeffs.put(0, 0, 1, 3, 2, 4);
 +        truth = new Mat(3, 3, CvType.CV_32F);
 +        truth.put(0, 0, 0, 0, 0);
 +        truth.put(1, 0, 0, 0, 0);
 +        truth.put(2, 0, 0, 3, 0);
 +        // TODO: No documentation for this function
 +        // Calib3d.initWideAngleProjMap(cameraMatrix, distCoeffs, imageSize,
 +        // 5, m1type, truthput1, truthput2);
 +    }
 +
 +    public void testInitWideAngleProjMapMatMatSizeIntIntMatMatInt() {
 +        fail("Not yet implemented");
 +    }
 +
 +    public void testInitWideAngleProjMapMatMatSizeIntIntMatMatIntDouble() {
 +        fail("Not yet implemented");
 +    }
 +
 +    public void testUndistortMatMatMatMat() {
 +        Mat src = new Mat(3, 3, CvType.CV_32F, new Scalar(3));
 +        Mat cameraMatrix = new Mat(3, 3, CvType.CV_32F) {
 +            {
 +                put(0, 0, 1, 0, 1);
 +                put(1, 0, 0, 1, 2);
 +                put(2, 0, 0, 0, 1);
 +            }
 +        };
 +        Mat distCoeffs = new Mat(1, 4, CvType.CV_32F) {
 +            {
 +                put(0, 0, 1, 3, 2, 4);
 +            }
 +        };
 +
 +        Calib3d.undistort(src, dst, cameraMatrix, distCoeffs);
 +
 +        truth = new Mat(3, 3, CvType.CV_32F) {
 +            {
 +                put(0, 0, 0, 0, 0);
 +                put(1, 0, 0, 0, 0);
 +                put(2, 0, 0, 3, 0);
 +            }
 +        };
 +        assertMatEqual(truth, dst, EPS);
 +    }
 +
 +    public void testUndistortMatMatMatMatMat() {
 +        Mat src = new Mat(3, 3, CvType.CV_32F, new Scalar(3));
 +        Mat cameraMatrix = new Mat(3, 3, CvType.CV_32F) {
 +            {
 +                put(0, 0, 1, 0, 1);
 +                put(1, 0, 0, 1, 2);
 +                put(2, 0, 0, 0, 1);
 +            }
 +        };
 +        Mat distCoeffs = new Mat(1, 4, CvType.CV_32F) {
 +            {
 +                put(0, 0, 2, 1, 4, 5);
 +            }
 +        };
 +        Mat newCameraMatrix = new Mat(3, 3, CvType.CV_32F, new Scalar(1));
 +
 +        Calib3d.undistort(src, dst, cameraMatrix, distCoeffs, newCameraMatrix);
 +
 +        truth = new Mat(3, 3, CvType.CV_32F, new Scalar(3));
 +        assertMatEqual(truth, dst, EPS);
 +    }
 +
 +    //undistortPoints(List<Point> src, List<Point> dst, Mat cameraMatrix, Mat distCoeffs)
 +    public void testUndistortPointsListOfPointListOfPointMatMat() {
 +        MatOfPoint2f src = new MatOfPoint2f(new Point(1, 2), new Point(3, 4), new Point(-1, -1));
 +        MatOfPoint2f dst = new MatOfPoint2f();
 +        Mat cameraMatrix = Mat.eye(3, 3, CvType.CV_64FC1);
 +        Mat distCoeffs = new Mat(8, 1, CvType.CV_64FC1, new Scalar(0));
 +
 +        Calib3d.undistortPoints(src, dst, cameraMatrix, distCoeffs);
 +
 +        assertEquals(src.size(), dst.size());
 +        for(int i=0; i<src.toList().size(); i++) {
 +            //Log.d("UndistortPoints", "s="+src.get(i)+", d="+dst.get(i));
 +            assertTrue(src.toList().get(i).equals(dst.toList().get(i)));
 +        }
 +    }
  }
Simple merge
Simple merge
@@@ -2006,8 -2146,9 +1904,8 @@@ TEST(Calib3d_ProjectPoints_CPP, outputS
      }
  }
  
 -TEST(Calib3d_StereoCalibrate_C, regression) { CV_StereoCalibrationTest_C test; test.safe_run(); }
  TEST(Calib3d_StereoCalibrate_CPP, regression) { CV_StereoCalibrationTest_CPP test; test.safe_run(); }
- TEST(Calib3d_StereoCalibrateCorner, regression) { CV_StereoCalibrationCornerTest test; test.safe_run(); }
  
  TEST(Calib3d_StereoCalibrate_CPP, extended)
  {
Simple merge
@@@ -1364,6 -1455,30 +1392,20 @@@ private
  #endif
  };
  
 -#ifdef CV_CXX11
+ template<> bool DisposedSingletonMark<TlsAbstraction>::mark = false;
+ static TlsAbstraction& getTlsAbstraction_()
+ {
+     static TlsAbstraction g_tls;  // disposed in atexit() handlers (required for unregistering our callbacks)
+     return g_tls;
+ }
+ static TlsAbstraction* getTlsAbstraction()
+ {
 -#else
 -    static TlsAbstraction* volatile instance = NULL;
 -    if (instance == NULL)
 -    {
 -        cv::AutoLock lock(cv::getInitializationMutex());
 -        if (instance == NULL)
 -            instance = &getTlsAbstraction_();
 -    }
 -#endif
+     static TlsAbstraction* instance = &getTlsAbstraction_();
+     return DisposedSingletonMark<TlsAbstraction>::isDisposed() ? NULL : instance;
+ }
  #ifdef _WIN32
  #ifdef WINRT
  static __declspec( thread ) void* tlsData = NULL; // using C++11 thread attribute for local thread data
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge