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;
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)));
+ }
+ }
}