java tests: commited tests by Hussein Abdinoor

This commit is contained in:
Kirill Kornyakov 2011-07-16 10:25:05 +00:00
parent f2e1a64c1b
commit eafa837e34
2 changed files with 490 additions and 167 deletions

View File

@ -7,6 +7,7 @@ import org.opencv.Scalar;
import org.opencv.core; import org.opencv.core;
import org.opencv.test.OpenCVTestCase; import org.opencv.test.OpenCVTestCase;
import org.opencv.test.OpenCVTestRunner;
public class coreTest extends OpenCVTestCase { public class coreTest extends OpenCVTestCase {
@ -109,11 +110,39 @@ public class coreTest extends OpenCVTestCase {
} }
public void testCartToPolarMatMatMatMat() { public void testCartToPolarMatMatMatMat() {
fail("Not yet implemented"); Mat x = new Mat(1, 3, CvType.CV_32F);
Mat y = new Mat(1, 3, CvType.CV_32F);
Mat magnitude = new Mat(1, 3, CvType.CV_32F);
Mat angle = new Mat(1, 3, CvType.CV_32F);
Mat dst_angle = new Mat();
x.put(0, 0, 3.0, 6.0, 5,0);
y.put(0, 0, 4.0, 8.0, 12.0);
magnitude.put(0, 0, 5.0, 10.0, 13.0);
angle.put(0, 0, 0.92729962, 0.92729962, 1.1759995);
core.cartToPolar(x, y, dst, dst_angle);
assertMatEqual(magnitude, dst);
assertMatEqual(angle, dst_angle);
} }
public void testCartToPolarMatMatMatMatBoolean() { public void testCartToPolarMatMatMatMatBoolean() {
fail("Not yet implemented"); Mat x = new Mat(1, 3, CvType.CV_32F);
Mat y = new Mat(1, 3, CvType.CV_32F);
Mat magnitude = new Mat(1, 3, CvType.CV_32F);
Mat angle = new Mat(1, 3, CvType.CV_32F);
Mat dst_angle = new Mat();
x.put(0 ,0, 3.0, 6.0, 5,0);
y.put(0 ,0, 4.0, 8.0, 12.0);
magnitude.put(0 ,0, 5.0, 10.0, 13.0);
angle.put(0 ,0, 0.92729962, 0.92729962, 1.1759995);
core.cartToPolar(x, y, dst, dst_angle,false);
assertMatEqual(magnitude, dst);
OpenCVTestRunner.Log(dst_angle.dump());
assertMatEqual(angle, dst_angle);
} }
public void testCircleMatPointIntScalar() { public void testCircleMatPointIntScalar() {
@ -220,9 +249,11 @@ public class coreTest extends OpenCVTestCase {
assertMatEqual(gray0_32f_1d, dst); assertMatEqual(gray0_32f_1d, dst);
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);
Mat out = new Mat(1, 8, CvType.CV_32F); Mat out = new Mat(1, 8, CvType.CV_32F);
out.put(0,0,0.775716, 0.3727, 0.185299, 0.0121461, -0.325, -0.993021, 0.559794, -0.625127);
in.put(0, 0, 0.203056, 0.980407, 0.35312, -0.106651, 0.0399382, 0.871475, -0.648355, 0.501067);
out.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);
assertMatEqual(out, dst); assertMatEqual(out, dst);
} }
@ -233,20 +264,44 @@ public class coreTest extends OpenCVTestCase {
mat.put(0, 1, 2.0); mat.put(0, 1, 2.0);
mat.put(1, 0, 4.0); mat.put(1, 0, 4.0);
mat.put(1, 1, 4.0); mat.put(1, 1, 4.0);
double det = core.determinant(mat); double det = core.determinant(mat);
assertEquals(8.0, det); assertEquals(8.0, det);
} }
public void testDftMatMat() { public void testDftMatMat() {
fail("Not yet implemented"); Mat src = new Mat(1, 4, CvType.CV_32F);
src.put(0, 0, 0, 0, 0, 0);
Mat out = new Mat(1, 4, CvType.CV_32F);
out.put(0, 0, 0, 0, 0, 0);
core.dft(src, dst);
assertMatEqual(out, dst);
} }
public void testDftMatMatInt() { public void testDftMatMatInt() {
fail("Not yet implemented"); Mat src = new Mat(1, 4, CvType.CV_32F);
Mat out = new Mat(1, 4, CvType.CV_32F);
Mat out2 = new Mat(1, 4, CvType.CV_32F);
src.put(0, 0, 1, 2, 3, 4);
out.put(0 , 0, 10, -2, 2, -2);
core.dft(src, dst, core.DFT_REAL_OUTPUT);
assertMatEqual(out, dst);
core.dft(src, dst, core.DFT_INVERSE);
out2.put(0 , 0, 9, -9, 1, 3);
assertMatEqual(out2, dst);
} }
public void testDftMatMatIntInt() { public void testDftMatMatIntInt() {
fail("Not yet implemented"); 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);
out.put(0 , 0, 10, -2, 2, -2);
core.dft(src, dst, core.DFT_REAL_OUTPUT, 1);
assertMatEqual(out, dst);
} }
public void testDivideDoubleMatMat() { public void testDivideDoubleMatMat() {
@ -308,7 +363,6 @@ public class coreTest extends OpenCVTestCase {
float res2 = core.fastAtan2(80, 20); float res2 = core.fastAtan2(80, 20);
assertEquals(75.96, res2, delta); assertEquals(75.96, res2, delta);
} }
public void testFlip() { public void testFlip() {
@ -336,37 +390,47 @@ public class coreTest extends OpenCVTestCase {
} }
public void testGemmMatMatDoubleMatDoubleMat() { public void testGemmMatMatDoubleMatDoubleMat() {
fail("Not yet implemented."); Mat m1 = new Mat(2, 2, CvType.CV_32FC1);
// Mat m1 = new Mat(2,2, CvType.CV_32FC1); Mat m2 = new Mat(2, 2, CvType.CV_32FC1);
// Mat m2 = new Mat(2,2, CvType.CV_32FC1); Mat desired = new Mat(2, 2, CvType.CV_32FC1);
// Mat des = new Mat(2,2, CvType.CV_32FC1); Mat dmatrix = new Mat(2, 2, CvType.CV_32FC1);
// Mat dmatrix = new Mat(2,2, CvType.CV_32FC1);
// m1.put(0, 0, 1.0); m1.put(0, 0, 1.0, 0.0);
// m1.put(0, 1, 0.0); m1.put(1, 0, 1.0, 0.0);
// m1.put(1, 0, 1.0);
// m1.put(1, 1, 0.0); m2.put(0, 0, 1.0, 0.0);
// m2.put(1, 0, 1.0, 0.0);
// m2.put(0, 0, 1.0);
// m2.put(0, 1, 0.0); dmatrix.put(0, 0, 0.001, 0.001);
// m2.put(1, 0, 1.0); dmatrix.put(1, 0, 0.001, 0.001);
// m2.put(1, 1, 0.0);
// desired.put(0, 0, 1.001, 0.001);
// dmatrix.put(0, 0, 0.001); desired.put(1, 0, 1.001, 0.001);
// dmatrix.put(0, 1, 0.001);
// dmatrix.put(1, 0, 0.001); core.gemm(m1, m2, 1.0, dmatrix, 1.0, dst);
// dmatrix.put(1, 1, 0.001); assertMatEqual(desired, dst);
// }
// des.put(0, 0, 1.001);
// des.put(0, 1, 1.001); public void testGemmMatMatDoubleMatDoubleMatInt() {
// des.put(1, 0, 1.001); Mat m1 = new Mat(2, 2, CvType.CV_32FC1);
// des.put(1, 1, 1.001); Mat m2 = new Mat(2, 2, CvType.CV_32FC1);
// Mat desired = new Mat(2, 2, CvType.CV_32FC1);
//// OpenCVTestRunner.Log(dst_gray_32f.dump()); Mat dmatrix = new Mat(2, 2, CvType.CV_32FC1);
//
// core.gemm(m1, m2, 1.0, dmatrix, 1.0, dst_gray_32f); m1.put(0, 0, 1.0, 0.0);
// OpenCVTestRunner.Log(dst_gray_32f.dump()); m1.put(1, 0, 1.0, 0.0);
// OpenCVTestRunner.Log(des.dump());
// assertMatEqual(des,dst_gray_32f); m2.put(0, 0, 1.0, 0.0);
m2.put(1, 0, 1.0, 0.0);
dmatrix.put(0, 0, 0.001, 0.001);
dmatrix.put(1, 0, 0.001, 0.001);
desired.put(0, 0, 2.001, 0.001);
desired.put(1, 0, 0.001, 0.001);
core.gemm(m1, m2, 1.0, dmatrix, 1.0, dst, core.GEMM_1_T);
assertMatEqual(desired, dst);
} }
public void testGetOptimalDFTSize() { public void testGetOptimalDFTSize() {
@ -388,36 +452,63 @@ public class coreTest extends OpenCVTestCase {
public void testHconcat() { public void testHconcat() {
Mat e = Mat.eye(3, 3, CvType.CV_8UC1); Mat e = Mat.eye(3, 3, CvType.CV_8UC1);
Mat eConcat = new Mat(1, 9, CvType.CV_8UC1); Mat eConcat = new Mat(1, 9, CvType.CV_8UC1);
e.put(0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1);
eConcat.put(0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1); eConcat.put(0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1);
core.hconcat(e, dst); core.hconcat(e, dst);
assertMatEqual(eConcat, dst); assertMatEqual(eConcat, dst);
} }
public void testIdctMatMat() { public void testIdctMatMat() {
Mat in = new Mat(1, 8, CvType.CV_32F); Mat in = 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);
Mat out = new Mat(1, 8, CvType.CV_32F); Mat out = new Mat(1, 8, CvType.CV_32F);
out.put(0, 0, 3.88909,-0.791065, 0.844623, 0.865723, -1.76777, -0.0228873, -0.732538, 0.352443); 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);
core.idct(in, dst); core.idct(in, dst);
assertMatEqual(out, dst); assertMatEqual(out, dst);
} }
public void testIdctMatMatInt() { public void testIdctMatMatInt() {
fail("Not yet implemented"); 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);
out.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);
assertMatEqual(out, dst);
} }
public void testIdftMatMat() { public void testIdftMatMat() {
fail("Not yet implemented"); 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);
out.put(0, 0, 9, -9, 1, 3);
core.idft(in, dst);
assertMatEqual(out, dst);
} }
public void testIdftMatMatInt() { public void testIdftMatMatInt() {
fail("Not yet implemented"); 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);
out.put(0, 0, 9, -9, 1, 3);
core.idft(in, dst, core.DFT_REAL_OUTPUT);
assertMatEqual(out, dst);
} }
public void testIdftMatMatIntInt() { public void testIdftMatMatIntInt() {
fail("Not yet implemented"); 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);
out.put(0, 0, 9, -9, 1, 3);
core.idft(in, dst, core.DFT_REAL_OUTPUT, 1);
assertMatEqual(out, dst);
} }
public void testInRange() { public void testInRange() {
@ -435,22 +526,46 @@ public class coreTest extends OpenCVTestCase {
public void testInvertMatMat() { public void testInvertMatMat() {
Mat src = new Mat(2, 2, CvType.CV_32F); Mat src = new Mat(2, 2, CvType.CV_32F);
Mat des = new Mat(2, 2, CvType.CV_32F);
src.put(0, 0, 1.0); src.put(0, 0, 1.0);
src.put(0, 1, 2.0); src.put(0, 1, 2.0);
src.put(1, 0, 1.5); src.put(1, 0, 1.5);
src.put(1, 1, 4.0); src.put(1, 1, 4.0);
des.put(0, 0, -2.0); Mat answer = new Mat(2, 2, CvType.CV_32F);
des.put(0, 1, 1.0); answer.put(0, 0, 4.0);
des.put(1, 0, 1.5); answer.put(0, 1, -2.0);
des.put(1, 1, -0.5); answer.put(1, 0, -1.5);
answer.put(1, 1, 1.0);
core.invert(src, dst); core.invert(src, dst);
assertMatEqual(des, dst); OpenCVTestRunner.Log(answer.dump());
OpenCVTestRunner.Log(dst.dump());
assertMatEqual(answer, dst);
//TODO: needs epsilon comparison
// Mat m = grayRnd_32f.clone();
// Mat inv = m.inv();
// core.gemm(m, inv, 1.0, new Mat(), 0.0, dst);
// assertMatEqual(grayE_32f, dst);
} }
public void testInvertMatMatInt() { public void testInvertMatMatInt() {
fail("Not yet implemented"); Mat src = new Mat(3, 3, CvType.CV_32F);
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);
out.put(1, 0, 0, 1, 0);
out.put(2, 0, 0, 0, 1);
core.invert(src, dst,core.DECOMP_CHOLESKY);
assertMatEqual(out, dst);
core.invert(src, dst,core.DECOMP_LU);
double det = core.determinant(src);
assertTrue(det > 0.0);
} }
public void testLineMatPointPointScalar() { public void testLineMatPointPointScalar() {
@ -466,7 +581,15 @@ public class coreTest extends OpenCVTestCase {
} }
public void testLineMatPointPointScalarInt() { public void testLineMatPointPointScalarInt() {
fail("Not yet implemented"); int nPoints = Math.min(gray0.cols(), gray0.rows());
Point point1 = new Point(0, 0);
Point point2 = new Point(nPoints, nPoints);
Scalar color = new Scalar(255);
assertTrue(0 == core.countNonZero(gray0));
core.line(gray0, point1, point2, color, 0);
assertTrue(nPoints == core.countNonZero(gray0));
} }
public void testLineMatPointPointScalarIntInt() { public void testLineMatPointPointScalarIntInt() {
@ -500,33 +623,24 @@ public class coreTest extends OpenCVTestCase {
} }
public void testLUTMatMatMatInt() { public void testLUTMatMatMatInt() {
fail("Not yet implemented"); Mat lut = new Mat(1, 256, CvType.CV_8UC1);
lut.setTo(new Scalar(255));
core.LUT(grayRnd, lut, dst, 0);
assertMatEqual(gray255, dst);
} }
public void testMagnitude() { public void testMagnitude() {
/*Mat x = new Mat(1, 4, Mat.CvType.CV_32FC1); Mat x = new Mat(1, 4, CvType.CV_32F);
Mat y = new Mat(1, 4, Mat.CvType.CV_32FC1); Mat y = new Mat(1, 4, CvType.CV_32F);
Mat dst = new Mat(1, 4, Mat.CvType.CV_32FC1); Mat out = new Mat(1, 4, CvType.CV_32F);
x.put(0, 0, 3.0, 5.0, 9.0, 6.0); x.put(0, 0, 3.0, 5.0, 9.0, 6.0);
y.put(0, 0, 4.0, 12.0, 40.0, 8.0); y.put(0, 0, 4.0, 12.0, 40.0, 8.0);
dst.put(0, 0, 5.0, 13,0, 41.0, 10.0); out.put(0, 0, 5.0, 13.0, 41.0, 10.0);
core.magnitude(x, y, dst_gray); core.magnitude(x, y, dst);
assertMatEqual(dst,dst_gray); assertMatEqual(out,dst);
*/
//fails for the above case, why?
/*Mat x = new Mat(1, 1, Mat.CvType.CV_32FC1);
Mat y = new Mat(1, 1, Mat.CvType.CV_32FC1);
Mat dst = new Mat(1, 1, Mat.CvType.CV_32FC1);
x.put(0, 0, 3.0);
y.put(0, 0, 4.0);
dst.put(0, 0, 5.0);
core.magnitude(x, y, dst_gray);
assertMatEqual(dst,dst_gray);
*/
core.magnitude(gray0_32f, gray255_32f, dst); core.magnitude(gray0_32f, gray255_32f, dst);
assertMatEqual(gray255_32f, dst); assertMatEqual(gray255_32f, dst);
} }
@ -563,11 +677,37 @@ public class coreTest extends OpenCVTestCase {
} }
public void testMeanStdDevMatMatMat() { public void testMeanStdDevMatMatMat() {
fail("Not yet implemented"); Mat mean = new Mat();
Mat stddev = new Mat();
core.meanStdDev(rgba0, mean, stddev);
assertEquals(0, core.countNonZero(mean));
assertEquals(0, core.countNonZero(stddev));
} }
public void testMeanStdDevMatMatMatMat() { public void testMeanStdDevMatMatMatMat() {
fail("Not yet implemented"); Mat mean = new Mat();
Mat stddev = new Mat();
core.meanStdDev(rgba0, mean, stddev, gray255);
assertEquals(0, core.countNonZero(mean));
assertEquals(0, core.countNonZero(stddev));
Mat submat = grayRnd.submat(0, grayRnd.rows()/2, 0, grayRnd.cols()/2);
submat.setTo(new Scalar(33));
Mat mask = gray0.clone();
submat = mask.submat(0, mask.rows()/2, 0, mask.cols()/2);
submat.setTo(new Scalar(1));
core.meanStdDev(grayRnd, mean, stddev, mask);
Mat desiredMean = new Mat(1, 1, CvType.CV_64F, new Scalar(33));
assertMatEqual(desiredMean, mean);
assertEquals(0, core.countNonZero(stddev));
core.meanStdDev(grayRnd, mean, stddev, gray1);
assertTrue(0 != core.countNonZero(mean));
assertTrue(0 != core.countNonZero(stddev));
} }
public void testMin() { public void testMin() {
@ -578,27 +718,39 @@ public class coreTest extends OpenCVTestCase {
public void testMinMaxLoc() { public void testMinMaxLoc() {
double minVal = 1; double minVal = 1;
double maxVal = 10; double maxVal = 10;
Point minLoc = new Point((int)matSize/4, (int)matSize/2); Point minLoc = new Point(gray3.cols()/4, gray3.rows()/2);
Point maxLoc = new Point((int)matSize/2, (int)matSize/4); Point maxLoc = new Point(gray3.cols()/2, gray3.rows()/4);
gray3.put((int)minLoc.y, (int)minLoc.x, minVal); gray3.put((int)minLoc.y, (int)minLoc.x, minVal);
gray3.put((int)maxLoc.y, (int)maxLoc.x, maxVal); gray3.put((int)maxLoc.y, (int)maxLoc.x, maxVal);
core.MinMaxLocResult mmres = core.minMaxLoc(gray3); core.MinMaxLocResult mmres = core.minMaxLoc(gray3);
assertTrue(mmres.minVal==minVal assertTrue(mmres.minVal == minVal);
&& mmres.maxVal==maxVal assertTrue(mmres.maxVal == maxVal);
&& mmres.minLoc.equals(minLoc) assertTrue(mmres.minLoc.equals(minLoc));
&& mmres.maxLoc.equals(maxLoc)); assertTrue(mmres.maxLoc.equals(maxLoc));
} }
public void testMulSpectrumsMatMatMatInt() { public void testMulSpectrumsMatMatMatInt() {
//nice example Mat src1 = new Mat(1, 4, CvType.CV_32F);
fail("Not yet implemented"); Mat src2 = new Mat(1, 4, CvType.CV_32F);
Mat out = new Mat(1, 4, CvType.CV_32F);
src1.put(0, 0, 1.0, 2.0, 3.0, 4.0);
src2.put(0, 0, 1.0, 2.0, 3.0, 4.0);
out.put(0, 0, 1, -5, 12, 16);
core.mulSpectrums(src1, src2, dst, core.DFT_ROWS);
assertMatEqual(out, dst);
} }
public void testMulSpectrumsMatMatMatIntBoolean() { public void testMulSpectrumsMatMatMatIntBoolean() {
fail("Not yet implemented"); Mat src1 = new Mat(1, 4, CvType.CV_32F);
Mat src2 = new Mat(1, 4, CvType.CV_32F);
Mat out = new Mat(1, 4, CvType.CV_32F);
src1.put(0, 0, 1.0, 2.0, 3.0, 4.0);
src2.put(0, 0, 1.0, 2.0, 3.0, 4.0);
out.put(0, 0, 1, 13, 0, 16);
core.mulSpectrums(src1, src2, dst, core.DFT_ROWS, true);
assertMatEqual(out, dst);
} }
public void testMultiplyMatMatMat() { public void testMultiplyMatMatMat() {
@ -640,31 +792,66 @@ public class coreTest extends OpenCVTestCase {
} }
public void testMulTransposedMatMatBooleanMatDoubleInt() { public void testMulTransposedMatMatBooleanMatDoubleInt() {
fail("Not yet implemented"); Mat a = new Mat(3, 3, CvType.CV_32F);
Mat grayDelta = new Mat(3, 3, CvType.CV_8U);
grayDelta.setTo(new Scalar(0.0001));
Mat res = new Mat(3, 3, CvType.CV_32F);
a.put(0, 0, 1, 1, 1);
a.put(1, 0, 1, 1, 1);
a.put(2, 0, 1, 1, 1);
res.put(0, 0, 3, 3, 3);
res.put(1, 0, 3, 3, 3);
res.put(2, 0, 3, 3, 3);
core.mulTransposed(a, dst, true, grayDelta, 1.0, 1);
assertMatEqual(res, dst);
} }
public void testNormalizeMatMat() { public void testNormalizeMatMat() {
fail("Not yet implemented"); core.normalize(gray0, dst);
assertMatEqual(gray0, dst);
} }
public void testNormalizeMatMatDouble() { public void testNormalizeMatMatDouble() {
fail("Not yet implemented"); core.normalize(gray0, dst, 0.0);
assertMatEqual(gray0, dst);
} }
public void testNormalizeMatMatDoubleDouble() { public void testNormalizeMatMatDoubleDouble() {
fail("Not yet implemented"); core.normalize(gray0, dst, 0.0, 1.0);
assertMatEqual(gray0, dst);
} }
public void testNormalizeMatMatDoubleDoubleInt() { public void testNormalizeMatMatDoubleDoubleInt() {
fail("Not yet implemented"); Mat src = new Mat(1, 4, CvType.CV_32F);
Mat out = new Mat(1, 4, CvType.CV_32F);
src.put(0, 0, 1.0, 2.0, 3.0, 4.0);
out.put(0, 0, 0.25, 0.5, 0.75, 1);
core.normalize(src, dst, 1.0, 2.0, core.NORM_INF);
assertMatEqual(out, dst);
} }
public void testNormalizeMatMatDoubleDoubleIntInt() { public void testNormalizeMatMatDoubleDoubleIntInt() {
fail("Not yet implemented"); Mat src = new Mat(1, 4, CvType.CV_32F);
Mat out = new Mat(1, 4, CvType.CV_32F);
src.put(0, 0, 1.0, 2.0, 3.0, 4.0);
out.put(0, 0, 0.25, 0.5, 0.75, 1);
core.normalize(src, dst, 1.0, 2.0, core.NORM_INF, -1);
assertMatEqual(out, dst);
} }
public void testNormalizeMatMatDoubleDoubleIntIntMat() { public void testNormalizeMatMatDoubleDoubleIntIntMat() {
fail("Not yet implemented"); Mat src = new Mat(1, 4, CvType.CV_32F);
Mat out = new Mat(1, 4, CvType.CV_32F);
Mat mask = new Mat(1, 4, CvType.CV_8U, new Scalar(1));
src.put(0, 0, 1.0, 2.0, 3.0, 4.0);
out.put(0, 0, 0.25, 0.5, 0.75, 1);
core.normalize(src, dst, 1.0, 2.0, core.NORM_INF, -1, mask);
assertMatEqual(out, dst);
} }
public void testNormMat() { public void testNormMat() {
@ -703,15 +890,58 @@ public class coreTest extends OpenCVTestCase {
} }
public void testPhaseMatMatMat() { public void testPhaseMatMatMat() {
fail("Not yet implemented"); Mat x = new Mat(1, 4, CvType.CV_32F);
Mat y = new Mat(1, 4, CvType.CV_32F);
Mat res = new Mat(1, 4, CvType.CV_32F);
x.put(0, 0, 10.0, 10.0, 20.0, 5.0);
y.put(0, 0, 20.0, 15.0, 20.0, 20.0);
res.put(0, 0, 1.1071469, 0.98280007, 0.78539175, 1.3258134);
core.phase(x, y, dst);
assertMatEqual(res, dst);
} }
public void testPhaseMatMatMatBoolean() { public void testPhaseMatMatMatBoolean() {
fail("Not yet implemented"); Mat x = new Mat(1, 4, CvType.CV_32F);
Mat y = new Mat(1, 4, CvType.CV_32F);
Mat res = new Mat(1, 4, CvType.CV_32F);
x.put(0, 0, 10.0, 10.0, 20.0, 5.0);
y.put(0, 0, 20.0, 15.0, 20.0, 20.0);
res.put(0, 0, 63.434, 56.310, 44.999, 75.963);
core.phase(x, y, dst, true);
OpenCVTestRunner.Log(res.dump());
OpenCVTestRunner.Log(dst.dump());
} }
public void testPolarToCartMatMatMatMat() { public void testPolarToCartMatMatMatMat() {
fail("Not yet implemented"); Mat magnitude = new Mat(1, 3, CvType.CV_32F);
Mat angle = new Mat(1, 3, CvType.CV_32F);
Mat x = new Mat(1, 3, CvType.CV_32F);
Mat y = new Mat(1, 3, CvType.CV_32F);
Mat xCoordinate = new Mat();
Mat yCoordinate = new Mat();
// x.put(0, 0, 3.0, 6.0, 5,0);
// y.put(0, 0, 4.0, 8.0, 12.0);
// magnitude.put(0, 0, 5.0, 10.0, 13.0);
// angle.put(0, 0, 0.92729962, 0.92729962, 1.1759995);
magnitude.put(0, 0, 5.0, 10.0, 13.0);
angle.put(0, 0, 0.92729962, 0.92729962, 1.1759995);
x.put(0, 0, 3.0, 6.0, 5,0);
y.put(0, 0, 4.0, 8.0, 12.0);
//TODO: needs epsilon comparison
core.polarToCart(magnitude, angle, xCoordinate, yCoordinate);
OpenCVTestRunner.Log(x.dump());
OpenCVTestRunner.Log(xCoordinate.dump());
OpenCVTestRunner.Log(y.dump());
OpenCVTestRunner.Log(yCoordinate.dump());
assertMatEqual(x, xCoordinate);
} }
public void testPolarToCartMatMatMatMatBoolean() { public void testPolarToCartMatMatMatMatBoolean() {
@ -724,39 +954,100 @@ public class coreTest extends OpenCVTestCase {
} }
public void testRandn() { public void testRandn() {
fail("Not yet implemented"); Mat low = new Mat(1, 1, CvType.CV_16UC1, new Scalar(0));
Mat high = new Mat(1, 1, CvType.CV_16UC1, new Scalar(256));
assertTrue(0 == core.countNonZero(gray0));
core.randn(gray0, low, high);
assertTrue(0 != core.countNonZero(gray0));
} }
public void testRandu() { public void testRandu() {
fail("Not yet implemented"); Mat low = new Mat(1, 1, CvType.CV_16UC1, new Scalar(0));
Mat high = new Mat(1, 1, CvType.CV_16UC1, new Scalar(256));
assertTrue(0 == core.countNonZero(gray0));
core.randu(gray0, low, high);
assertTrue(0 != core.countNonZero(gray0));
} }
public void testRectangleMatPointPointScalar() { public void testRectangleMatPointPointScalar() {
fail("Not yet implemented"); Point center = new Point(gray0.cols()/2, gray0.rows()/2);
Point origin = new Point(0,0);
Scalar color = new Scalar(128);
assertTrue(0 == core.countNonZero(gray0));
core.rectangle(gray0, center, origin, color);
assertTrue(0 != core.countNonZero(gray0));
} }
public void testRectangleMatPointPointScalarInt() { public void testRectangleMatPointPointScalarInt() {
fail("Not yet implemented"); Point center = new Point(gray0.cols(), gray0.rows());
Point origin = new Point(0,0);
Scalar color = new Scalar(128);
assertTrue(0 == core.countNonZero(gray0));
core.rectangle(gray0, center, origin, color, 2);
assertTrue(0 != core.countNonZero(gray0));
} }
public void testRectangleMatPointPointScalarIntInt() { public void testRectangleMatPointPointScalarIntInt() {
fail("Not yet implemented"); Point center = new Point(gray0.cols()/2, gray0.rows()/2);
Point origin = new Point(0,0);
Scalar color = new Scalar(128);
assertTrue(0 == core.countNonZero(gray0));
core.rectangle(gray0, center, origin, color, 2, 8);
assertTrue(0 != core.countNonZero(gray0));
} }
public void testRectangleMatPointPointScalarIntIntInt() { public void testRectangleMatPointPointScalarIntIntInt() {
fail("Not yet implemented"); Point center = new Point(gray0.cols(), gray0.rows());
Point origin = new Point(0,0);
Scalar color = new Scalar(128);
assertTrue(0 == core.countNonZero(gray0));
core.rectangle(gray0, center, origin, color, 2, 4, 2);
assertTrue(0 != core.countNonZero(gray0));
} }
public void testReduceMatMatIntInt() { public void testReduceMatMatIntInt() {
fail("Not yet implemented"); Mat src = new Mat(2, 2, CvType.CV_32F);
Mat out = new Mat(1, 2, CvType.CV_32F);
src.put(0, 0, 1 , 0);
src.put(1, 0, 1 , 0);
out.put(0 , 0, 1, 0);
core.reduce(src, dst, 0, 2);
assertMatEqual(out, dst);
} }
public void testReduceMatMatIntIntInt() { public void testReduceMatMatIntIntInt() {
fail("Not yet implemented"); Mat src = new Mat(2, 2, CvType.CV_32F);
Mat out = new Mat(1, 2, CvType.CV_32F);
src.put(0, 0, 1 , 0);
src.put(1, 0, 1 , 0);
out.put(0 , 0, 1, 0);
core.reduce(src, dst, 0, 2, -1);
assertMatEqual(out, dst);
} }
public void testRepeat() { public void testRepeat() {
fail("Not yet implemented"); Mat src = new Mat(1, 3, CvType.CV_32F);
Mat des1 = new Mat(1, 3, CvType.CV_32F);
Mat des2 = new Mat(1, 6, CvType.CV_32F);
src.put(0, 0, 1, 2, 3);
des1.put(0, 0, 1, 2, 3);
des2.put(0, 0, 1, 2, 3, 1, 2, 3);
core.repeat(src, 1, 1, dst);
assertMatEqual(des1, dst);
core.repeat(src, 1, 2, dst);
assertMatEqual(des2, dst);
} }
public void testScaleAdd() { public void testScaleAdd() {
@ -765,52 +1056,86 @@ public class coreTest extends OpenCVTestCase {
} }
public void testSetIdentityMat() { public void testSetIdentityMat() {
core.setIdentity(gray0); core.setIdentity(gray0_32f);
assertTrue(gray0.rows() == core.countNonZero(gray0)); assertMatEqual(grayE_32f, gray0_32f);
} }
public void testSetIdentityMatScalar() { public void testSetIdentityMatScalar() {
fail("Not yet implemented. Scalar type is not supported"); core.gemm(grayE_32f, grayE_32f, 5.0, new Mat(), 0.0, dst);
core.setIdentity(gray0_32f, new Scalar(5));
assertMatEqual(dst, gray0_32f);
} }
public void testSolveCubic() { public void testSolveCubic() {
fail("Not yet implemented"); Mat coeffs = new Mat(1, 4, CvType.CV_32F);
Mat roots = new Mat(3, 1, CvType.CV_32F);
coeffs.put(0, 0, 1, 6, 11, 6);
roots.put(0, 0, -3, -1, -2);
core.solveCubic(coeffs, dst);
assertMatEqual(roots, dst);
} }
public void testSolveMatMatMat() { public void testSolveMatMatMat() {
fail("Not yet implemented"); Mat a = new Mat(3, 3, CvType.CV_32F);
Mat b = new Mat(3, 1, CvType.CV_32F);
Mat res = new Mat(3, 1, CvType.CV_32F);
a.put(0, 0, 1, 1, 1);
a.put(1, 0, 1, -2, 2);
a.put(2, 0, 1, 2, 1);
b.put(0, 0, 0, 4, 2);
res.put(0, 0, -12, 2, 10);
core.solve(a, b, dst);
assertMatEqual(res, dst);
} }
public void testSolveMatMatMatInt() { public void testSolveMatMatMatInt() {
fail("Not yet implemented"); Mat a = new Mat(3, 3, CvType.CV_32F);
Mat b = new Mat(3, 1, CvType.CV_32F);
Mat res = new Mat(3, 1, CvType.CV_32F);
a.put(0, 0, 1, 1, 1);
a.put(1, 0, 1, -2, 2);
a.put(2, 0, 1, 2, 1);
b.put(0, 0, 0, 4, 2);
res.put(0, 0, -12, 2, 10);
core.solve(a, b, dst, 3);
assertMatEqual(res, dst);
} }
public void testSolvePolyMatMat() { public void testSolvePolyMatMat() {
fail("Not yet implemented"); Mat coeffs = new Mat(4, 1, CvType.CV_32F);
// Mat coeffs = new Mat(4, 1, CvType.CV_32F); Mat roots = new Mat(3, 1, CvType.CV_32F);
// Mat standart = new Mat(3, 1, CvType.CV_32F);
// Mat roots = new Mat(3, 1, CvType.CV_32F);
// coeffs.setTo(0);
// coeffs.put(0, 0, 1);
// coeffs.put(0, 1, -6);
// coeffs.put(0, 2, 11);
// coeffs.put(0, 3, -6);
// standart.put(0, 0, 1);
// standart.put(0, 1, 2);
// standart.put(0, 2, 3);
// utils.Log(standart.dump()); coeffs.put(0, 0, -6, 11, -6, 1);
// core.solvePoly(coeffs, roots); Mat answer = new Mat(3, 1, CvType.CV_32FC2);
// //FIXME: doesn't work answer.put(0, 0, 1, 0, 2, 0, 3, 0);
// OpenCVTestRunner.Log(roots.dump()); answer.put(0, 0, 1, 0);
// core.sort(roots, roots, CV_SORT_EVERY_ROW); answer.put(1, 0, 2, 0);
// assertTrue(1 == core.countNonZero(coeffs)); answer.put(2, 0, 3, 0);
//assertMatEqual(roots, standart);
core.solvePoly(coeffs, roots);
assertMatEqual(answer, roots);
} }
public void testSolvePolyMatMatInt() { public void testSolvePolyMatMatInt() {
fail("Not yet implemented"); Mat coeffs = new Mat(4, 1, CvType.CV_32F);
Mat roots = new Mat(3, 1, CvType.CV_32F);
coeffs.put(0, 0, -6, 11, -6, 1);
Mat answer = new Mat(3, 1, CvType.CV_32FC2);
//FIXME: doesn't work answer.put(0, 0, 1, 0, 2, 0, 3, 0);
answer.put(0, 0, 1, 0);
answer.put(1, 0, -1, 2);
answer.put(2, 0, -2, 12);
core.solvePoly(coeffs, roots, 1);
assertMatEqual(answer, roots);
} }
public void testSort() { public void testSort() {
@ -827,23 +1152,16 @@ public class coreTest extends OpenCVTestCase {
} }
public void testSortIdx() { public void testSortIdx() {
fail("Not yet implemented"); Mat a = Mat.eye(3, 3, CvType.CV_8UC1);
// Mat matrix = new Mat(matSize, matSize, Mat.CvType.CV_8UC1); Mat b = new Mat();
// matrix.setTo(0);
// Mat submatrix = matrix.submat(0, matrix.rows() / 2, 0, matrix.cols() / 2);
// Mat subdst = dst.submat(0, dst.rows() / 2, dst.cols() / 2, dst.cols());
// submatrix.setTo(1);
// utils.Log(subdst.dump());
// core.sortIdx(matrix, dst, CV_SORT_EVERY_ROW + CV_SORT_ASCENDING);
// utils.Log(subdst.dump());
// assertTrue(subdst.total() == core.countNonZero(subdst));
Mat answer = new Mat(3, 3, CvType.CV_32SC1);
answer.put(0, 0, 1, 2, 0);
answer.put(1, 0, 0, 2, 1);
answer.put(2, 0, 0, 1, 2);
// dst.setTo(0); core.sortIdx(a, b, 0+0/*TODO: CV_SORT_EVERY_ROW + CV_SORT_ASCENDING*/);
// core.sortIdx(matrix, dst, CV_SORT_EVERY_COLUM + CV_SORT_DESCENDING); assertMatEqual(answer, b);
// Mat subdst1 = dst.submat(0, dst.rows() / 2, 0, dst.cols() / 2);
// utils.Log(subdst1.dump());
// assertTrue(subdst1.total() == core.countNonZero(subdst1));
} }
public void testSqrt() { public void testSqrt() {
@ -881,7 +1199,12 @@ public class coreTest extends OpenCVTestCase {
} }
public void testTransform() { public void testTransform() {
fail("Not yet implemented"); Mat src = new Mat(2, 2, CvType.CV_32F, new Scalar(55));
Mat m = Mat.eye(2, 2, CvType.CV_32FC1);
core.transform(src, dst, m);
Mat answer = new Mat(2, 2, CvType.CV_32FC2, new Scalar(55, 1));
assertMatEqual(answer, dst);
} }
public void testTranspose() { public void testTranspose() {