vendor: OpenCV 5.0.0 snapshot at 40738fb16ceddb5fb3fea747585f7ce6abb0605b
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
{
|
||||
"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" } },
|
||||
"minEnclosingCircle" : { "points" : {"ctype" : "vector_Point2f"} },
|
||||
"fitEllipse" : { "points" : {"ctype" : "vector_Point2f"} },
|
||||
"fillPoly" : { "pts" : {"ctype" : "vector_vector_Point"} },
|
||||
"polylines" : { "pts" : {"ctype" : "vector_vector_Point"} },
|
||||
"fillConvexPoly" : { "points" : {"ctype" : "vector_Point"} },
|
||||
"approxPolyDP" : { "curve" : {"ctype" : "vector_Point2f"},
|
||||
"approxCurve" : {"ctype" : "vector_Point2f"} },
|
||||
"arcLength" : { "curve" : {"ctype" : "vector_Point2f"} },
|
||||
"pointPolygonTest" : { "contour" : {"ctype" : "vector_Point2f"} },
|
||||
"minAreaRect" : { "points" : {"ctype" : "vector_Point2f"} },
|
||||
"getAffineTransform" : { "src" : {"ctype" : "vector_Point2f"},
|
||||
"dst" : {"ctype" : "vector_Point2f"} },
|
||||
"convexityDefects" : { "contour" : {"ctype" : "vector_Point"},
|
||||
"convexhull" : {"ctype" : "vector_int"},
|
||||
"convexityDefects" : {"ctype" : "vector_Vec4i"} },
|
||||
"isContourConvex" : { "contour" : {"ctype" : "vector_Point"} },
|
||||
"convexHull" : { "points" : {"ctype" : "vector_Point"},
|
||||
"hull" : {"ctype" : "vector_int"},
|
||||
"returnPoints" : {"ctype" : ""} }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,242 @@
|
||||
package org.opencv.geometry;
|
||||
|
||||
//javadoc:Moments
|
||||
public class Moments {
|
||||
|
||||
public double m00;
|
||||
public double m10;
|
||||
public double m01;
|
||||
public double m20;
|
||||
public double m11;
|
||||
public double m02;
|
||||
public double m30;
|
||||
public double m21;
|
||||
public double m12;
|
||||
public double m03;
|
||||
|
||||
public double mu20;
|
||||
public double mu11;
|
||||
public double mu02;
|
||||
public double mu30;
|
||||
public double mu21;
|
||||
public double mu12;
|
||||
public double mu03;
|
||||
|
||||
public double nu20;
|
||||
public double nu11;
|
||||
public double nu02;
|
||||
public double nu30;
|
||||
public double nu21;
|
||||
public double nu12;
|
||||
public double nu03;
|
||||
|
||||
public Moments(
|
||||
double m00,
|
||||
double m10,
|
||||
double m01,
|
||||
double m20,
|
||||
double m11,
|
||||
double m02,
|
||||
double m30,
|
||||
double m21,
|
||||
double m12,
|
||||
double m03)
|
||||
{
|
||||
this.m00 = m00;
|
||||
this.m10 = m10;
|
||||
this.m01 = m01;
|
||||
this.m20 = m20;
|
||||
this.m11 = m11;
|
||||
this.m02 = m02;
|
||||
this.m30 = m30;
|
||||
this.m21 = m21;
|
||||
this.m12 = m12;
|
||||
this.m03 = m03;
|
||||
this.completeState();
|
||||
}
|
||||
|
||||
public Moments() {
|
||||
this(0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
public Moments(double[] vals) {
|
||||
set(vals);
|
||||
}
|
||||
|
||||
public void set(double[] vals) {
|
||||
if (vals != null) {
|
||||
m00 = vals.length > 0 ? vals[0] : 0;
|
||||
m10 = vals.length > 1 ? vals[1] : 0;
|
||||
m01 = vals.length > 2 ? vals[2] : 0;
|
||||
m20 = vals.length > 3 ? vals[3] : 0;
|
||||
m11 = vals.length > 4 ? vals[4] : 0;
|
||||
m02 = vals.length > 5 ? vals[5] : 0;
|
||||
m30 = vals.length > 6 ? vals[6] : 0;
|
||||
m21 = vals.length > 7 ? vals[7] : 0;
|
||||
m12 = vals.length > 8 ? vals[8] : 0;
|
||||
m03 = vals.length > 9 ? vals[9] : 0;
|
||||
this.completeState();
|
||||
} else {
|
||||
m00 = 0;
|
||||
m10 = 0;
|
||||
m01 = 0;
|
||||
m20 = 0;
|
||||
m11 = 0;
|
||||
m02 = 0;
|
||||
m30 = 0;
|
||||
m21 = 0;
|
||||
m12 = 0;
|
||||
m03 = 0;
|
||||
mu20 = 0;
|
||||
mu11 = 0;
|
||||
mu02 = 0;
|
||||
mu30 = 0;
|
||||
mu21 = 0;
|
||||
mu12 = 0;
|
||||
mu03 = 0;
|
||||
nu20 = 0;
|
||||
nu11 = 0;
|
||||
nu02 = 0;
|
||||
nu30 = 0;
|
||||
nu21 = 0;
|
||||
nu12 = 0;
|
||||
nu03 = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Moments [ " +
|
||||
"\n" +
|
||||
"m00=" + m00 + ", " +
|
||||
"\n" +
|
||||
"m10=" + m10 + ", " +
|
||||
"m01=" + m01 + ", " +
|
||||
"\n" +
|
||||
"m20=" + m20 + ", " +
|
||||
"m11=" + m11 + ", " +
|
||||
"m02=" + m02 + ", " +
|
||||
"\n" +
|
||||
"m30=" + m30 + ", " +
|
||||
"m21=" + m21 + ", " +
|
||||
"m12=" + m12 + ", " +
|
||||
"m03=" + m03 + ", " +
|
||||
"\n" +
|
||||
"mu20=" + mu20 + ", " +
|
||||
"mu11=" + mu11 + ", " +
|
||||
"mu02=" + mu02 + ", " +
|
||||
"\n" +
|
||||
"mu30=" + mu30 + ", " +
|
||||
"mu21=" + mu21 + ", " +
|
||||
"mu12=" + mu12 + ", " +
|
||||
"mu03=" + mu03 + ", " +
|
||||
"\n" +
|
||||
"nu20=" + nu20 + ", " +
|
||||
"nu11=" + nu11 + ", " +
|
||||
"nu02=" + nu02 + ", " +
|
||||
"\n" +
|
||||
"nu30=" + nu30 + ", " +
|
||||
"nu21=" + nu21 + ", " +
|
||||
"nu12=" + nu12 + ", " +
|
||||
"nu03=" + nu03 + ", " +
|
||||
"\n]";
|
||||
}
|
||||
|
||||
protected void completeState()
|
||||
{
|
||||
double cx = 0, cy = 0;
|
||||
double mu20, mu11, mu02;
|
||||
double inv_m00 = 0.0;
|
||||
|
||||
if( Math.abs(this.m00) > 0.00000001 )
|
||||
{
|
||||
inv_m00 = 1. / this.m00;
|
||||
cx = this.m10 * inv_m00;
|
||||
cy = this.m01 * inv_m00;
|
||||
}
|
||||
|
||||
// mu20 = m20 - m10*cx
|
||||
mu20 = this.m20 - this.m10 * cx;
|
||||
// mu11 = m11 - m10*cy
|
||||
mu11 = this.m11 - this.m10 * cy;
|
||||
// mu02 = m02 - m01*cy
|
||||
mu02 = this.m02 - this.m01 * cy;
|
||||
|
||||
this.mu20 = mu20;
|
||||
this.mu11 = mu11;
|
||||
this.mu02 = mu02;
|
||||
|
||||
// mu30 = m30 - cx*(3*mu20 + cx*m10)
|
||||
this.mu30 = this.m30 - cx * (3 * mu20 + cx * this.m10);
|
||||
mu11 += mu11;
|
||||
// mu21 = m21 - cx*(2*mu11 + cx*m01) - cy*mu20
|
||||
this.mu21 = this.m21 - cx * (mu11 + cx * this.m01) - cy * mu20;
|
||||
// mu12 = m12 - cy*(2*mu11 + cy*m10) - cx*mu02
|
||||
this.mu12 = this.m12 - cy * (mu11 + cy * this.m10) - cx * mu02;
|
||||
// mu03 = m03 - cy*(3*mu02 + cy*m01)
|
||||
this.mu03 = this.m03 - cy * (3 * mu02 + cy * this.m01);
|
||||
|
||||
|
||||
double inv_sqrt_m00 = Math.sqrt(Math.abs(inv_m00));
|
||||
double s2 = inv_m00*inv_m00, s3 = s2*inv_sqrt_m00;
|
||||
|
||||
this.nu20 = this.mu20*s2;
|
||||
this.nu11 = this.mu11*s2;
|
||||
this.nu02 = this.mu02*s2;
|
||||
this.nu30 = this.mu30*s3;
|
||||
this.nu21 = this.mu21*s3;
|
||||
this.nu12 = this.mu12*s3;
|
||||
this.nu03 = this.mu03*s3;
|
||||
|
||||
}
|
||||
|
||||
public double get_m00() { return this.m00; }
|
||||
public double get_m10() { return this.m10; }
|
||||
public double get_m01() { return this.m01; }
|
||||
public double get_m20() { return this.m20; }
|
||||
public double get_m11() { return this.m11; }
|
||||
public double get_m02() { return this.m02; }
|
||||
public double get_m30() { return this.m30; }
|
||||
public double get_m21() { return this.m21; }
|
||||
public double get_m12() { return this.m12; }
|
||||
public double get_m03() { return this.m03; }
|
||||
public double get_mu20() { return this.mu20; }
|
||||
public double get_mu11() { return this.mu11; }
|
||||
public double get_mu02() { return this.mu02; }
|
||||
public double get_mu30() { return this.mu30; }
|
||||
public double get_mu21() { return this.mu21; }
|
||||
public double get_mu12() { return this.mu12; }
|
||||
public double get_mu03() { return this.mu03; }
|
||||
public double get_nu20() { return this.nu20; }
|
||||
public double get_nu11() { return this.nu11; }
|
||||
public double get_nu02() { return this.nu02; }
|
||||
public double get_nu30() { return this.nu30; }
|
||||
public double get_nu21() { return this.nu21; }
|
||||
public double get_nu12() { return this.nu12; }
|
||||
public double get_nu03() { return this.nu03; }
|
||||
|
||||
public void set_m00(double m00) { this.m00 = m00; }
|
||||
public void set_m10(double m10) { this.m10 = m10; }
|
||||
public void set_m01(double m01) { this.m01 = m01; }
|
||||
public void set_m20(double m20) { this.m20 = m20; }
|
||||
public void set_m11(double m11) { this.m11 = m11; }
|
||||
public void set_m02(double m02) { this.m02 = m02; }
|
||||
public void set_m30(double m30) { this.m30 = m30; }
|
||||
public void set_m21(double m21) { this.m21 = m21; }
|
||||
public void set_m12(double m12) { this.m12 = m12; }
|
||||
public void set_m03(double m03) { this.m03 = m03; }
|
||||
public void set_mu20(double mu20) { this.mu20 = mu20; }
|
||||
public void set_mu11(double mu11) { this.mu11 = mu11; }
|
||||
public void set_mu02(double mu02) { this.mu02 = mu02; }
|
||||
public void set_mu30(double mu30) { this.mu30 = mu30; }
|
||||
public void set_mu21(double mu21) { this.mu21 = mu21; }
|
||||
public void set_mu12(double mu12) { this.mu12 = mu12; }
|
||||
public void set_mu03(double mu03) { this.mu03 = mu03; }
|
||||
public void set_nu20(double nu20) { this.nu20 = nu20; }
|
||||
public void set_nu11(double nu11) { this.nu11 = nu11; }
|
||||
public void set_nu02(double nu02) { this.nu02 = nu02; }
|
||||
public void set_nu30(double nu30) { this.nu30 = nu30; }
|
||||
public void set_nu21(double nu21) { this.nu21 = nu21; }
|
||||
public void set_nu12(double nu12) { this.nu12 = nu12; }
|
||||
public void set_nu03(double nu03) { this.nu03 = nu03; }
|
||||
}
|
||||
@@ -0,0 +1,728 @@
|
||||
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.Rect;
|
||||
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.2);
|
||||
assertMatEqual(truth_tvec, tvec, EPS*2.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
|
||||
}
|
||||
|
||||
//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, Geometry.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);
|
||||
}
|
||||
|
||||
public void testContourAreaMat() {
|
||||
Mat contour = new Mat(1, 4, CvType.CV_32FC2);
|
||||
contour.put(0, 0, 0, 0, 10, 0, 10, 10, 5, 4);
|
||||
|
||||
double area = Geometry.contourArea(contour);
|
||||
|
||||
assertEquals(45., area, EPS);
|
||||
}
|
||||
|
||||
public void testContourAreaMatBoolean() {
|
||||
Mat contour = new Mat(1, 4, CvType.CV_32FC2);
|
||||
contour.put(0, 0, 0, 0, 10, 0, 10, 10, 5, 4);
|
||||
|
||||
double area = Geometry.contourArea(contour, true);
|
||||
|
||||
assertEquals(45., area, EPS);
|
||||
// TODO_: write better test
|
||||
}
|
||||
|
||||
public void testArcLength() {
|
||||
MatOfPoint2f curve = new MatOfPoint2f(new Point(1, 3), new Point(2, 4), new Point(3, 5), new Point(4, 4), new Point(5, 3));
|
||||
|
||||
double arcLength = Geometry.arcLength(curve, false);
|
||||
|
||||
assertEquals(5.656854249, arcLength, 0.000001);
|
||||
}
|
||||
|
||||
public void testBoundingRect() {
|
||||
MatOfPoint points = new MatOfPoint(new Point(0, 0), new Point(0, 4), new Point(4, 0), new Point(4, 4));
|
||||
Point p1 = new Point(1, 1);
|
||||
Point p2 = new Point(-5, -2);
|
||||
|
||||
Rect bbox = Geometry.boundingRect(points);
|
||||
|
||||
assertTrue(bbox.contains(p1));
|
||||
assertFalse(bbox.contains(p2));
|
||||
}
|
||||
|
||||
public void testGetAffineTransform() {
|
||||
MatOfPoint2f src = new MatOfPoint2f(new Point(2, 3), new Point(3, 1), new Point(1, 4));
|
||||
MatOfPoint2f dst = new MatOfPoint2f(new Point(3, 3), new Point(7, 4), new Point(5, 6));
|
||||
|
||||
Mat transform = Geometry.getAffineTransform(src, dst);
|
||||
|
||||
Mat truth = new Mat(2, 3, CvType.CV_64FC1) {
|
||||
{
|
||||
put(0, 0, -8, -6, 37);
|
||||
put(1, 0, -7, -4, 29);
|
||||
}
|
||||
};
|
||||
assertMatEqual(truth, transform, EPS);
|
||||
}
|
||||
|
||||
public void testGetRotationMatrix2D() {
|
||||
Point center = new Point(0, 0);
|
||||
|
||||
dst = Geometry.getRotationMatrix2D(center, 0, 1);
|
||||
|
||||
truth = new Mat(2, 3, CvType.CV_64F) {
|
||||
{
|
||||
put(0, 0, 1, 0, 0);
|
||||
put(1, 0, 0, 1, 0);
|
||||
}
|
||||
};
|
||||
|
||||
assertMatEqual(truth, dst, EPS);
|
||||
}
|
||||
|
||||
public void testInvertAffineTransform() {
|
||||
Mat src = new Mat(2, 3, CvType.CV_64F, new Scalar(1));
|
||||
|
||||
Geometry.invertAffineTransform(src, dst);
|
||||
|
||||
truth = new Mat(2, 3, CvType.CV_64F, new Scalar(0));
|
||||
assertMatEqual(truth, dst, EPS);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package org.opencv.test.geometry;
|
||||
|
||||
import org.opencv.test.OpenCVTestCase;
|
||||
import org.opencv.core.Core;
|
||||
import org.opencv.core.Mat;
|
||||
import org.opencv.core.CvType;
|
||||
import org.opencv.core.Scalar;
|
||||
import org.opencv.geometry.Geometry;
|
||||
import org.opencv.geometry.Moments;
|
||||
|
||||
public class MomentsTest extends OpenCVTestCase {
|
||||
|
||||
Mat data;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
data = new Mat(3,3, CvType.CV_8UC1, new Scalar(1));
|
||||
data.row(1).setTo(new Scalar(5));
|
||||
}
|
||||
|
||||
public void testAll() {
|
||||
Moments res = Geometry.moments(data);
|
||||
assertEquals(res.m00, 21.0, EPS);
|
||||
assertEquals(res.m10, 21.0, EPS);
|
||||
assertEquals(res.m01, 21.0, EPS);
|
||||
assertEquals(res.m20, 35.0, EPS);
|
||||
assertEquals(res.m11, 21.0, EPS);
|
||||
assertEquals(res.m02, 27.0, EPS);
|
||||
assertEquals(res.m30, 63.0, EPS);
|
||||
assertEquals(res.m21, 35.0, EPS);
|
||||
assertEquals(res.m12, 27.0, EPS);
|
||||
assertEquals(res.m03, 39.0, EPS);
|
||||
assertEquals(res.mu20, 14.0, EPS);
|
||||
assertEquals(res.mu11, 0.0, EPS);
|
||||
assertEquals(res.mu02, 6.0, EPS);
|
||||
assertEquals(res.mu30, 0.0, EPS);
|
||||
assertEquals(res.mu21, 0.0, EPS);
|
||||
assertEquals(res.mu12, 0.0, EPS);
|
||||
assertEquals(res.mu03, 0.0, EPS);
|
||||
assertEquals(res.nu20, 0.031746031746031744, EPS);
|
||||
assertEquals(res.nu11, 0.0, EPS);
|
||||
assertEquals(res.nu02, 0.013605442176870746, EPS);
|
||||
assertEquals(res.nu30, 0.0, EPS);
|
||||
assertEquals(res.nu21, 0.0, EPS);
|
||||
assertEquals(res.nu12, 0.0, EPS);
|
||||
assertEquals(res.nu03, 0.0, EPS);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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,42 @@
|
||||
{
|
||||
"whitelist":
|
||||
{
|
||||
"": [
|
||||
"findHomography",
|
||||
"estimateAffine2D",
|
||||
"getDefaultNewCameraMatrix",
|
||||
"initUndistortRectifyMap",
|
||||
"Rodrigues",
|
||||
"solvePnP",
|
||||
"solvePnPRansac",
|
||||
"solvePnPRefineLM",
|
||||
"projectPoints",
|
||||
"undistort",
|
||||
"fisheye_projectPoints",
|
||||
"approxPolyDP",
|
||||
"approxPolyN",
|
||||
"boundingRect",
|
||||
"minAreaRect",
|
||||
"minEnclosingCircle",
|
||||
"minEnclosingTriangle",
|
||||
"matchShapes",
|
||||
"convexHull",
|
||||
"convexityDefects",
|
||||
"isContourConvex",
|
||||
"intersectConvexConvex",
|
||||
"fitEllipse",
|
||||
"fitEllipseAMS",
|
||||
"fitEllipseDirect",
|
||||
"fitLine",
|
||||
"pointPolygonTest",
|
||||
"getAffineTransform",
|
||||
"getPerspectiveTransform",
|
||||
"getRotationMatrix2D",
|
||||
"HuMoments",
|
||||
"invertAffineTransform",
|
||||
"moments",
|
||||
"rotatedRectangleIntersection"
|
||||
],
|
||||
"UsacParams": ["UsacParams"]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"namespaces_dict": {
|
||||
"cv.fisheye": "fisheye"
|
||||
},
|
||||
"func_arg_fix" : {
|
||||
"Geometry" : {
|
||||
"minEnclosingCircle" : { "points" : {"ctype" : "vector_Point2f"} },
|
||||
"fitEllipse" : { "points" : {"ctype" : "vector_Point2f"} },
|
||||
"approxPolyDP" : { "curve" : {"ctype" : "vector_Point2f"},
|
||||
"approxCurve" : {"ctype" : "vector_Point2f"} },
|
||||
"arcLength" : { "curve" : {"ctype" : "vector_Point2f"} },
|
||||
"pointPolygonTest" : { "contour" : {"ctype" : "vector_Point2f"} },
|
||||
"minAreaRect" : { "points" : {"ctype" : "vector_Point2f"} },
|
||||
"getAffineTransform" : { "src" : {"ctype" : "vector_Point2f"},
|
||||
"dst" : {"ctype" : "vector_Point2f"} },
|
||||
"convexityDefects" : { "contour" : {"ctype" : "vector_Point"},
|
||||
"convexhull" : {"ctype" : "vector_int"},
|
||||
"convexityDefects" : {"ctype" : "vector_Vec4i"} },
|
||||
"isContourConvex" : { "contour" : {"ctype" : "vector_Point"} },
|
||||
"convexHull" : { "points" : {"ctype" : "vector_Point"},
|
||||
"hull" : {"ctype" : "vector_int"},
|
||||
"returnPoints" : {"ctype" : ""} },
|
||||
"matchShapes" : { "method" : {"ctype" : "ShapeMatchModes"}},
|
||||
"fitLine" : { "distType" : {"ctype" : "DistanceTypes"}}
|
||||
},
|
||||
"Subdiv2D" : {
|
||||
"(void)insert:(NSArray<Point2f*>*)ptvec" : { "insert" : {"name" : "insertVector"} }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,386 @@
|
||||
//
|
||||
// Calib3dTest.swift
|
||||
//
|
||||
// Created by Giles Payne on 2020/05/26.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
import OpenCV
|
||||
|
||||
class GeometryTest: 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])
|
||||
|
||||
Geometry.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 = Geometry.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])
|
||||
|
||||
Geometry.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()
|
||||
Geometry.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()
|
||||
Geometry.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])
|
||||
Geometry.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)
|
||||
|
||||
Geometry.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 = Geometry.getDefaultNewCameraMatrix(cameraMatrix: gray0)
|
||||
|
||||
XCTAssertFalse(mtx.empty())
|
||||
XCTAssertEqual(0, Core.countNonZero(src: mtx))
|
||||
}
|
||||
|
||||
func testGetDefaultNewCameraMatrixMatSizeBoolean() {
|
||||
let mtx = Geometry.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])
|
||||
|
||||
Geometry.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))
|
||||
|
||||
Geometry.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))
|
||||
|
||||
Geometry.undistortPoints(src: src, dst: dst, cameraMatrix: cameraMatrix, distCoeffs: distCoeffs)
|
||||
|
||||
XCTAssertEqual(src.toArray(), dst.toArray())
|
||||
}
|
||||
|
||||
func testApproxPolyDP() {
|
||||
let curve = [Point2f(x: 1, y: 3), Point2f(x: 2, y: 4), Point2f(x: 3, y: 5), Point2f(x: 4, y: 4), Point2f(x: 5, y: 3)]
|
||||
|
||||
var approxCurve = [Point2f]()
|
||||
|
||||
Geometry.approxPolyDP(curve: curve, approxCurve: &approxCurve, epsilon: OpenCVTestCase.EPS, closed: true)
|
||||
|
||||
let approxCurveGold = [Point2f(x: 1, y: 3), Point2f(x: 3, y: 5), Point2f(x: 5, y: 3)]
|
||||
|
||||
XCTAssert(approxCurve == approxCurveGold)
|
||||
}
|
||||
|
||||
func testArcLength() {
|
||||
let curve = [Point2f(x: 1, y: 3), Point2f(x: 2, y: 4), Point2f(x: 3, y: 5), Point2f(x: 4, y: 4), Point2f(x: 5, y: 3)]
|
||||
|
||||
let arcLength = Geometry.arcLength(curve: curve, closed: false)
|
||||
|
||||
XCTAssertEqual(5.656854249, arcLength, accuracy:0.000001)
|
||||
}
|
||||
|
||||
func testContourAreaMat() throws {
|
||||
let contour = Mat(rows: 1, cols: 4, type: CvType.CV_32FC2)
|
||||
try contour.put(row: 0, col: 0, data: [0, 0, 10, 0, 10, 10, 5, 4] as [Float])
|
||||
|
||||
let area = Geometry.contourArea(contour: contour)
|
||||
|
||||
XCTAssertEqual(45.0, area, accuracy: OpenCVTestCase.EPS)
|
||||
}
|
||||
|
||||
func testContourAreaMatBoolean() throws {
|
||||
let contour = Mat(rows: 1, cols: 4, type: CvType.CV_32FC2)
|
||||
try contour.put(row: 0, col: 0, data: [0, 0, 10, 0, 10, 10, 5, 4] as [Float])
|
||||
|
||||
let area = Geometry.contourArea(contour: contour, oriented: true)
|
||||
|
||||
XCTAssertEqual(45.0, area, accuracy: OpenCVTestCase.EPS)
|
||||
}
|
||||
|
||||
func testConvexHullMatMatBooleanBoolean() {
|
||||
let points = [Point(x: 2, y: 0),
|
||||
Point(x: 4, y: 0),
|
||||
Point(x: 3, y: 2),
|
||||
Point(x: 0, y: 2),
|
||||
Point(x: 2, y: 1),
|
||||
Point(x: 3, y: 1)]
|
||||
|
||||
var hull = [Int32]()
|
||||
|
||||
Geometry.convexHull(points: points, hull: &hull, clockwise: true)
|
||||
|
||||
XCTAssert([3, 2, 1, 0] == hull)
|
||||
}
|
||||
|
||||
func testConvexityDefects() throws {
|
||||
let points = [Point(x: 20, y: 0),
|
||||
Point(x: 40, y: 0),
|
||||
Point(x: 30, y: 20),
|
||||
Point(x: 0, y: 20),
|
||||
Point(x: 20, y: 10),
|
||||
Point(x: 30, y: 10)]
|
||||
|
||||
var hull = [Int32]()
|
||||
Geometry.convexHull(points: points, hull: &hull)
|
||||
|
||||
var convexityDefects = [Int4]()
|
||||
Geometry.convexityDefects(contour: points, convexhull: hull, convexityDefects: &convexityDefects)
|
||||
|
||||
XCTAssertTrue(Int4(v0: 3, v1: 0, v2: 5, v3: 3620) == convexityDefects[0])
|
||||
}
|
||||
|
||||
func testGetAffineTransform() throws {
|
||||
let src = [Point2f(x: 2, y: 3), Point2f(x: 3, y: 1), Point2f(x: 1, y: 4)]
|
||||
let dst = [Point2f(x: 3, y: 3), Point2f(x: 7, y: 4), Point2f(x: 5, y: 6)]
|
||||
|
||||
let transform = Geometry.getAffineTransform(src: src, dst: dst)
|
||||
|
||||
let truth = Mat(rows: 2, cols: 3, type: CvType.CV_64FC1)
|
||||
|
||||
try truth.put(row: 0, col: 0, data: [-8.0, -6.0, 37.0])
|
||||
try truth.put(row: 1, col: 0, data: [-7.0, -4.0, 29.0])
|
||||
try assertMatEqual(truth, transform, OpenCVTestCase.EPS)
|
||||
}
|
||||
|
||||
func testGetRotationMatrix2D() throws {
|
||||
let center = Point2f(x: 0, y: 0)
|
||||
|
||||
dst = Geometry.getRotationMatrix2D(center: center, angle: 0, scale: 1)
|
||||
|
||||
truth = Mat(rows: 2, cols: 3, type: CvType.CV_64F)
|
||||
try truth!.put(row: 0, col: 0, data: [1.0, 0.0, 0.0])
|
||||
try truth!.put(row: 1, col: 0, data: [0.0, 1.0, 0.0])
|
||||
|
||||
try assertMatEqual(truth!, dst, OpenCVTestCase.EPS)
|
||||
}
|
||||
|
||||
func testInvertAffineTransform() throws {
|
||||
let src = Mat(rows: 2, cols: 3, type: CvType.CV_64F, scalar: Scalar(1))
|
||||
|
||||
Geometry.invertAffineTransform(M: src, iM: dst)
|
||||
|
||||
truth = Mat(rows: 2, cols: 3, type: CvType.CV_64F, scalar: Scalar(0))
|
||||
try assertMatEqual(truth!, dst, OpenCVTestCase.EPS)
|
||||
}
|
||||
|
||||
func testIsContourConvex() {
|
||||
let contour1 = [Point(x: 0, y: 0), Point(x: 10, y: 0), Point(x: 10, y: 10), Point(x: 5, y: 4)]
|
||||
|
||||
XCTAssertFalse(Geometry.isContourConvex(contour: contour1))
|
||||
|
||||
let contour2 = [Point(x: 0, y: 0), Point(x: 10, y: 0), Point(x: 10, y: 10), Point(x: 5, y: 6)]
|
||||
|
||||
XCTAssert(Geometry.isContourConvex(contour: contour2))
|
||||
}
|
||||
|
||||
func testMinAreaRect() {
|
||||
let points = [Point2f(x: 1, y: 1), Point2f(x: 5, y: 1), Point2f(x: 4, y: 3), Point2f(x: 6, y: 2)]
|
||||
|
||||
let rrect = Geometry.minAreaRect(points: points)
|
||||
|
||||
XCTAssertEqual(Size2f(width: 5, height: 2), rrect.size)
|
||||
XCTAssertEqual(0.0, rrect.angle)
|
||||
XCTAssertEqual(Point2f(x: 3.5, y: 2), rrect.center)
|
||||
}
|
||||
|
||||
func testMinEnclosingCircle() {
|
||||
let points = [Point2f(x: 0, y: 0), Point2f(x: -100, y: 0), Point2f(x: 0, y: -100), Point2f(x: 100, y: 0), Point2f(x: 0, y: 100)]
|
||||
let actualCenter = Point2f()
|
||||
var radius:Float = 0
|
||||
|
||||
Geometry.minEnclosingCircle(points: points, center: actualCenter, radius: &radius)
|
||||
|
||||
XCTAssertEqual(Point2f(x: 0, y: 0), actualCenter)
|
||||
XCTAssertEqual(100.0, radius, accuracy: 1.0)
|
||||
}
|
||||
|
||||
func testPointPolygonTest() {
|
||||
let contour = [Point2f(x: 0, y: 0), Point2f(x: 1, y: 3), Point2f(x: 3, y: 4), Point2f(x: 4, y: 3), Point2f(x: 2, y: 1)]
|
||||
let sign1 = Geometry.pointPolygonTest(contour: contour, pt: Point2f(x: 2, y: 2), measureDist: false)
|
||||
XCTAssertEqual(1.0, sign1)
|
||||
|
||||
let sign2 = Geometry.pointPolygonTest(contour: contour, pt: Point2f(x: 4, y: 4), measureDist: true)
|
||||
XCTAssertEqual(-sqrt(0.5), sign2)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -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,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()
|
||||
Reference in New Issue
Block a user