mirror of
https://github.com/opencv/opencv.git
synced 2026-07-30 07:43:03 +04:00
Merge pull request #29175 from asmorkalov:as/geometry2
Geometry module #29175 OpenCV Contrib: https://github.com/opencv/opencv_contrib/pull/4129 CI changes: https://github.com/opencv/ci-gha-workflow/pull/313 Continues - https://github.com/opencv/opencv/pull/28804 - https://github.com/opencv/opencv/pull/29101 - https://github.com/opencv/opencv/pull/29108 - https://github.com/opencv/opencv/pull/28810 Todo for followup PRs: - [x] Rename doxygen groups - [x] Fix JS modules layout and whitelists - [ ] Sort tutorials code/snippets ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [ ] There is a reference to the original bug report and related work - [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [ ] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
committed by
GitHub
parent
14a475aa0b
commit
59218f9edd
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"namespaces_dict": {
|
||||
"cv.fisheye": "fisheye"
|
||||
},
|
||||
"func_arg_fix" : {
|
||||
"findFundamentalMat" : { "points1" : {"ctype" : "vector_Point2f"},
|
||||
"points2" : {"ctype" : "vector_Point2f"} },
|
||||
"findHomography" : { "srcPoints" : {"ctype" : "vector_Point2f"},
|
||||
"dstPoints" : {"ctype" : "vector_Point2f"} },
|
||||
"solvePnP" : { "objectPoints" : {"ctype" : "vector_Point3f"},
|
||||
"imagePoints" : {"ctype" : "vector_Point2f"},
|
||||
"distCoeffs" : {"ctype" : "vector_double" } },
|
||||
"solvePnPRansac" : { "objectPoints" : {"ctype" : "vector_Point3f"},
|
||||
"imagePoints" : {"ctype" : "vector_Point2f"},
|
||||
"distCoeffs" : {"ctype" : "vector_double" } },
|
||||
"undistortPoints" : { "src" : {"ctype" : "vector_Point2f"},
|
||||
"dst" : {"ctype" : "vector_Point2f"} },
|
||||
"projectPoints" : { "objectPoints" : {"ctype" : "vector_Point3f"},
|
||||
"imagePoints" : {"ctype" : "vector_Point2f"},
|
||||
"distCoeffs" : {"ctype" : "vector_double" } }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,744 @@
|
||||
package org.opencv.test.geometry;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.opencv.geometry.Geometry;
|
||||
import org.opencv.core.Core;
|
||||
import org.opencv.core.CvType;
|
||||
import org.opencv.core.Mat;
|
||||
import org.opencv.core.MatOfDouble;
|
||||
import org.opencv.core.MatOfPoint;
|
||||
import org.opencv.core.MatOfPoint2f;
|
||||
import org.opencv.core.MatOfPoint3f;
|
||||
import org.opencv.core.MatOfInt;
|
||||
import org.opencv.core.MatOfInt4;
|
||||
import org.opencv.core.Point;
|
||||
import org.opencv.core.Scalar;
|
||||
import org.opencv.core.Size;
|
||||
import org.opencv.core.RotatedRect;
|
||||
import org.opencv.test.OpenCVTestCase;
|
||||
import org.opencv.imgproc.Imgproc;
|
||||
|
||||
public class GeometryTest extends OpenCVTestCase {
|
||||
|
||||
Size size;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
size = new Size(3, 3);
|
||||
}
|
||||
|
||||
public void testComposeRTMatMatMatMatMatMat() {
|
||||
Mat rvec1 = new Mat(3, 1, CvType.CV_32F);
|
||||
rvec1.put(0, 0, 0.5302828, 0.19925919, 0.40105945);
|
||||
Mat tvec1 = new Mat(3, 1, CvType.CV_32F);
|
||||
tvec1.put(0, 0, 0.81438506, 0.43713298, 0.2487897);
|
||||
Mat rvec2 = new Mat(3, 1, CvType.CV_32F);
|
||||
rvec2.put(0, 0, 0.77310503, 0.76209372, 0.30779448);
|
||||
Mat tvec2 = new Mat(3, 1, CvType.CV_32F);
|
||||
tvec2.put(0, 0, 0.70243168, 0.4784472, 0.79219002);
|
||||
|
||||
Mat rvec3 = new Mat();
|
||||
Mat tvec3 = new Mat();
|
||||
|
||||
Mat outRvec = new Mat(3, 1, CvType.CV_32F);
|
||||
outRvec.put(0, 0, 1.418641, 0.88665926, 0.56020796);
|
||||
Mat outTvec = new Mat(3, 1, CvType.CV_32F);
|
||||
outTvec.put(0, 0, 1.4560841, 1.0680628, 0.81598103);
|
||||
|
||||
Geometry.composeRT(rvec1, tvec1, rvec2, tvec2, rvec3, tvec3);
|
||||
|
||||
assertMatEqual(outRvec, rvec3, EPS);
|
||||
assertMatEqual(outTvec, tvec3, EPS);
|
||||
}
|
||||
|
||||
public void testComposeRTMatMatMatMatMatMatMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testComposeRTMatMatMatMatMatMatMatMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testComposeRTMatMatMatMatMatMatMatMatMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testComposeRTMatMatMatMatMatMatMatMatMatMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testComposeRTMatMatMatMatMatMatMatMatMatMatMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testComposeRTMatMatMatMatMatMatMatMatMatMatMatMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testComposeRTMatMatMatMatMatMatMatMatMatMatMatMatMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testComposeRTMatMatMatMatMatMatMatMatMatMatMatMatMatMat() {
|
||||
fail("Not yet implemented");
|
||||
// Mat dr3dr1;
|
||||
// Mat dr3dt1;
|
||||
// Mat dr3dr2;
|
||||
// Mat dr3dt2;
|
||||
// Mat dt3dr1;
|
||||
// Mat dt3dt1;
|
||||
// Mat dt3dr2;
|
||||
// Mat dt3dt2;
|
||||
// , dr3dr1, dr3dt1, dr3dr2, dr3dt2, dt3dr1, dt3dt1, dt3dr2, dt3dt2);
|
||||
// [0.97031879, -0.091774099, 0.38594806;
|
||||
// 0.15181915, 0.98091727, -0.44186208;
|
||||
// -0.39509675, 0.43839464, 0.93872648]
|
||||
// [0, 0, 0;
|
||||
// 0, 0, 0;
|
||||
// 0, 0, 0]
|
||||
// [1.0117353, 0.16348237, -0.083180845;
|
||||
// -0.1980398, 1.006078, 0.30299222;
|
||||
// 0.075766489, -0.32784501, 1.0163091]
|
||||
// [0, 0, 0;
|
||||
// 0, 0, 0;
|
||||
// 0, 0, 0]
|
||||
// [0, 0, 0;
|
||||
// 0, 0, 0;
|
||||
// 0, 0, 0]
|
||||
// [0.69658804, 0.018115902, 0.7172426;
|
||||
// 0.51114357, 0.68899536, -0.51382649;
|
||||
// -0.50348526, 0.72453934, 0.47068608]
|
||||
// [0.18536358, -0.20515044, -0.48834875;
|
||||
// -0.25120571, 0.29043972, 0.60573936;
|
||||
// 0.35370794, -0.69923931, 0.45781645]
|
||||
// [1, 0, 0;
|
||||
// 0, 1, 0;
|
||||
// 0, 0, 1]
|
||||
}
|
||||
|
||||
public void testConvertPointsFromHomogeneous() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testConvertPointsToHomogeneous() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testDecomposeProjectionMatrixMatMatMatMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testDecomposeProjectionMatrixMatMatMatMatMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testDecomposeProjectionMatrixMatMatMatMatMatMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testDecomposeProjectionMatrixMatMatMatMatMatMatMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testDecomposeProjectionMatrixMatMatMatMatMatMatMatMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testEstimateAffine3DMatMatMatMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testEstimateAffine3DMatMatMatMatDouble() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testEstimateAffine3DMatMatMatMatDoubleDouble() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testFindFundamentalMatListOfPointListOfPointInt() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testFindFundamentalMatListOfPointListOfPointIntDouble() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testFindFundamentalMatListOfPointListOfPointIntDoubleDouble() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testFindFundamentalMatListOfPointListOfPointIntDoubleDoubleMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testFindHomographyListOfPointListOfPoint() {
|
||||
final int NUM = 20;
|
||||
|
||||
MatOfPoint2f originalPoints = new MatOfPoint2f();
|
||||
originalPoints.alloc(NUM);
|
||||
MatOfPoint2f transformedPoints = new MatOfPoint2f();
|
||||
transformedPoints.alloc(NUM);
|
||||
|
||||
for (int i = 0; i < NUM; i++) {
|
||||
double x = Math.random() * 100 - 50;
|
||||
double y = Math.random() * 100 - 50;
|
||||
originalPoints.put(i, 0, x, y);
|
||||
transformedPoints.put(i, 0, y, x);
|
||||
}
|
||||
|
||||
Mat hmg = Geometry.findHomography(originalPoints, transformedPoints);
|
||||
|
||||
truth = new Mat(3, 3, CvType.CV_64F);
|
||||
truth.put(0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1);
|
||||
|
||||
assertMatEqual(truth, hmg, EPS);
|
||||
}
|
||||
|
||||
public void testFindHomographyListOfPointListOfPointInt() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testFindHomographyListOfPointListOfPointIntDouble() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testFindHomographyListOfPointListOfPointIntDoubleMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testGetOptimalNewCameraMatrixMatMatSizeDouble() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testGetOptimalNewCameraMatrixMatMatSizeDoubleSize() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testGetOptimalNewCameraMatrixMatMatSizeDoubleSizeRect() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testGetOptimalNewCameraMatrixMatMatSizeDoubleSizeRectBoolean() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testGetValidDisparityROI() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testMatMulDeriv() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testProjectPointsMatMatMatMatMatMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testProjectPointsMatMatMatMatMatMatMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testProjectPointsMatMatMatMatMatMatMatDouble() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testRectify3Collinear() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testRodriguesMatMat() {
|
||||
Mat r = new Mat(3, 1, CvType.CV_32F);
|
||||
Mat R = new Mat(3, 3, CvType.CV_32F);
|
||||
|
||||
r.put(0, 0, Math.PI, 0, 0);
|
||||
|
||||
Geometry.Rodrigues(r, R);
|
||||
|
||||
truth = new Mat(3, 3, CvType.CV_32F);
|
||||
truth.put(0, 0, 1, 0, 0, 0, -1, 0, 0, 0, -1);
|
||||
assertMatEqual(truth, R, EPS);
|
||||
|
||||
Mat r2 = new Mat();
|
||||
Geometry.Rodrigues(R, r2);
|
||||
|
||||
assertMatEqual(r, r2, EPS);
|
||||
}
|
||||
|
||||
public void testRodriguesMatMatMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testRQDecomp3x3MatMatMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testRQDecomp3x3MatMatMatMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testRQDecomp3x3MatMatMatMatMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testRQDecomp3x3MatMatMatMatMatMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testSolvePnPListOfPoint3ListOfPointMatMatMatMat() {
|
||||
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));
|
||||
}
|
||||
|
||||
Mat rvec = new Mat();
|
||||
Mat tvec = new Mat();
|
||||
Geometry.solvePnP(points3d, points2d, intrinsics, new MatOfDouble(), rvec, tvec);
|
||||
|
||||
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, rvec, EPS*2);
|
||||
assertMatEqual(truth_tvec, tvec, EPS*2);
|
||||
}
|
||||
|
||||
public void testSolvePnPListOfPoint3ListOfPointMatMatMatMatBoolean() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testSolvePnPRansacListOfPoint3ListOfPointMatMatMatMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testSolvePnPRansacListOfPoint3ListOfPointMatMatMatMatBoolean() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testSolvePnPRansacListOfPoint3ListOfPointMatMatMatMatBooleanInt() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testSolvePnPRansacListOfPoint3ListOfPointMatMatMatMatBooleanIntFloat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testSolvePnPRansacListOfPoint3ListOfPointMatMatMatMatBooleanIntFloatInt() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testSolvePnPRansacListOfPoint3ListOfPointMatMatMatMatBooleanIntFloatIntMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testStereoCalibrateListOfMatListOfMatListOfMatMatMatMatMatSizeMatMatMatMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testStereoCalibrateListOfMatListOfMatListOfMatMatMatMatMatSizeMatMatMatMatTermCriteria() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testStereoCalibrateListOfMatListOfMatListOfMatMatMatMatMatSizeMatMatMatMatTermCriteriaInt() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testStereoRectifyUncalibratedMatMatMatSizeMatMat() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testStereoRectifyUncalibratedMatMatMatSizeMatMatDouble() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testValidateDisparityMatMatIntInt() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testValidateDisparityMatMatIntIntInt() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testComputeCorrespondEpilines()
|
||||
{
|
||||
Mat fundamental = new Mat(3, 3, CvType.CV_64F);
|
||||
fundamental.put(0, 0, 0, -0.577, 0.288, 0.577, 0, 0.288, -0.288, -0.288, 0);
|
||||
MatOfPoint2f left = new MatOfPoint2f();
|
||||
left.alloc(1);
|
||||
left.put(0, 0, 2, 3); //add(new Point(x, y));
|
||||
Mat lines = new Mat();
|
||||
Mat truth = new Mat(1, 1, CvType.CV_32FC3);
|
||||
truth.put(0, 0, -0.70735186, 0.70686162, -0.70588124);
|
||||
Geometry.computeCorrespondEpilines(left, 1, fundamental, lines);
|
||||
assertMatEqual(truth, lines, EPS);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
Geometry.solvePnPGeneric(points3d, points2d, intrinsics, new MatOfDouble(), rvecs, tvecs, false, Geometry.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 = Geometry.getDefaultNewCameraMatrix(gray0);
|
||||
|
||||
assertFalse(mtx.empty());
|
||||
assertEquals(0, Core.countNonZero(mtx));
|
||||
}
|
||||
|
||||
public void testGetDefaultNewCameraMatrixMatSizeBoolean() {
|
||||
Mat mtx = Geometry.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
|
||||
Geometry.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
|
||||
// Geometry.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);
|
||||
}
|
||||
};
|
||||
|
||||
Geometry.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));
|
||||
|
||||
Geometry.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));
|
||||
|
||||
Geometry.undistortPoints(src, dst, cameraMatrix, distCoeffs);
|
||||
|
||||
assertEquals(src.cols(), dst.rows());
|
||||
assertEquals(src.rows(), dst.cols());
|
||||
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)));
|
||||
}
|
||||
}
|
||||
|
||||
public void testEstimateNewCameraMatrixForUndistortRectify() {
|
||||
Mat K = new Mat().eye(3, 3, CvType.CV_64FC1);
|
||||
Mat K_new = new Mat().eye(3, 3, CvType.CV_64FC1);
|
||||
Mat K_new_truth = new Mat().eye(3, 3, CvType.CV_64FC1);
|
||||
Mat D = new Mat().zeros(4, 1, CvType.CV_64FC1);
|
||||
|
||||
K.put(0,0,600.4447738238429);
|
||||
K.put(1,1,578.9929805505851);
|
||||
K.put(0,2,992.0642578801213);
|
||||
K.put(1,2,549.2682624212172);
|
||||
|
||||
D.put(0,0,-0.05090103223466704);
|
||||
D.put(1,0,0.030944413642173308);
|
||||
D.put(2,0,-0.021509225493198905);
|
||||
D.put(3,0,0.0043378096628297145);
|
||||
|
||||
K_new_truth.put(0,0, 387.5118215642316);
|
||||
K_new_truth.put(0,2, 1033.936556777084);
|
||||
K_new_truth.put(1,1, 373.6673784974842);
|
||||
K_new_truth.put(1,2, 538.794152656429);
|
||||
|
||||
Geometry.fisheye_estimateNewCameraMatrixForUndistortRectify(K,D,new Size(1920,1080),
|
||||
new Mat().eye(3, 3, CvType.CV_64F), K_new, 0.0, new Size(1920,1080));
|
||||
|
||||
assertMatEqual(K_new, K_new_truth, EPS);
|
||||
}
|
||||
|
||||
public void testApproxPolyDP() {
|
||||
MatOfPoint2f curve = new MatOfPoint2f(new Point(1, 3), new Point(2, 4), new Point(3, 5), new Point(4, 4), new Point(5, 3));
|
||||
|
||||
MatOfPoint2f approxCurve = new MatOfPoint2f();
|
||||
|
||||
Geometry.approxPolyDP(curve, approxCurve, EPS, true);
|
||||
|
||||
List<Point> approxCurveGold = new ArrayList<Point>(3);
|
||||
approxCurveGold.add(new Point(1, 3));
|
||||
approxCurveGold.add(new Point(3, 5));
|
||||
approxCurveGold.add(new Point(5, 3));
|
||||
|
||||
assertListPointEquals(approxCurve.toList(), approxCurveGold, EPS);
|
||||
}
|
||||
|
||||
public void testConvexHullMatMat() {
|
||||
MatOfPoint points = new MatOfPoint(
|
||||
new Point(20, 0),
|
||||
new Point(40, 0),
|
||||
new Point(30, 20),
|
||||
new Point(0, 20),
|
||||
new Point(20, 10),
|
||||
new Point(30, 10)
|
||||
);
|
||||
|
||||
MatOfInt hull = new MatOfInt();
|
||||
|
||||
Geometry.convexHull(points, hull);
|
||||
|
||||
MatOfInt expHull = new MatOfInt(
|
||||
0, 1, 2, 3
|
||||
);
|
||||
assertMatEqual(expHull, hull.reshape(1, (int)hull.total()), EPS);
|
||||
}
|
||||
|
||||
public void testConvexHullMatMatBooleanBoolean() {
|
||||
MatOfPoint points = new MatOfPoint(
|
||||
new Point(2, 0),
|
||||
new Point(4, 0),
|
||||
new Point(3, 2),
|
||||
new Point(0, 2),
|
||||
new Point(2, 1),
|
||||
new Point(3, 1)
|
||||
);
|
||||
|
||||
MatOfInt hull = new MatOfInt();
|
||||
|
||||
Geometry.convexHull(points, hull, true);
|
||||
|
||||
MatOfInt expHull = new MatOfInt(
|
||||
3, 2, 1, 0
|
||||
);
|
||||
assertMatEqual(expHull, hull.reshape(1, hull.cols()), EPS);
|
||||
}
|
||||
|
||||
public void testConvexityDefects() {
|
||||
MatOfPoint points = new MatOfPoint(
|
||||
new Point(20, 0),
|
||||
new Point(40, 0),
|
||||
new Point(30, 20),
|
||||
new Point(0, 20),
|
||||
new Point(20, 10),
|
||||
new Point(30, 10)
|
||||
);
|
||||
|
||||
MatOfInt hull = new MatOfInt();
|
||||
Geometry.convexHull(points, hull);
|
||||
|
||||
MatOfInt4 convexityDefects = new MatOfInt4();
|
||||
Geometry.convexityDefects(points, hull, convexityDefects);
|
||||
|
||||
assertMatEqual(new MatOfInt4(3, 0, 5, 3620), convexityDefects.reshape(4, convexityDefects.cols()));
|
||||
}
|
||||
|
||||
public void testFitEllipse() {
|
||||
MatOfPoint2f points = new MatOfPoint2f(new Point(0, 0), new Point(-1, 1), new Point(1, 1), new Point(1, -1), new Point(-1, -1));
|
||||
RotatedRect rrect = new RotatedRect();
|
||||
|
||||
rrect = Geometry.fitEllipse(points);
|
||||
|
||||
double FIT_ELLIPSE_CENTER_EPS = 0.01;
|
||||
double FIT_ELLIPSE_SIZE_EPS = 0.4;
|
||||
|
||||
assertEquals(0.0, rrect.center.x, FIT_ELLIPSE_CENTER_EPS);
|
||||
assertEquals(0.0, rrect.center.y, FIT_ELLIPSE_CENTER_EPS);
|
||||
assertEquals(2.828, rrect.size.width, FIT_ELLIPSE_SIZE_EPS);
|
||||
assertEquals(2.828, rrect.size.height, FIT_ELLIPSE_SIZE_EPS);
|
||||
}
|
||||
|
||||
public void testFitLine() {
|
||||
Mat points = new Mat(1, 4, CvType.CV_32FC2);
|
||||
points.put(0, 0, 0, 0, 2, 3, 3, 4, 5, 8);
|
||||
|
||||
Mat linePoints = new Mat(4, 1, CvType.CV_32FC1);
|
||||
linePoints.put(0, 0, 0.53198653, 0.84675282, 2.5, 3.75);
|
||||
|
||||
Geometry.fitLine(points, dst, Imgproc.DIST_L12, 0, 0.01, 0.01);
|
||||
|
||||
assertMatEqual(linePoints, dst, EPS);
|
||||
}
|
||||
|
||||
public void testIsContourConvex() {
|
||||
MatOfPoint contour1 = new MatOfPoint(new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(5, 4));
|
||||
|
||||
assertFalse(Geometry.isContourConvex(contour1));
|
||||
|
||||
MatOfPoint contour2 = new MatOfPoint(new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(5, 6));
|
||||
|
||||
assertTrue(Geometry.isContourConvex(contour2));
|
||||
}
|
||||
|
||||
public void testMatchShapes() {
|
||||
Mat contour1 = new Mat(1, 4, CvType.CV_32FC2);
|
||||
Mat contour2 = new Mat(1, 4, CvType.CV_32FC2);
|
||||
contour1.put(0, 0, 1, 1, 5, 1, 4, 3, 6, 2);
|
||||
contour2.put(0, 0, 1, 1, 6, 1, 4, 1, 2, 5);
|
||||
|
||||
double distance = Geometry.matchShapes(contour1, contour2, Imgproc.CONTOURS_MATCH_I1, 1);
|
||||
|
||||
assertEquals(2.81109697365334, distance, EPS);
|
||||
}
|
||||
|
||||
public void testMinAreaRect() {
|
||||
MatOfPoint2f points = new MatOfPoint2f(new Point(1, 1), new Point(5, 1), new Point(4, 3), new Point(6, 2));
|
||||
|
||||
RotatedRect rrect = Geometry.minAreaRect(points);
|
||||
|
||||
assertEquals(new Size(2, 5), rrect.size);
|
||||
assertEquals(-90., rrect.angle);
|
||||
assertEquals(new Point(3.5, 2), rrect.center);
|
||||
}
|
||||
|
||||
public void testMinEnclosingCircle() {
|
||||
MatOfPoint2f points = new MatOfPoint2f(new Point(0, 0), new Point(-100, 0), new Point(0, -100), new Point(100, 0), new Point(0, 100));
|
||||
Point actualCenter = new Point();
|
||||
float[] radius = new float[1];
|
||||
|
||||
Geometry.minEnclosingCircle(points, actualCenter, radius);
|
||||
|
||||
assertEquals(new Point(0, 0), actualCenter);
|
||||
assertEquals(100.0f, radius[0], 1.0);
|
||||
}
|
||||
|
||||
public void testPointPolygonTest() {
|
||||
MatOfPoint2f contour = new MatOfPoint2f(new Point(0, 0), new Point(1, 3), new Point(3, 4), new Point(4, 3), new Point(2, 1));
|
||||
double sign1 = Geometry.pointPolygonTest(contour, new Point(2, 2), false);
|
||||
assertEquals(1.0, sign1);
|
||||
|
||||
double sign2 = Geometry.pointPolygonTest(contour, new Point(4, 4), true);
|
||||
assertEquals(-Math.sqrt(0.5), sign2);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
package org.opencv.test.geometry;
|
||||
|
||||
import org.opencv.core.MatOfFloat6;
|
||||
import org.opencv.core.Point;
|
||||
import org.opencv.core.Rect;
|
||||
import org.opencv.geometry.Subdiv2D;
|
||||
import org.opencv.test.OpenCVTestCase;
|
||||
|
||||
public class Subdiv2DTest extends OpenCVTestCase {
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
public void testEdgeDstInt() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testEdgeDstIntPoint() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testEdgeOrgInt() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testEdgeOrgIntPoint() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testFindNearestPoint() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testFindNearestPointPoint() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testGetEdge() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testGetEdgeList() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testGetTriangleList() {
|
||||
Subdiv2D s2d = new Subdiv2D( new Rect(0, 0, 50, 50) );
|
||||
s2d.insert( new Point(10, 10) );
|
||||
s2d.insert( new Point(20, 10) );
|
||||
s2d.insert( new Point(20, 20) );
|
||||
s2d.insert( new Point(10, 20) );
|
||||
MatOfFloat6 triangles = new MatOfFloat6();
|
||||
s2d.getTriangleList(triangles);
|
||||
assertEquals(2, triangles.cols());
|
||||
/*
|
||||
int cnt = triangles.rows();
|
||||
float buff[] = new float[cnt*6];
|
||||
triangles.get(0, 0, buff);
|
||||
for(int i=0; i<cnt; i++)
|
||||
Log.d("*****", "["+i+"]: " + // (a.x, a.y) -> (b.x, b.y) -> (c.x, c.y)
|
||||
"("+buff[6*i+0]+","+buff[6*i+1]+")" + "->" +
|
||||
"("+buff[6*i+2]+","+buff[6*i+3]+")" + "->" +
|
||||
"("+buff[6*i+4]+","+buff[6*i+5]+")"
|
||||
);
|
||||
*/
|
||||
}
|
||||
|
||||
public void testGetVertexInt() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testGetVertexIntIntArray() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testGetVoronoiFacetList() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testInitDelaunay() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testInsertListOfPoint() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testInsertPoint() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testLocate() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testNextEdge() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testRotateEdge() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testSubdiv2D() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testSubdiv2DRect() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
public void testSymEdge() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"whitelist":
|
||||
{
|
||||
"": [
|
||||
"findHomography",
|
||||
"drawFrameAxes",
|
||||
"estimateAffine2D",
|
||||
"getDefaultNewCameraMatrix",
|
||||
"initUndistortRectifyMap",
|
||||
"Rodrigues",
|
||||
"solvePnP",
|
||||
"solvePnPRansac",
|
||||
"solvePnPRefineLM",
|
||||
"projectPoints",
|
||||
"undistort",
|
||||
"fisheye_initUndistortRectifyMap",
|
||||
"fisheye_projectPoints",
|
||||
"approxPolyDP",
|
||||
"approxPolyN",
|
||||
"boundingRect",
|
||||
"minAreaRect",
|
||||
"minEnclosingCircle",
|
||||
"minEnclosingTriangle",
|
||||
"matchShapes",
|
||||
"convexHull",
|
||||
"convexityDefects",
|
||||
"isContourConvex",
|
||||
"intersectConvexConvex",
|
||||
"fitEllipse",
|
||||
"fitEllipseAMS",
|
||||
"fitEllipseDirect",
|
||||
"fitLine",
|
||||
"pointPolygonTest"
|
||||
],
|
||||
"UsacParams": ["UsacParams"]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"namespaces_dict": {
|
||||
"cv.fisheye": "fisheye"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,240 @@
|
||||
//
|
||||
// Calib3dTest.swift
|
||||
//
|
||||
// Created by Giles Payne on 2020/05/26.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
import OpenCV
|
||||
|
||||
class Cv3dTest: OpenCVTestCase {
|
||||
|
||||
var size = Size()
|
||||
|
||||
override func setUp() {
|
||||
super.setUp()
|
||||
size = Size(width: 3, height: 3)
|
||||
}
|
||||
|
||||
override func tearDown() {
|
||||
super.tearDown()
|
||||
}
|
||||
|
||||
func testComposeRTMatMatMatMatMatMat() throws {
|
||||
let rvec1 = Mat(rows: 3, cols: 1, type: CvType.CV_32F)
|
||||
try rvec1.put(row: 0, col: 0, data: [0.5302828, 0.19925919, 0.40105945] as [Float])
|
||||
let tvec1 = Mat(rows: 3, cols: 1, type: CvType.CV_32F)
|
||||
try tvec1.put(row: 0, col: 0, data: [0.81438506, 0.43713298, 0.2487897] as [Float])
|
||||
let rvec2 = Mat(rows: 3, cols: 1, type: CvType.CV_32F)
|
||||
try rvec2.put(row: 0, col: 0, data: [0.77310503, 0.76209372, 0.30779448] as [Float])
|
||||
let tvec2 = Mat(rows: 3, cols: 1, type: CvType.CV_32F)
|
||||
try tvec2.put(row: 0, col: 0, data: [0.70243168, 0.4784472, 0.79219002] as [Float])
|
||||
|
||||
let rvec3 = Mat()
|
||||
let tvec3 = Mat()
|
||||
|
||||
let outRvec = Mat(rows: 3, cols: 1, type: CvType.CV_32F)
|
||||
try outRvec.put(row: 0, col: 0, data: [1.418641, 0.88665926, 0.56020796])
|
||||
let outTvec = Mat(rows: 3, cols: 1, type: CvType.CV_32F)
|
||||
try outTvec.put(row: 0, col: 0, data: [1.4560841, 1.0680628, 0.81598103])
|
||||
|
||||
Cv3d.composeRT(rvec1: rvec1, tvec1: tvec1, rvec2: rvec2, tvec2: tvec2, rvec3: rvec3, tvec3: tvec3)
|
||||
|
||||
try assertMatEqual(outRvec, rvec3, OpenCVTestCase.EPS)
|
||||
try assertMatEqual(outTvec, tvec3, OpenCVTestCase.EPS)
|
||||
}
|
||||
|
||||
func testFindHomographyListOfPointListOfPoint() throws {
|
||||
let NUM:Int32 = 20
|
||||
|
||||
let originalPoints = MatOfPoint2f()
|
||||
originalPoints.alloc(NUM)
|
||||
let transformedPoints = MatOfPoint2f()
|
||||
transformedPoints.alloc(NUM)
|
||||
|
||||
for i:Int32 in 0..<NUM {
|
||||
let x:Float = Float.random(in: -50...50)
|
||||
let y:Float = Float.random(in: -50...50)
|
||||
try originalPoints.put(row:i, col:0, data:[x, y])
|
||||
try transformedPoints.put(row:i, col:0, data:[y, x])
|
||||
}
|
||||
|
||||
let hmg = Cv3d.findHomography(srcPoints: originalPoints, dstPoints: transformedPoints)
|
||||
|
||||
truth = Mat(rows: 3, cols: 3, type: CvType.CV_64F)
|
||||
try truth!.put(row:0, col:0, data:[0, 1, 0, 1, 0, 0, 0, 0, 1] as [Double])
|
||||
try assertMatEqual(truth!, hmg, OpenCVTestCase.EPS)
|
||||
}
|
||||
|
||||
func testRodriguesMatMat() throws {
|
||||
let r = Mat(rows: 3, cols: 1, type: CvType.CV_32F)
|
||||
let R = Mat(rows: 3, cols: 3, type: CvType.CV_32F)
|
||||
|
||||
try r.put(row:0, col:0, data:[.pi, 0, 0] as [Float])
|
||||
|
||||
Cv3d.Rodrigues(src: r, dst: R)
|
||||
|
||||
truth = Mat(rows: 3, cols: 3, type: CvType.CV_32F)
|
||||
try truth!.put(row:0, col:0, data:[1, 0, 0, 0, -1, 0, 0, 0, -1] as [Float])
|
||||
try assertMatEqual(truth!, R, OpenCVTestCase.EPS)
|
||||
|
||||
let r2 = Mat()
|
||||
Cv3d.Rodrigues(src: R, dst: r2)
|
||||
|
||||
try assertMatEqual(r, r2, OpenCVTestCase.EPS)
|
||||
}
|
||||
|
||||
func testSolvePnPListOfPoint3ListOfPointMatMatMatMat() throws {
|
||||
let intrinsics = Mat.eye(rows: 3, cols: 3, type: CvType.CV_64F)
|
||||
try intrinsics.put(row: 0, col: 0, data: [400] as [Double])
|
||||
try intrinsics.put(row: 1, col: 1, data: [400] as [Double])
|
||||
try intrinsics.put(row: 0, col: 2, data: [640 / 2] as [Double])
|
||||
try intrinsics.put(row: 1, col: 2, data: [480 / 2] as [Double])
|
||||
|
||||
let minPnpPointsNum: Int32 = 4
|
||||
|
||||
let points3d = MatOfPoint3f()
|
||||
points3d.alloc(minPnpPointsNum)
|
||||
let points2d = MatOfPoint2f()
|
||||
points2d.alloc(minPnpPointsNum)
|
||||
|
||||
for i in 0..<minPnpPointsNum {
|
||||
let x = Float.random(in: -50...50)
|
||||
let y = Float.random(in: -50...50)
|
||||
try points2d.put(row: i, col: 0, data: [x, y]) //add(Point(x, y))
|
||||
try points3d.put(row: i, col: 0, data: [0, y, x]) // add(Point3(0, y, x))
|
||||
}
|
||||
|
||||
let rvec = Mat()
|
||||
let tvec = Mat()
|
||||
Cv3d.solvePnP(objectPoints: points3d, imagePoints: points2d, cameraMatrix: intrinsics, distCoeffs: MatOfDouble(), rvec: rvec, tvec: tvec)
|
||||
|
||||
let truth_rvec = Mat(rows: 3, cols: 1, type: CvType.CV_64F)
|
||||
try truth_rvec.put(row: 0, col: 0, data: [0, .pi / 2, 0] as [Double])
|
||||
|
||||
let truth_tvec = Mat(rows: 3, cols: 1, type: CvType.CV_64F)
|
||||
try truth_tvec.put(row: 0, col: 0, data: [-320, -240, 400] as [Double])
|
||||
|
||||
try assertMatEqual(truth_rvec, rvec, OpenCVTestCase.EPS)
|
||||
try assertMatEqual(truth_tvec, tvec, OpenCVTestCase.EPS)
|
||||
}
|
||||
|
||||
func testComputeCorrespondEpilines() throws {
|
||||
let fundamental = Mat(rows: 3, cols: 3, type: CvType.CV_64F)
|
||||
try fundamental.put(row: 0, col: 0, data: [0, -0.577, 0.288, 0.577, 0, 0.288, -0.288, -0.288, 0])
|
||||
let left = MatOfPoint2f()
|
||||
left.alloc(1)
|
||||
try left.put(row: 0, col: 0, data: [2, 3] as [Float]) //add(Point(x, y))
|
||||
let lines = Mat()
|
||||
let truth = Mat(rows: 1, cols: 1, type: CvType.CV_32FC3)
|
||||
try truth.put(row: 0, col: 0, data: [-0.70735186, 0.70686162, -0.70588124])
|
||||
Cv3d.computeCorrespondEpilines(points: left, whichImage: 1, F: fundamental, lines: lines)
|
||||
try assertMatEqual(truth, lines, OpenCVTestCase.EPS)
|
||||
}
|
||||
|
||||
func testSolvePnPGeneric_regression_16040() throws {
|
||||
let intrinsics = Mat.eye(rows: 3, cols: 3, type: CvType.CV_64F)
|
||||
try intrinsics.put(row: 0, col: 0, data: [400] as [Double])
|
||||
try intrinsics.put(row: 1, col: 1, data: [400] as [Double])
|
||||
try intrinsics.put(row: 0, col: 2, data: [640 / 2] as [Double])
|
||||
try intrinsics.put(row: 1, col: 2, data: [480 / 2] as [Double])
|
||||
|
||||
let minPnpPointsNum: Int32 = 4
|
||||
|
||||
let points3d = MatOfPoint3f()
|
||||
points3d.alloc(minPnpPointsNum)
|
||||
let points2d = MatOfPoint2f()
|
||||
points2d.alloc(minPnpPointsNum)
|
||||
|
||||
for i in 0..<minPnpPointsNum {
|
||||
let x = Float.random(in: -50...50)
|
||||
let y = Float.random(in: -50...50)
|
||||
try points2d.put(row: i, col: 0, data: [x, y]) //add(Point(x, y))
|
||||
try points3d.put(row: i, col: 0, data: [0, y, x]) // add(Point3(0, y, x))
|
||||
}
|
||||
|
||||
var rvecs = [Mat]()
|
||||
var tvecs = [Mat]()
|
||||
|
||||
let rvec = Mat()
|
||||
let tvec = Mat()
|
||||
|
||||
let reprojectionError = Mat(rows: 2, cols: 1, type: CvType.CV_64FC1)
|
||||
|
||||
Cv3d.solvePnPGeneric(objectPoints: points3d, imagePoints: points2d, cameraMatrix: intrinsics, distCoeffs: MatOfDouble(), rvecs: &rvecs, tvecs: &tvecs, useExtrinsicGuess: false, flags: .SOLVEPNP_IPPE, rvec: rvec, tvec: tvec, reprojectionError: reprojectionError)
|
||||
|
||||
let truth_rvec = Mat(rows: 3, cols: 1, type: CvType.CV_64F)
|
||||
try truth_rvec.put(row: 0, col: 0, data: [0, .pi / 2, 0] as [Double])
|
||||
|
||||
let truth_tvec = Mat(rows: 3, cols: 1, type: CvType.CV_64F)
|
||||
try truth_tvec.put(row: 0, col: 0, data: [-320, -240, 400] as [Double])
|
||||
|
||||
try assertMatEqual(truth_rvec, rvecs[0], 10 * OpenCVTestCase.EPS)
|
||||
try assertMatEqual(truth_tvec, tvecs[0], 1000 * OpenCVTestCase.EPS)
|
||||
}
|
||||
|
||||
func testGetDefaultNewCameraMatrixMat() {
|
||||
let mtx = Cv3d.getDefaultNewCameraMatrix(cameraMatrix: gray0)
|
||||
|
||||
XCTAssertFalse(mtx.empty())
|
||||
XCTAssertEqual(0, Core.countNonZero(src: mtx))
|
||||
}
|
||||
|
||||
func testGetDefaultNewCameraMatrixMatSizeBoolean() {
|
||||
let mtx = Cv3d.getDefaultNewCameraMatrix(cameraMatrix: gray0, imgsize: size, centerPrincipalPoint: true)
|
||||
|
||||
XCTAssertFalse(mtx.empty())
|
||||
XCTAssertFalse(0 == Core.countNonZero(src: mtx))
|
||||
// TODO_: write better test
|
||||
}
|
||||
|
||||
func testUndistortMatMatMatMat() throws {
|
||||
let src = Mat(rows: 3, cols: 3, type: CvType.CV_32F, scalar: Scalar(3))
|
||||
let cameraMatrix = Mat(rows: 3, cols: 3, type: CvType.CV_32F)
|
||||
try cameraMatrix.put(row: 0, col: 0, data: [1, 0, 1] as [Float])
|
||||
try cameraMatrix.put(row: 1, col: 0, data: [0, 1, 2] as [Float])
|
||||
try cameraMatrix.put(row: 2, col: 0, data: [0, 0, 1] as [Float])
|
||||
|
||||
let distCoeffs = Mat(rows: 1, cols: 4, type: CvType.CV_32F)
|
||||
try distCoeffs.put(row: 0, col: 0, data: [1, 3, 2, 4] as [Float])
|
||||
|
||||
Cv3d.undistort(src: src, dst: dst, cameraMatrix: cameraMatrix, distCoeffs: distCoeffs)
|
||||
|
||||
truth = Mat(rows: 3, cols: 3, type: CvType.CV_32F)
|
||||
try truth!.put(row: 0, col: 0, data: [0, 0, 0] as [Float])
|
||||
try truth!.put(row: 1, col: 0, data: [0, 0, 0] as [Float])
|
||||
try truth!.put(row: 2, col: 0, data: [0, 3, 0] as [Float])
|
||||
|
||||
try assertMatEqual(truth!, dst, OpenCVTestCase.EPS)
|
||||
}
|
||||
|
||||
func testUndistortMatMatMatMatMat() throws {
|
||||
let src = Mat(rows: 3, cols: 3, type: CvType.CV_32F, scalar: Scalar(3))
|
||||
let cameraMatrix = Mat(rows: 3, cols: 3, type: CvType.CV_32F)
|
||||
try cameraMatrix.put(row: 0, col: 0, data: [1, 0, 1] as [Float])
|
||||
try cameraMatrix.put(row: 1, col: 0, data: [0, 1, 2] as [Float])
|
||||
try cameraMatrix.put(row: 2, col: 0, data: [0, 0, 1] as [Float])
|
||||
|
||||
let distCoeffs = Mat(rows: 1, cols: 4, type: CvType.CV_32F)
|
||||
try distCoeffs.put(row: 0, col: 0, data: [2, 1, 4, 5] as [Float])
|
||||
|
||||
let newCameraMatrix = Mat(rows: 3, cols: 3, type: CvType.CV_32F, scalar: Scalar(1))
|
||||
|
||||
Cv3d.undistort(src: src, dst: dst, cameraMatrix: cameraMatrix, distCoeffs: distCoeffs, newCameraMatrix: newCameraMatrix)
|
||||
|
||||
truth = Mat(rows: 3, cols: 3, type: CvType.CV_32F, scalar: Scalar(3))
|
||||
try assertMatEqual(truth!, dst, OpenCVTestCase.EPS)
|
||||
}
|
||||
|
||||
//undistortPoints(List<Point> src, List<Point> dst, Mat cameraMatrix, Mat distCoeffs)
|
||||
func testUndistortPointsListOfPointListOfPointMatMat() {
|
||||
let src = MatOfPoint2f(array: [Point2f(x: 1, y: 2), Point2f(x: 3, y: 4), Point2f(x: -1, y: -1)])
|
||||
let dst = MatOfPoint2f()
|
||||
let cameraMatrix = Mat.eye(rows: 3, cols: 3, type: CvType.CV_64FC1)
|
||||
let distCoeffs = Mat(rows: 8, cols: 1, type: CvType.CV_64FC1, scalar: Scalar(0))
|
||||
|
||||
Cv3d.undistortPoints(src: src, dst: dst, cameraMatrix: cameraMatrix, distCoeffs: distCoeffs)
|
||||
|
||||
XCTAssertEqual(src.toArray(), dst.toArray())
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
//
|
||||
// Subdiv2DTest.swift
|
||||
//
|
||||
// Created by Giles Payne on 2020/02/10.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
import OpenCV
|
||||
|
||||
class Subdiv2DTest: OpenCVTestCase {
|
||||
|
||||
func testGetTriangleList() {
|
||||
let s2d = Subdiv2D(rect: Rect(x: 0, y: 0, width: 50, height: 50))
|
||||
s2d.insert(pt: Point2f(x: 10, y: 10))
|
||||
s2d.insert(pt: Point2f(x: 20, y: 10))
|
||||
s2d.insert(pt: Point2f(x: 20, y: 20))
|
||||
s2d.insert(pt: Point2f(x: 10, y: 20))
|
||||
var triangles = [Float6]()
|
||||
s2d.getTriangleList(triangleList: &triangles)
|
||||
XCTAssertEqual(2, triangles.count)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Python 2/3 compatibility
|
||||
from __future__ import print_function
|
||||
|
||||
import os, numpy
|
||||
import math
|
||||
import unittest
|
||||
import cv2 as cv
|
||||
|
||||
from tests_common import NewOpenCVTests
|
||||
|
||||
class raster_test(NewOpenCVTests):
|
||||
|
||||
def test_loadCloud(self):
|
||||
fin = self.find_file("pointcloudio/orig.obj")
|
||||
points, normals, colors = cv.loadPointCloud(fin)
|
||||
|
||||
if points.shape != (8, 1, 3):
|
||||
self.fail('point array should be 8x1x3')
|
||||
if normals.shape != (6, 1, 3):
|
||||
self.fail('normals array should be 6x1x3')
|
||||
if colors.shape != (8, 1, 3):
|
||||
self.fail('colors array should be 8x1x3')
|
||||
|
||||
def test_loadMesh(self):
|
||||
fin = self.find_file("pointcloudio/orig.obj")
|
||||
points, indices, normals, colors, texCoords = cv.loadMesh(fin)
|
||||
goodShapes = [(1, 18, 3), (18, 1, 3)]
|
||||
errorMsg = "%s array should be 18x1x3 or 1x18x3"
|
||||
for a, s in [(points, 'points'), (normals, 'normals'), (colors, 'colors')]:
|
||||
if a.shape not in goodShapes:
|
||||
self.fail(errorMsg % s)
|
||||
|
||||
if texCoords.shape not in [(1, 18, 2), (18, 1, 2), (18, 2)]:
|
||||
self.fail('texture coordinates array should be 1x18x2 or 18x1x2')
|
||||
if isinstance(indices, numpy.ndarray):
|
||||
if indices.shape not in [(1, 6, 3), (6, 1, 3)]:
|
||||
self.fail('indices array should be 1x6x3 or 6x1x3')
|
||||
elif isinstance(indices, list) or isinstance(indices, tuple):
|
||||
for i in indices:
|
||||
if len(indices) != 6 or i.shape != (1, 3):
|
||||
self.fail('indices array should be 1x6x3 or 6x1x3')
|
||||
|
||||
if __name__ == '__main__':
|
||||
NewOpenCVTests.bootstrap()
|
||||
@@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import os
|
||||
import numpy as np
|
||||
import math
|
||||
import unittest
|
||||
import cv2 as cv
|
||||
|
||||
from tests_common import NewOpenCVTests
|
||||
|
||||
class octree_test(NewOpenCVTests):
|
||||
def test_octree_basic_test(self):
|
||||
pointCloudSize = 1000
|
||||
resolution = 0.0001
|
||||
scale = 1 << 20
|
||||
|
||||
pointCloud = np.random.randint(-scale, scale, size=(pointCloudSize, 3)) * (10.0 / scale)
|
||||
pointCloud = pointCloud.astype(np.float32)
|
||||
|
||||
octree = cv.Octree_createWithResolution(resolution, pointCloud)
|
||||
|
||||
restPoint = np.random.randint(-scale, scale, size=(1, 3)) * (10.0 / scale)
|
||||
restPoint = [restPoint[0, 0], restPoint[0, 1], restPoint[0, 2]]
|
||||
|
||||
self.assertTrue(octree.isPointInBound(restPoint))
|
||||
self.assertFalse(octree.deletePoint(restPoint))
|
||||
self.assertTrue(octree.insertPoint(restPoint))
|
||||
self.assertTrue(octree.deletePoint(restPoint))
|
||||
|
||||
if __name__ == '__main__':
|
||||
NewOpenCVTests.bootstrap()
|
||||
@@ -0,0 +1,88 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import numpy as np
|
||||
import cv2 as cv
|
||||
|
||||
from tests_common import NewOpenCVTests
|
||||
|
||||
class odometry_test(NewOpenCVTests):
|
||||
def commonOdometryTest(self, needRgb, otype, algoType, useFrame):
|
||||
depth = self.get_sample('cv/rgbd/depth.png', cv.IMREAD_ANYDEPTH).astype(np.float32)
|
||||
if needRgb:
|
||||
rgb = self.get_sample('cv/rgbd/rgb.png', cv.IMREAD_ANYCOLOR)
|
||||
radian = np.radians(1)
|
||||
Rt_warp = np.array(
|
||||
[[np.cos(radian), -np.sin(radian), 0],
|
||||
[np.sin(radian), np.cos(radian), 0],
|
||||
[0, 0, 1]], dtype=np.float32
|
||||
)
|
||||
Rt_curr = np.array(
|
||||
[[np.cos(radian), -np.sin(radian), 0, 0],
|
||||
[np.sin(radian), np.cos(radian), 0, 0],
|
||||
[0, 0, 1, 0],
|
||||
[0, 0, 0, 1]], dtype=np.float32
|
||||
)
|
||||
Rt_res = np.zeros((4, 4))
|
||||
|
||||
if otype is not None:
|
||||
settings = cv.OdometrySettings()
|
||||
odometry = cv.Odometry(otype, settings, algoType)
|
||||
else:
|
||||
odometry = cv.Odometry()
|
||||
|
||||
warped_depth = cv.warpPerspective(depth, Rt_warp, (640, 480))
|
||||
if needRgb:
|
||||
warped_rgb = cv.warpPerspective(rgb, Rt_warp, (640, 480))
|
||||
|
||||
if useFrame:
|
||||
if needRgb:
|
||||
srcFrame = cv.OdometryFrame(depth, rgb)
|
||||
dstFrame = cv.OdometryFrame(warped_depth, warped_rgb)
|
||||
else:
|
||||
srcFrame = cv.OdometryFrame(depth)
|
||||
dstFrame = cv.OdometryFrame(warped_depth)
|
||||
odometry.prepareFrames(srcFrame, dstFrame)
|
||||
isCorrect = odometry.compute(srcFrame, dstFrame, Rt_res)
|
||||
else:
|
||||
if needRgb:
|
||||
isCorrect = odometry.compute(depth, rgb, warped_depth, warped_rgb, Rt_res)
|
||||
else:
|
||||
isCorrect = odometry.compute(depth, warped_depth, Rt_res)
|
||||
|
||||
res = np.absolute(Rt_curr - Rt_res).sum()
|
||||
eps = 0.15
|
||||
self.assertLessEqual(res, eps)
|
||||
self.assertTrue(isCorrect)
|
||||
|
||||
def test_OdometryDefault(self):
|
||||
self.commonOdometryTest(False, None, None, False)
|
||||
|
||||
def test_OdometryDefaultFrame(self):
|
||||
self.commonOdometryTest(False, None, None, True)
|
||||
|
||||
def test_OdometryDepth(self):
|
||||
self.commonOdometryTest(False, cv.OdometryType_DEPTH, cv.OdometryAlgoType_COMMON, False)
|
||||
|
||||
def test_OdometryDepthFast(self):
|
||||
self.commonOdometryTest(False, cv.OdometryType_DEPTH, cv.OdometryAlgoType_FAST, False)
|
||||
|
||||
def test_OdometryDepthFrame(self):
|
||||
self.commonOdometryTest(False, cv.OdometryType_DEPTH, cv.OdometryAlgoType_COMMON, True)
|
||||
|
||||
def test_OdometryDepthFastFrame(self):
|
||||
self.commonOdometryTest(False, cv.OdometryType_DEPTH, cv.OdometryAlgoType_FAST, True)
|
||||
|
||||
def test_OdometryRGB(self):
|
||||
self.commonOdometryTest(True, cv.OdometryType_RGB, cv.OdometryAlgoType_COMMON, False)
|
||||
|
||||
def test_OdometryRGBFrame(self):
|
||||
self.commonOdometryTest(True, cv.OdometryType_RGB, cv.OdometryAlgoType_COMMON, True)
|
||||
|
||||
def test_OdometryRGB_Depth(self):
|
||||
self.commonOdometryTest(True, cv.OdometryType_RGB_DEPTH, cv.OdometryAlgoType_COMMON, False)
|
||||
|
||||
def test_OdometryRGB_DepthFrame(self):
|
||||
self.commonOdometryTest(True, cv.OdometryType_RGB_DEPTH, cv.OdometryAlgoType_COMMON, True)
|
||||
|
||||
if __name__ == '__main__':
|
||||
NewOpenCVTests.bootstrap()
|
||||
@@ -0,0 +1,113 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Python 2/3 compatibility
|
||||
from __future__ import print_function
|
||||
|
||||
import os, numpy
|
||||
import math
|
||||
import unittest
|
||||
import cv2 as cv
|
||||
|
||||
from tests_common import NewOpenCVTests
|
||||
|
||||
def lookAtMatrixCal(position, lookat, upVector):
|
||||
tmp = position - lookat
|
||||
norm = numpy.linalg.norm(tmp)
|
||||
w = tmp / norm
|
||||
tmp = numpy.cross(upVector, w)
|
||||
norm = numpy.linalg.norm(tmp)
|
||||
u = tmp / norm
|
||||
v = numpy.cross(w, u)
|
||||
res = numpy.array([
|
||||
[u[0], u[1], u[2], 0],
|
||||
[v[0], v[1], v[2], 0],
|
||||
[w[0], w[1], w[2], 0],
|
||||
[0, 0, 0, 1.0]
|
||||
], dtype=numpy.float32)
|
||||
translate = numpy.array([
|
||||
[1.0, 0, 0, -position[0]],
|
||||
[0, 1.0, 0, -position[1]],
|
||||
[0, 0, 1.0, -position[2]],
|
||||
[0, 0, 0, 1.0]
|
||||
], dtype=numpy.float32)
|
||||
res = numpy.matmul(res, translate)
|
||||
return res
|
||||
|
||||
class raster_test(NewOpenCVTests):
|
||||
|
||||
def prepareData(self):
|
||||
self.vertices = numpy.array([
|
||||
[ 2.0, 0.0, -2.0],
|
||||
[ 0.0, -6.0, -2.0],
|
||||
[-2.0, 0.0, -2.0],
|
||||
[ 3.5, -1.0, -5.0],
|
||||
[ 2.5, -2.5, -5.0],
|
||||
[-1.0, 1.0, -5.0],
|
||||
[-6.5, -1.0, -3.0],
|
||||
[-2.5, -2.0, -3.0],
|
||||
[ 1.0, 1.0, -5.0],
|
||||
], dtype=numpy.float32)
|
||||
|
||||
self.indices = numpy.array([ [0, 1, 2], [3, 4, 5], [6, 7, 8]], dtype=int)
|
||||
|
||||
col1 = [ 185.0, 238.0, 217.0 ]
|
||||
col2 = [ 238.0, 217.0, 185.0 ]
|
||||
col3 = [ 238.0, 10.0, 150.0 ]
|
||||
|
||||
self.colors = numpy.array([
|
||||
col1, col2, col3,
|
||||
col2, col3, col1,
|
||||
col3, col1, col2,
|
||||
], dtype=numpy.float32)
|
||||
|
||||
self.colors = self.colors / 255.0
|
||||
|
||||
self.zNear = 0.1
|
||||
self.zFar = 50.0
|
||||
self.fovy = 45.0 * math.pi / 180.0
|
||||
|
||||
position = numpy.array([0.0, 0.0, 5.0], dtype=numpy.float32)
|
||||
lookat = numpy.array([0.0, 0.0, 0.0], dtype=numpy.float32)
|
||||
upVector = numpy.array([0.0, 1.0, 0.0], dtype=numpy.float32)
|
||||
self.cameraPose = lookAtMatrixCal(position, lookat, upVector)
|
||||
|
||||
self.depth_buf = numpy.ones((240, 320), dtype=numpy.float32) * self.zFar
|
||||
self.color_buf = numpy.zeros((240, 320, 3), dtype=numpy.float32)
|
||||
|
||||
self.settings = cv.TriangleRasterizeSettings().setShadingType(cv.RASTERIZE_SHADING_SHADED)
|
||||
self.settings = self.settings.setCullingMode(cv.RASTERIZE_CULLING_NONE)
|
||||
|
||||
def compareResults(self, needRgb, needDepth):
|
||||
if needDepth:
|
||||
depth = self.get_sample('rendering/depth_image_Clipping_320x240_CullNone.png', cv.IMREAD_ANYDEPTH).astype(numpy.float32)
|
||||
depthFactor = 1000.0
|
||||
diff = depth/depthFactor - self.depth_buf
|
||||
norm = numpy.linalg.norm(diff)
|
||||
self.assertLessEqual(norm, 356.0)
|
||||
|
||||
if needRgb:
|
||||
rgb = self.get_sample('rendering/example_image_Clipping_320x240_CullNone_Shaded.png', cv.IMREAD_ANYCOLOR)
|
||||
diff = rgb/255.0 - self.color_buf
|
||||
norm = numpy.linalg.norm(diff)
|
||||
self.assertLessEqual(norm, 11.62)
|
||||
|
||||
def test_rasterizeBoth(self):
|
||||
self.prepareData()
|
||||
self.color_buf, self.depth_buf = cv.triangleRasterize(self.vertices, self.indices, self.colors, self.color_buf, self.depth_buf,
|
||||
self.cameraPose, self.fovy, self.zNear, self.zFar, self.settings)
|
||||
self.compareResults(needRgb=True, needDepth=True)
|
||||
|
||||
def test_rasterizeDepth(self):
|
||||
self.prepareData()
|
||||
self.depth_buf = cv.triangleRasterizeDepth(self.vertices, self.indices, self.depth_buf,
|
||||
self.cameraPose, self.fovy, self.zNear, self.zFar, self.settings)
|
||||
self.compareResults(needRgb=False, needDepth=True)
|
||||
|
||||
def test_rasterizeColor(self):
|
||||
self.prepareData()
|
||||
self.color_buf = cv.triangleRasterizeColor(self.vertices, self.indices, self.colors, self.color_buf,
|
||||
self.cameraPose, self.fovy, self.zNear, self.zFar, self.settings)
|
||||
self.compareResults(needRgb=True, needDepth=False)
|
||||
|
||||
if __name__ == '__main__':
|
||||
NewOpenCVTests.bootstrap()
|
||||
@@ -0,0 +1,43 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Python 2/3 compatibility
|
||||
from __future__ import print_function
|
||||
|
||||
import os, numpy
|
||||
import unittest
|
||||
import cv2 as cv
|
||||
|
||||
from tests_common import NewOpenCVTests
|
||||
|
||||
class rgbd_test(NewOpenCVTests):
|
||||
|
||||
def test_computeRgbdPlane(self):
|
||||
|
||||
depth_image = self.get_sample('cv/rgbd/depth.png', cv.IMREAD_ANYDEPTH)
|
||||
if depth_image is None:
|
||||
raise unittest.SkipTest("Missing files with test data")
|
||||
|
||||
K = numpy.array([[525, 0, 320.5], [0, 525, 240.5], [0, 0, 1]])
|
||||
points3d = cv.depthTo3d(depth_image, K)
|
||||
normals = cv.RgbdNormals_create(480, 640, cv.CV_32F, K).apply(points3d)
|
||||
_, planes_coeff = cv.findPlanes(points3d, normals, numpy.array([]), numpy.array([]), 40, 1600, 0.01, 0, 0, 0, cv.RGBD_PLANE_METHOD_DEFAULT)
|
||||
|
||||
planes_coeff_expected = \
|
||||
numpy.asarray([[[-0.02447728, -0.8678335 , -0.49625182, 4.02800846]],
|
||||
[[-0.05055107, -0.86144137, -0.50533485, 3.95456314]],
|
||||
[[-0.03294908, -0.86964548, -0.49257591, 3.97052431]],
|
||||
[[-0.02886586, -0.87153459, -0.48948362, 7.77550507]],
|
||||
[[-0.04455929, -0.87659335, -0.47916424, 3.93200684]],
|
||||
[[-0.21514639, 0.18835169, -0.95824611, 7.59479475]],
|
||||
[[-0.01006953, -0.86679155, -0.49856904, 4.01355648]],
|
||||
[[-0.00876531, -0.87571168, -0.48275498, 3.96768975]],
|
||||
[[-0.06395926, -0.86951321, -0.48975089, 4.08618736]],
|
||||
[[-0.01403128, -0.87593341, -0.48222789, 7.74559402]],
|
||||
[[-0.01143177, -0.87495202, -0.4840748 , 7.75355816]]],
|
||||
dtype=numpy.float32)
|
||||
|
||||
eps = 0.05
|
||||
self.assertLessEqual(cv.norm(planes_coeff, planes_coeff_expected, cv.NORM_L2), eps)
|
||||
|
||||
if __name__ == '__main__':
|
||||
NewOpenCVTests.bootstrap()
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
#!/usr/bin/env python
|
||||
# Python 2/3 compatibility
|
||||
from __future__ import print_function
|
||||
|
||||
import numpy as np
|
||||
import cv2 as cv
|
||||
|
||||
from tests_common import NewOpenCVTests
|
||||
|
||||
class solvepnp_test(NewOpenCVTests):
|
||||
|
||||
def test_regression_16040(self):
|
||||
obj_points = np.array([[0, 0, 0], [0, 1, 0], [1, 1, 0], [1, 0, 0]], dtype=np.float32)
|
||||
img_points = np.array(
|
||||
[[700, 400], [700, 600], [900, 600], [900, 400]], dtype=np.float32
|
||||
)
|
||||
|
||||
cameraMatrix = np.array(
|
||||
[[712.0634, 0, 800], [0, 712.540, 500], [0, 0, 1]], dtype=np.float32
|
||||
)
|
||||
distCoeffs = np.array([[0, 0, 0, 0]], dtype=np.float32)
|
||||
r = np.array([], dtype=np.float32)
|
||||
x, r, t, e = cv.solvePnPGeneric(
|
||||
obj_points, img_points, cameraMatrix, distCoeffs, reprojectionError=r
|
||||
)
|
||||
|
||||
def test_regression_16040_2(self):
|
||||
obj_points = np.array([[0, 0, 0], [0, 1, 0], [1, 1, 0], [1, 0, 0]], dtype=np.float32)
|
||||
img_points = np.array(
|
||||
[[[700, 400], [700, 600], [900, 600], [900, 400]]], dtype=np.float32
|
||||
)
|
||||
|
||||
cameraMatrix = np.array(
|
||||
[[712.0634, 0, 800], [0, 712.540, 500], [0, 0, 1]], dtype=np.float32
|
||||
)
|
||||
distCoeffs = np.array([[0, 0, 0, 0]], dtype=np.float32)
|
||||
r = np.array([], dtype=np.float32)
|
||||
x, r, t, e = cv.solvePnPGeneric(
|
||||
obj_points, img_points, cameraMatrix, distCoeffs, reprojectionError=r
|
||||
)
|
||||
|
||||
def test_regression_16049(self):
|
||||
obj_points = np.array([[0, 0, 0], [0, 1, 0], [1, 1, 0], [1, 0, 0]], dtype=np.float32)
|
||||
img_points = np.array(
|
||||
[[[700, 400], [700, 600], [900, 600], [900, 400]]], dtype=np.float32
|
||||
)
|
||||
|
||||
cameraMatrix = np.array(
|
||||
[[712.0634, 0, 800], [0, 712.540, 500], [0, 0, 1]], dtype=np.float32
|
||||
)
|
||||
distCoeffs = np.array([[0, 0, 0, 0]], dtype=np.float32)
|
||||
x, r, t, e = cv.solvePnPGeneric(
|
||||
obj_points, img_points, cameraMatrix, distCoeffs
|
||||
)
|
||||
if e is None:
|
||||
# noArray() is supported, see https://github.com/opencv/opencv/issues/16049
|
||||
pass
|
||||
else:
|
||||
eDump = cv.utils.dumpInputArray(e)
|
||||
self.assertEqual(eDump, "InputArray: empty()=false kind=0x00010000 flags=0x01010000 total(-1)=1 dims(-1)=2 size(-1)=1x1 type(-1)=CV_32FC1")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
NewOpenCVTests.bootstrap()
|
||||
@@ -0,0 +1,123 @@
|
||||
import numpy as np
|
||||
import cv2 as cv
|
||||
|
||||
from tests_common import NewOpenCVTests
|
||||
|
||||
class volume_test(NewOpenCVTests):
|
||||
def test_VolumeDefault(self):
|
||||
depthPath = 'cv/rgbd/depth.png'
|
||||
depth = self.get_sample(depthPath, cv.IMREAD_ANYDEPTH).astype(np.float32)
|
||||
if depth.size <= 0:
|
||||
raise Exception('Failed to load depth file: %s' % depthPath)
|
||||
|
||||
Rt = np.eye(4)
|
||||
volume = cv.Volume()
|
||||
volume.integrate(depth, Rt)
|
||||
|
||||
size = (480, 640, 4)
|
||||
points = np.zeros(size, np.float32)
|
||||
normals = np.zeros(size, np.float32)
|
||||
|
||||
Kraycast = np.array([[525. , 0. , 319.5],
|
||||
[ 0. , 525. , 239.5],
|
||||
[ 0. , 0. , 1. ]])
|
||||
|
||||
volume.raycastEx(Rt, size[0], size[1], Kraycast, points, normals)
|
||||
|
||||
self.assertEqual(points.shape, size)
|
||||
self.assertEqual(points.shape, normals.shape)
|
||||
|
||||
volume.raycast(Rt, points, normals)
|
||||
|
||||
self.assertEqual(points.shape, size)
|
||||
self.assertEqual(points.shape, normals.shape)
|
||||
|
||||
def test_VolumeTSDF(self):
|
||||
depthPath = 'cv/rgbd/depth.png'
|
||||
depth = self.get_sample(depthPath, cv.IMREAD_ANYDEPTH).astype(np.float32)
|
||||
if depth.size <= 0:
|
||||
raise Exception('Failed to load depth file: %s' % depthPath)
|
||||
|
||||
Rt = np.eye(4)
|
||||
|
||||
settings = cv.VolumeSettings(cv.VolumeType_TSDF)
|
||||
volume = cv.Volume(cv.VolumeType_TSDF, settings)
|
||||
volume.integrate(depth, Rt)
|
||||
|
||||
size = (480, 640, 4)
|
||||
points = np.zeros(size, np.float32)
|
||||
normals = np.zeros(size, np.float32)
|
||||
|
||||
Kraycast = settings.getCameraRaycastIntrinsics()
|
||||
volume.raycastEx(Rt, size[0], size[1], Kraycast, points, normals)
|
||||
|
||||
self.assertEqual(points.shape, size)
|
||||
self.assertEqual(points.shape, normals.shape)
|
||||
|
||||
volume.raycast(Rt, points, normals)
|
||||
|
||||
self.assertEqual(points.shape, size)
|
||||
self.assertEqual(points.shape, normals.shape)
|
||||
|
||||
def test_VolumeHashTSDF(self):
|
||||
depthPath = 'cv/rgbd/depth.png'
|
||||
depth = self.get_sample(depthPath, cv.IMREAD_ANYDEPTH).astype(np.float32)
|
||||
if depth.size <= 0:
|
||||
raise Exception('Failed to load depth file: %s' % depthPath)
|
||||
|
||||
Rt = np.eye(4)
|
||||
settings = cv.VolumeSettings(cv.VolumeType_HashTSDF)
|
||||
volume = cv.Volume(cv.VolumeType_HashTSDF, settings)
|
||||
volume.integrate(depth, Rt)
|
||||
|
||||
size = (480, 640, 4)
|
||||
points = np.zeros(size, np.float32)
|
||||
normals = np.zeros(size, np.float32)
|
||||
|
||||
Kraycast = settings.getCameraRaycastIntrinsics()
|
||||
volume.raycastEx(Rt, size[0], size[1], Kraycast, points, normals)
|
||||
|
||||
self.assertEqual(points.shape, size)
|
||||
self.assertEqual(points.shape, normals.shape)
|
||||
|
||||
volume.raycast(Rt, points, normals)
|
||||
|
||||
self.assertEqual(points.shape, size)
|
||||
self.assertEqual(points.shape, normals.shape)
|
||||
|
||||
def test_VolumeColorTSDF(self):
|
||||
depthPath = 'cv/rgbd/depth.png'
|
||||
rgbPath = 'cv/rgbd/rgb.png'
|
||||
depth = self.get_sample(depthPath, cv.IMREAD_ANYDEPTH).astype(np.float32)
|
||||
rgb = self.get_sample(rgbPath, cv.IMREAD_ANYCOLOR).astype(np.float32)
|
||||
|
||||
if depth.size <= 0:
|
||||
raise Exception('Failed to load depth file: %s' % depthPath)
|
||||
if rgb.size <= 0:
|
||||
raise Exception('Failed to load RGB file: %s' % rgbPath)
|
||||
|
||||
Rt = np.eye(4)
|
||||
settings = cv.VolumeSettings(cv.VolumeType_ColorTSDF)
|
||||
volume = cv.Volume(cv.VolumeType_ColorTSDF, settings)
|
||||
volume.integrateColor(depth, rgb, Rt)
|
||||
|
||||
size = (480, 640, 4)
|
||||
points = np.zeros(size, np.float32)
|
||||
normals = np.zeros(size, np.float32)
|
||||
colors = np.zeros(size, np.float32)
|
||||
|
||||
Kraycast = settings.getCameraRaycastIntrinsics()
|
||||
volume.raycastExColor(Rt, size[0], size[1], Kraycast, points, normals, colors)
|
||||
|
||||
self.assertEqual(points.shape, size)
|
||||
self.assertEqual(points.shape, normals.shape)
|
||||
|
||||
volume.raycastColor(Rt, points, normals, colors)
|
||||
|
||||
self.assertEqual(points.shape, size)
|
||||
self.assertEqual(points.shape, normals.shape)
|
||||
self.assertEqual(points.shape, colors.shape)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
NewOpenCVTests.bootstrap()
|
||||
Reference in New Issue
Block a user