提交 1098566a 编写于 作者: K Kirill Kornyakov

java api: fixed ctor in RotatedRect, added 114 tests by Hussein Abdinoor

上级 2bc9bca3
...@@ -8,9 +8,9 @@ import org.opencv.test.OpenCVTestCase; ...@@ -8,9 +8,9 @@ import org.opencv.test.OpenCVTestCase;
public class RotatedRectTest extends OpenCVTestCase { public class RotatedRectTest extends OpenCVTestCase {
private double angle;
private Point center; private Point center;
private Size size; private Size size;
private double angle;
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
...@@ -131,12 +131,25 @@ public class RotatedRectTest extends OpenCVTestCase { ...@@ -131,12 +131,25 @@ public class RotatedRectTest extends OpenCVTestCase {
public void testRotatedRect() { public void testRotatedRect() {
RotatedRect rr = new RotatedRect(); RotatedRect rr = new RotatedRect();
assertTrue(rr != null); assertTrue(rr != null);
assertTrue(rr.center != null);
assertTrue(rr.size != null);
assertTrue(rr.angle == 0.0);
} }
public void testRotatedRectDoubleArray() {
fail("Not yet implemented");
//public RotatedRect(double[] vals)
}
public void testRotatedRectPointSizeDouble() { public void testRotatedRectPointSizeDouble() {
RotatedRect rr = new RotatedRect(center, size, 40); RotatedRect rr = new RotatedRect(center, size, 40);
assertTrue(rr != null); assertTrue(rr != null);
assertTrue(rr.center != null);
assertTrue(rr.size != null);
assertTrue(rr.angle == 40.0);
} }
} }
...@@ -262,11 +262,12 @@ public class coreTest extends OpenCVTestCase { ...@@ -262,11 +262,12 @@ public class coreTest extends OpenCVTestCase {
Mat in = new Mat(1, 4, CvType.CV_32F); Mat in = new Mat(1, 4, CvType.CV_32F);
in.put(0, 0, 135.22211, 50.811096, 102.27016, 207.6682); in.put(0, 0, 135.22211, 50.811096, 102.27016, 207.6682);
Mat out = new Mat(1, 4, CvType.CV_32F);
out.put(0, 0, 247.98576, -61.252407, 94.904533, 14.013477); truth = new Mat(1, 4, CvType.CV_32F);
truth.put(0, 0, 247.98576, -61.252407, 94.904533, 14.013477);
Core.dct(in, dst); Core.dct(in, dst);
assertMatEqual(out, dst); assertMatEqual(truth, dst);
} }
public void testDctMatMatInt() { public void testDctMatMatInt() {
...@@ -276,7 +277,7 @@ public class coreTest extends OpenCVTestCase { ...@@ -276,7 +277,7 @@ public class coreTest extends OpenCVTestCase {
Mat in = new Mat(1, 8, CvType.CV_32F); Mat in = new Mat(1, 8, CvType.CV_32F);
in.put(0, 0, 0.203056, 0.980407, 0.35312, -0.106651, 0.0399382, 0.871475, -0.648355, 0.501067); in.put(0, 0, 0.203056, 0.980407, 0.35312, -0.106651, 0.0399382, 0.871475, -0.648355, 0.501067);
truth = new Mat(1, 8, CvType.CV_32F); truth = new Mat(1, 8, CvType.CV_32F);
truth.put(0, 0, 0.77571625, 0.37270021, 0.18529896, 0.012146413, -0.32499927, -0.99302113, 0.55979407, -0.6251272); truth.put(0, 0, 0.77571625, 0.37270021, 0.18529896, 0.012146413, -0.32499927, -0.99302113, 0.55979407, -0.6251272);
Core.dct(in, dst); Core.dct(in, dst);
...@@ -306,27 +307,26 @@ public class coreTest extends OpenCVTestCase { ...@@ -306,27 +307,26 @@ public class coreTest extends OpenCVTestCase {
public void testDftMatMatInt() { public void testDftMatMatInt() {
Mat src = new Mat(1, 4, CvType.CV_32F); Mat src = new Mat(1, 4, CvType.CV_32F);
Mat out = new Mat(1, 4, CvType.CV_32F); truth = new Mat(1, 4, CvType.CV_32F);
Mat out2 = new Mat(1, 4, CvType.CV_32F);
src.put(0, 0, 1, 2, 3, 4); src.put(0, 0, 1, 2, 3, 4);
out.put(0, 0, 10, -2, 2, -2); truth.put(0, 0, 10, -2, 2, -2);
Core.dft(src, dst, Core.DFT_REAL_OUTPUT); Core.dft(src, dst, Core.DFT_REAL_OUTPUT);
assertMatEqual(out, dst); assertMatEqual(truth, dst);
Core.dft(src, dst, Core.DFT_INVERSE); Core.dft(src, dst, Core.DFT_INVERSE);
out2.put(0, 0, 9, -9, 1, 3); truth.put(0, 0, 9, -9, 1, 3);
assertMatEqual(out2, dst); assertMatEqual(truth, dst);
} }
public void testDftMatMatIntInt() { public void testDftMatMatIntInt() {
Mat src = new Mat(1, 4, CvType.CV_32F); Mat src = new Mat(1, 4, CvType.CV_32F);
Mat out = new Mat(1, 4, CvType.CV_32F);
src.put(0, 0, 1, 2, 3, 4); src.put(0, 0, 1, 2, 3, 4);
out.put(0, 0, 10, -2, 2, -2);
truth = new Mat(1, 4, CvType.CV_32F);
truth.put(0, 0, 10, -2, 2, -2);
Core.dft(src, dst, Core.DFT_REAL_OUTPUT, 1); Core.dft(src, dst, Core.DFT_REAL_OUTPUT, 1);
assertMatEqual(out, dst); assertMatEqual(truth, dst);
} }
public void testDivideDoubleMatMat() { public void testDivideDoubleMatMat() {
...@@ -504,55 +504,56 @@ public class coreTest extends OpenCVTestCase { ...@@ -504,55 +504,56 @@ public class coreTest extends OpenCVTestCase {
} }
public void testIdctMatMat() { public void testIdctMatMat() {
Mat in = new Mat(1, 8, CvType.CV_32F); Mat in = new Mat(1, 8, CvType.CV_32F);
Mat out = new Mat(1, 8, CvType.CV_32F);
in.put(0, 0, 1.0, 2.0, 1.0, 0.0, 1.0, 2.0, 3.0, 1.0); in.put(0, 0, 1.0, 2.0, 1.0, 0.0, 1.0, 2.0, 3.0, 1.0);
out.put(0, 0, 3.3769724, -1.6215782, 2.3608727, 0.20730907, -0.86502546, 0.028082132, -0.7673766, 0.10917115);
truth = new Mat(1, 8, CvType.CV_32F);
truth.put(0, 0, 3.3769724, -1.6215782, 2.3608727, 0.20730907, -0.86502546, 0.028082132, -0.7673766, 0.10917115);
Core.idct(in, dst); Core.idct(in, dst);
assertMatEqual(out, dst); assertMatEqual(truth, dst);
} }
public void testIdctMatMatInt() { public void testIdctMatMatInt() {
Mat in = new Mat(1, 8, CvType.CV_32F); Mat in = new Mat(1, 8, CvType.CV_32F);
Mat out = new Mat(1, 8, CvType.CV_32F);
in.put(0, 0, 1.0, 2.0, 1.0, 0.0, 1.0, 2.0, 3.0, 1.0); in.put(0, 0, 1.0, 2.0, 1.0, 0.0, 1.0, 2.0, 3.0, 1.0);
out.put(0, 0, 3.3769724, -1.6215782, 2.3608727, 0.20730907, -0.86502546, 0.028082132, -0.7673766, 0.10917115);
truth = new Mat(1, 8, CvType.CV_32F);
truth.put(0, 0, 3.3769724, -1.6215782, 2.3608727, 0.20730907, -0.86502546, 0.028082132, -0.7673766, 0.10917115);
Core.idct(in, dst, Core.DCT_ROWS); Core.idct(in, dst, Core.DCT_ROWS);
assertMatEqual(out, dst); assertMatEqual(truth, dst);
} }
public void testIdftMatMat() { public void testIdftMatMat() {
Mat in = new Mat(1, 4, CvType.CV_32F); Mat in = new Mat(1, 4, CvType.CV_32F);
Mat out = new Mat(1, 4, CvType.CV_32F);
in.put(0, 0, 1.0, 2.0, 3.0, 4.0); in.put(0, 0, 1.0, 2.0, 3.0, 4.0);
out.put(0, 0, 9, -9, 1, 3);
truth = new Mat(1, 4, CvType.CV_32F);
truth.put(0, 0, 9, -9, 1, 3);
Core.idft(in, dst); Core.idft(in, dst);
assertMatEqual(out, dst); assertMatEqual(truth, dst);
} }
public void testIdftMatMatInt() { public void testIdftMatMatInt() {
Mat in = new Mat(1, 4, CvType.CV_32F); Mat in = new Mat(1, 4, CvType.CV_32F);
Mat out = new Mat(1, 4, CvType.CV_32F);
in.put(0, 0, 1.0, 2.0, 3.0, 4.0); in.put(0, 0, 1.0, 2.0, 3.0, 4.0);
out.put(0, 0, 9, -9, 1, 3);
truth = new Mat(1, 4, CvType.CV_32F);
truth.put(0, 0, 9, -9, 1, 3);
Core.idft(in, dst, Core.DFT_REAL_OUTPUT); Core.idft(in, dst, Core.DFT_REAL_OUTPUT);
assertMatEqual(out, dst); assertMatEqual(truth, dst);
} }
public void testIdftMatMatIntInt() { public void testIdftMatMatIntInt() {
Mat in = new Mat(1, 4, CvType.CV_32F); Mat in = new Mat(1, 4, CvType.CV_32F);
Mat out = new Mat(1, 4, CvType.CV_32F);
in.put(0, 0, 1.0, 2.0, 3.0, 4.0); in.put(0, 0, 1.0, 2.0, 3.0, 4.0);
out.put(0, 0, 9, -9, 1, 3);
truth = new Mat(1, 4, CvType.CV_32F);
truth.put(0, 0, 9, -9, 1, 3);
Core.idft(in, dst, Core.DFT_REAL_OUTPUT, 1); Core.idft(in, dst, Core.DFT_REAL_OUTPUT, 1);
assertMatEqual(out, dst); assertMatEqual(truth, dst);
} }
public void testInRange() { public void testInRange() {
...@@ -575,14 +576,14 @@ public class coreTest extends OpenCVTestCase { ...@@ -575,14 +576,14 @@ public class coreTest extends OpenCVTestCase {
src.put(1, 0, 1.5); src.put(1, 0, 1.5);
src.put(1, 1, 4.0); src.put(1, 1, 4.0);
Mat answer = new Mat(2, 2, CvType.CV_32F); truth = new Mat(2, 2, CvType.CV_32F);
answer.put(0, 0, 4.0); truth.put(0, 0, 4.0);
answer.put(0, 1, -2.0); truth.put(0, 1, -2.0);
answer.put(1, 0, -1.5); truth.put(1, 0, -1.5);
answer.put(1, 1, 1.0); truth.put(1, 1, 1.0);
Core.invert(src, dst); Core.invert(src, dst);
assertMatEqual(answer, dst); assertMatEqual(truth, dst);
//TODO: needs epsilon comparison //TODO: needs epsilon comparison
// Mat m = grayRnd_32f.clone(); // Mat m = grayRnd_32f.clone();
...@@ -592,20 +593,14 @@ public class coreTest extends OpenCVTestCase { ...@@ -592,20 +593,14 @@ public class coreTest extends OpenCVTestCase {
} }
public void testInvertMatMatInt() { public void testInvertMatMatInt() {
Mat src = new Mat(3, 3, CvType.CV_32F); Mat src = Mat.eye(3, 3, CvType.CV_32FC1);
Mat out = new Mat(3, 3, CvType.CV_32F);
src.put(0, 0, 1, 0, 0);
src.put(1, 0, 0, 1, 0);
src.put(2, 0, 0, 0, 1);
out.put(0, 0, 1, 0, 0); truth = Mat.eye(3, 3, CvType.CV_32FC1);
out.put(1, 0, 0, 1, 0);
out.put(2, 0, 0, 0, 1);
Core.invert(src, dst,Core.DECOMP_CHOLESKY); Core.invert(src, dst, Core.DECOMP_CHOLESKY);
assertMatEqual(out, dst); assertMatEqual(truth, dst);
Core.invert(src, dst,Core.DECOMP_LU); Core.invert(src, dst, Core.DECOMP_LU);
double det = Core.determinant(src); double det = Core.determinant(src);
assertTrue(det > 0.0); assertTrue(det > 0.0);
} }
...@@ -1196,11 +1191,11 @@ public class coreTest extends OpenCVTestCase { ...@@ -1196,11 +1191,11 @@ public class coreTest extends OpenCVTestCase {
coeffs.put(0, 0, -6, 11, -6, 1); coeffs.put(0, 0, -6, 11, -6, 1);
Mat answer = new Mat(3, 1, CvType.CV_32FC2); truth = new Mat(3, 1, CvType.CV_32FC2);
answer.put(0, 0, 1, 0, 2, 0, 3, 0); truth.put(0, 0, 1, 0, 2, 0, 3, 0);
Core.solvePoly(coeffs, roots); Core.solvePoly(coeffs, roots);
assertMatEqual(answer, roots); assertMatEqual(truth, roots);
} }
public void testSolvePolyMatMatInt() { public void testSolvePolyMatMatInt() {
...@@ -1209,11 +1204,11 @@ public class coreTest extends OpenCVTestCase { ...@@ -1209,11 +1204,11 @@ public class coreTest extends OpenCVTestCase {
coeffs.put(0, 0, -6, 11, -6, 1); coeffs.put(0, 0, -6, 11, -6, 1);
Mat answer = new Mat(3, 1, CvType.CV_32FC2); truth = new Mat(3, 1, CvType.CV_32FC2);
answer.put(0, 0, 1, 0, -1, 2, -2, 12); truth.put(0, 0, 1, 0, -1, 2, -2, 12);
Core.solvePoly(coeffs, roots, 1); Core.solvePoly(coeffs, roots, 1);
assertMatEqual(answer, roots); assertMatEqual(truth, roots);
} }
public void testSort() { public void testSort() {
...@@ -1233,13 +1228,13 @@ public class coreTest extends OpenCVTestCase { ...@@ -1233,13 +1228,13 @@ public class coreTest extends OpenCVTestCase {
Mat a = Mat.eye(3, 3, CvType.CV_8UC1); Mat a = Mat.eye(3, 3, CvType.CV_8UC1);
Mat b = new Mat(); Mat b = new Mat();
Mat answer = new Mat(3, 3, CvType.CV_32SC1); truth = new Mat(3, 3, CvType.CV_32SC1);
answer.put(0, 0, 1, 2, 0); truth.put(0, 0, 1, 2, 0);
answer.put(1, 0, 0, 2, 1); truth.put(1, 0, 0, 2, 1);
answer.put(2, 0, 0, 1, 2); truth.put(2, 0, 0, 1, 2);
Core.sortIdx(a, b, 0+0/*TODO: CV_SORT_EVERY_ROW + CV_SORT_ASCENDING*/); Core.sortIdx(a, b, 0+0/*TODO: CV_SORT_EVERY_ROW + CV_SORT_ASCENDING*/);
assertMatEqual(answer, b); assertMatEqual(truth, b);
} }
public void testSplit() { public void testSplit() {
...@@ -1297,8 +1292,8 @@ public class coreTest extends OpenCVTestCase { ...@@ -1297,8 +1292,8 @@ public class coreTest extends OpenCVTestCase {
Mat m = Mat.eye(2, 2, CvType.CV_32FC1); Mat m = Mat.eye(2, 2, CvType.CV_32FC1);
Core.transform(src, dst, m); Core.transform(src, dst, m);
Mat answer = new Mat(2, 2, CvType.CV_32FC2, new Scalar(55, 1)); truth = new Mat(2, 2, CvType.CV_32FC2, new Scalar(55, 1));
assertMatEqual(answer, dst); assertMatEqual(truth, dst);
} }
public void testTranspose() { public void testTranspose() {
......
...@@ -8,7 +8,9 @@ public class RotatedRect { ...@@ -8,7 +8,9 @@ public class RotatedRect {
public double angle; public double angle;
public RotatedRect() { public RotatedRect() {
this.angle=0; this.center = new Point();
this.size = new Size();
this.angle = 0;
} }
public RotatedRect(Point c, Size s, double a) { public RotatedRect(Point c, Size s, double a) {
...@@ -21,6 +23,7 @@ public class RotatedRect { ...@@ -21,6 +23,7 @@ public class RotatedRect {
this(); this();
set(vals); set(vals);
} }
public void set(double[] vals) { public void set(double[] vals) {
if(vals!=null) { if(vals!=null) {
center.x = vals.length>0 ? (int)vals[0] : 0; center.x = vals.length>0 ? (int)vals[0] : 0;
...@@ -73,12 +76,10 @@ public class RotatedRect { ...@@ -73,12 +76,10 @@ public class RotatedRect {
return r; return r;
} }
public RotatedRect clone() { public RotatedRect clone() {
return new RotatedRect(center, size, angle); return new RotatedRect(center, size, angle);
} }
@Override @Override
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册