java tests: merged with new CvType, implemented half of the tests for Mat

pull/13383/head
Kirill Kornyakov 14 years ago
parent 2ef146c2c6
commit 80f0901dee
  1. 137
      modules/java/android_test/src/org/opencv/test/MatTest.java
  2. 51
      modules/java/android_test/src/org/opencv/test/OpenCVTestCase.java
  3. 45
      modules/java/android_test/src/org/opencv/test/coreTest.java

@ -1,6 +1,8 @@
package org.opencv.test;
import org.opencv.CvType;
import org.opencv.Mat;
import org.opencv.Scalar;
public class MatTest extends OpenCVTestCase {
@ -9,20 +11,26 @@ public class MatTest extends OpenCVTestCase {
}
public void testChannels() {
//fail("Not yet implemented");
//utils.Log(grayRnd.dump());
assertEquals(1, gray0.channels());
assertEquals(3, rgbLena.channels());
assertEquals(4, rgba0.channels());
}
public void testClone() {
fail("Not yet implemented");
dst = gray0.clone();
assertMatEqual(gray0, dst);
}
public void testCol() {
fail("Not yet implemented");
Mat col = gray0.col(0);
assertEquals(1, col.cols());
assertEquals(gray0.rows(), col.rows());
}
public void testColRange() {
fail("Not yet implemented");
Mat cols = gray0.colRange(0, gray0.cols()/2);
assertEquals(gray0.cols()/2, cols.cols());
assertEquals(gray0.rows(), cols.rows());
}
public void testCols() {
@ -42,7 +50,8 @@ public class MatTest extends OpenCVTestCase {
}
public void testDepth() {
fail("Not yet implemented");
assertEquals(CvType.CV_8U, gray0.depth());
assertEquals(CvType.CV_32F, gray0_32f.depth());
}
public void testDispose() {
@ -52,18 +61,31 @@ public class MatTest extends OpenCVTestCase {
public void testDot() {
fail("Not yet implemented");
}
public void testDump() {
fail("Not yet implemented");
}
public void testElemSize() {
fail("Not yet implemented");
}
public void testEmpty() {
assertTrue(dst.empty());
assertTrue(!gray0.empty());
}
public void testEye() {
fail("Not yet implemented");
}
public void testFinalize() {
fail("Not yet implemented");
}
public void testGetIntInt() {
fail("Not yet implemented");
}
public void testGetIntIntByteArray() {
fail("Not yet implemented");
@ -86,47 +108,74 @@ public class MatTest extends OpenCVTestCase {
}
public void testGetNativeObjAddr() {
fail("Not yet implemented");
assertTrue(0 != gray0.getNativeObjAddr());
}
public void testHeight() {
fail("Not yet implemented");
assertEquals(gray0.rows(), gray0.height());
assertEquals(rgbLena.rows(), rgbLena.height());
assertEquals(rgba128.rows(), rgba128.height());
}
public void testInv() {
fail("Not yet implemented");
//dst = grayE_32f.inv();
//assertMatEqual(grayE_32f, dst);
}
public void testIsContinuous() {
fail("Not yet implemented");
assertTrue(gray0.isContinuous());
Mat subMat = gray0.submat(0, 0, gray0.rows()/2, gray0.cols()/2);
assertFalse(subMat.isContinuous());
}
public void testIsSubmatrix() {
fail("Not yet implemented");
assertFalse(gray0.isSubmatrix());
Mat subMat = gray0.submat(0, 0, gray0.rows()/2, gray0.cols()/2);
assertTrue(subMat.isSubmatrix());
}
public void testMat() {
Mat m = new Mat();
assertTrue(null != m);
assertTrue(m.empty());
}
public void testMatIntIntCvType() {
Mat gray = new Mat(1, 1, Mat.CvType.CV_8UC1);
Mat gray = new Mat(1, 1, CvType.CV_8UC1);
assertFalse(gray.empty());
Mat rgb = new Mat(1, 1, Mat.CvType.CV_8UC3);
Mat rgb = new Mat(1, 1, CvType.CV_8UC3);
assertFalse(rgb.empty());
}
public void testMatIntIntCvTypeDouble() {
fail("Not yet implemented");
}
public void testMatIntIntCvTypeDoubleDouble() {
fail("Not yet implemented");
public void testMatIntIntCvTypeScalar() {
Mat gray = new Mat(1, 1, CvType.CV_8UC1, new Scalar(127));
assertFalse(gray.empty());
assertMatEqual(gray, gray127);
Mat rgb = new Mat(1, 1, CvType.CV_8UC4, new Scalar(128));
assertFalse(rgb.empty());
//FIXME: assertMatEqual(rgb, rgba128);
}
public void testMatIntIntCvTypeDoubleDoubleDouble() {
fail("Not yet implemented");
public void testMatIntIntInt() {
Mat gray = new Mat(1, 1, CvType.CV_8U);
assertFalse(gray.empty());
Mat rgb = new Mat(1, 1, CvType.CV_8U);
assertFalse(rgb.empty());
}
public void testMatIntIntCvTypeDoubleDoubleDoubleDouble() {
fail("Not yet implemented");
public void testMatIntIntIntScalar() {
Mat m1 = new Mat(1, 1, CvType.CV_8U, new Scalar(127));
assertFalse(m1.empty());
assertMatEqual(m1, gray127);
Mat m2 = new Mat(1, 1, CvType.CV_32F, new Scalar(0));
assertFalse(m2.empty());
assertMatEqual(m2, gray0_32f);
}
public void testMatLong() {
@ -154,50 +203,52 @@ public class MatTest extends OpenCVTestCase {
}
public void testRow() {
fail("Not yet implemented");
Mat row = gray0.row(0);
assertEquals(1, row.rows());
assertEquals(gray0.cols(), row.cols());
}
public void testRowRange() {
fail("Not yet implemented");
Mat rows = gray0.rowRange(0, gray0.rows()/2);
assertEquals(gray0.rows()/2, rows.rows());
assertEquals(gray0.cols(), rows.cols());
}
public void testRows() {
assertEquals(matSize, gray0.rows());
}
public void testSetToDouble() {
fail("Not yet implemented");
}
public void testSetToDoubleDouble() {
fail("Not yet implemented");
}
public void testSetToDoubleDoubleDouble() {
fail("Not yet implemented");
}
public void testSetToDoubleDoubleDoubleDouble() {
fail("Not yet implemented");
public void testSetTo() {
gray0.setTo(new Scalar(127));
assertMatEqual(gray127, gray0);
}
public void testSubmat() {
fail("Not yet implemented");
Mat submat = gray0.submat(0, gray0.rows()/2, 0, gray0.cols()/2);
assertEquals(gray0.rows()/2, submat.rows());
assertEquals(gray0.cols()/2, submat.cols());
}
public void testToString() {
fail("Not yet implemented");
assertTrue(null != gray0.toString());
}
public void testTotal() {
fail("Not yet implemented");
int nElements = gray0.rows() * gray0.cols();
assertEquals(nElements, gray0.total());
}
public void testType() {
fail("Not yet implemented");
assertEquals(CvType.CV_8UC1, gray0.type());
//TODO: assertEquals(CvType.CV_8U, gray0.type());
assertEquals(CvType.CV_32FC1, gray0_32f.type());
assertEquals(CvType.CV_8UC3, rgbLena.type());
}
public void testWidth() {
fail("Not yet implemented");
assertEquals(gray0.cols(), gray0.width());
assertEquals(rgbLena.cols(), rgbLena.width());
assertEquals(rgba128.cols(), rgba128.width());
}
}

@ -2,7 +2,9 @@ package org.opencv.test;
import junit.framework.TestCase;
import org.opencv.CvType;
import org.opencv.Mat;
import org.opencv.Scalar;
import org.opencv.core;
import org.opencv.highgui;
@ -36,11 +38,11 @@ public class OpenCVTestCase extends TestCase {
static Mat gray0_64f;
static Mat gray0_64f_1d;
static Mat rgba0;
static Mat rgba128;
static Mat rgbLena;
static Mat rgba0;
static Mat rgba128;
@Override
protected void setUp() throws Exception {
@ -49,30 +51,30 @@ public class OpenCVTestCase extends TestCase {
dst = new Mat();
assertTrue(dst.empty());
gray0 = new Mat(matSize, matSize, Mat.CvType.CV_8UC1); gray0.setTo(0.0);
gray1 = new Mat(matSize, matSize, Mat.CvType.CV_8UC1); gray1.setTo(1.0);
gray2 = new Mat(matSize, matSize, Mat.CvType.CV_8UC1); gray2.setTo(2.0);
gray3 = new Mat(matSize, matSize, Mat.CvType.CV_8UC1); gray3.setTo(3.0);
gray127 = new Mat(matSize, matSize, Mat.CvType.CV_8UC1); gray127.setTo(127.0);
gray128 = new Mat(matSize, matSize, Mat.CvType.CV_8UC1); gray128.setTo(128.0);
gray255 = new Mat(matSize, matSize, Mat.CvType.CV_8UC1); gray255.setTo(255.0);
gray0 = new Mat(matSize, matSize, CvType.CV_8U); gray0.setTo(new Scalar(0.0));
gray1 = new Mat(matSize, matSize, CvType.CV_8U); gray1.setTo(new Scalar(1.0));
gray2 = new Mat(matSize, matSize, CvType.CV_8U); gray2.setTo(new Scalar(2.0));
gray3 = new Mat(matSize, matSize, CvType.CV_8U); gray3.setTo(new Scalar(3.0));
gray127 = new Mat(matSize, matSize, CvType.CV_8U); gray127.setTo(new Scalar(127.0));
gray128 = new Mat(matSize, matSize, CvType.CV_8U); gray128.setTo(new Scalar(128.0));
gray255 = new Mat(matSize, matSize, CvType.CV_8U); gray255.setTo(new Scalar(255.0));
Mat low = new Mat(1, 1, Mat.CvType.CV_16UC1, 0.0);
Mat high = new Mat(1, 1, Mat.CvType.CV_16UC1, 256.0);
grayRnd = new Mat(matSize, matSize, Mat.CvType.CV_8UC1); core.randu(grayRnd, low, high);
Mat low = new Mat(1, 1, CvType.CV_16UC1, new Scalar(0));
Mat high = new Mat(1, 1, CvType.CV_16UC1, new Scalar(256));
grayRnd = new Mat(matSize, matSize, CvType.CV_8U); core.randu(grayRnd, low, high);
gray0_32f = new Mat(matSize, matSize, Mat.CvType.CV_32FC1); gray0_32f.setTo(0.0);
gray255_32f = new Mat(matSize, matSize, Mat.CvType.CV_32FC1); gray255_32f.setTo(255.0);
grayE_32f = new Mat(matSize, matSize, Mat.CvType.CV_32FC1); grayE_32f = Mat.eye(matSize, matSize, Mat.CvType.CV_32FC1);
grayRnd_32f = new Mat(matSize, matSize, Mat.CvType.CV_32FC1); core.randu(grayRnd_32f, low, high);
gray0_32f = new Mat(matSize, matSize, CvType.CV_32F); gray0_32f.setTo(new Scalar(0.0));
gray255_32f = new Mat(matSize, matSize, CvType.CV_32F); gray255_32f.setTo(new Scalar(255.0));
grayE_32f = new Mat(matSize, matSize, CvType.CV_32F); grayE_32f = Mat.eye(matSize, matSize, CvType.CV_32FC1);
grayRnd_32f = new Mat(matSize, matSize, CvType.CV_32F); core.randu(grayRnd_32f, low, high);
gray0_32f_1d = new Mat(1, matSize, Mat.CvType.CV_32FC1); gray0_32f_1d.setTo(0.0);
gray0_32f_1d = new Mat(1, matSize, CvType.CV_32F); gray0_32f_1d.setTo(new Scalar(0.0));
gray0_64f = new Mat(matSize, matSize, Mat.CvType.CV_64FC1); gray0_64f.setTo(0.0);
gray0_64f_1d = new Mat(1, matSize, Mat.CvType.CV_64FC1); gray0_64f_1d.setTo(0.0);
rgba0 = new Mat(matSize, matSize, Mat.CvType.CV_8UC4); rgba0.setTo(0, 0, 0, 0);
rgba128 = new Mat(matSize, matSize, Mat.CvType.CV_8UC4); rgba128.setTo(128, 128, 128, 128);
gray0_64f = new Mat(matSize, matSize, CvType.CV_64F); gray0_64f.setTo(new Scalar(0.0));
gray0_64f_1d = new Mat(1, matSize, CvType.CV_64F); gray0_64f_1d.setTo(new Scalar(0.0));
rgba0 = new Mat(matSize, matSize, CvType.CV_8UC4); rgba0.setTo(Scalar.all(0));
rgba128 = new Mat(matSize, matSize, CvType.CV_8UC4); rgba128.setTo(Scalar.all(128));
rgbLena = highgui.imread(OpenCVTestRunner.LENA_PATH);
}
@ -82,7 +84,7 @@ public class OpenCVTestCase extends TestCase {
}
static public double CalcPercentageOfDifference(Mat m1, Mat m2) {
Mat cmp = new Mat(0, 0, Mat.CvType.CV_8UC1);
Mat cmp = new Mat(0, 0, CvType.CV_8U);
core.compare(m1, m2, cmp, core.CMP_EQ);
double num = 100.0 *
(1.0 - Double.valueOf(core.countNonZero(cmp)) / Double.valueOf(cmp.rows() * cmp.cols()));
@ -93,6 +95,5 @@ public class OpenCVTestCase extends TestCase {
public void test_1(String label) {
OpenCVTestRunner.Log("================================================");
OpenCVTestRunner.Log("=============== " + label);
OpenCVTestRunner.Log("================================================");
}
}

@ -1,5 +1,6 @@
package org.opencv.test;
import org.opencv.CvType;
import org.opencv.Mat;
import org.opencv.Point;
import org.opencv.Scalar;
@ -74,8 +75,8 @@ public class coreTest extends OpenCVTestCase {
}
public void testCalcCovarMatrixMatMatMatInt() {
Mat covar = new Mat(matSize, matSize, Mat.CvType.CV_64FC1);
Mat mean = new Mat(1, matSize, Mat.CvType.CV_64FC1);
Mat covar = new Mat(matSize, matSize, CvType.CV_64FC1);
Mat mean = new Mat(1, matSize, CvType.CV_64FC1);
core.calcCovarMatrix(gray0_32f, covar, mean, 8|1); //TODO: CV_COVAR_NORMAL instead of magic numbers
assertMatEqual(gray0_64f, covar);
@ -83,10 +84,10 @@ public class coreTest extends OpenCVTestCase {
}
public void testCalcCovarMatrixMatMatMatIntInt() {
Mat covar = new Mat(matSize, matSize, Mat.CvType.CV_32FC1);
Mat mean = new Mat(1, matSize, Mat.CvType.CV_32FC1);
Mat covar = new Mat(matSize, matSize, CvType.CV_32FC1);
Mat mean = new Mat(1, matSize, CvType.CV_32FC1);
core.calcCovarMatrix(gray0_32f, covar, mean, 8|1, Mat.CvType.CV_32F); //TODO: CV_COVAR_NORMAL instead of magic numbers
core.calcCovarMatrix(gray0_32f, covar, mean, 8|1, CvType.CV_32F); //TODO: CV_COVAR_NORMAL instead of magic numbers
assertMatEqual(gray0_32f, covar);
assertMatEqual(gray0_32f_1d, mean);
}
@ -128,16 +129,14 @@ public class coreTest extends OpenCVTestCase {
}
public void testCompare() {
Mat cmp = new Mat(0, 0, Mat.CvType.CV_8UC1);
core.compare(gray0, gray0, cmp, core.CMP_EQ);
assertMatEqual(cmp, gray255);
core.compare(gray0, gray0, dst, core.CMP_EQ);
assertMatEqual(dst, gray255);
core.compare(gray0, gray1, cmp, core.CMP_EQ);
assertMatEqual(cmp, gray0);
core.compare(gray0, gray1, dst, core.CMP_EQ);
assertMatEqual(dst, gray0);
core.compare(gray0, grayRnd, cmp, core.CMP_EQ);
double nBlackPixels = core.countNonZero(cmp);
core.compare(gray0, grayRnd, dst, core.CMP_EQ);
double nBlackPixels = core.countNonZero(dst);
double nNonBlackpixels = core.countNonZero(grayRnd);
assertTrue((nBlackPixels + nNonBlackpixels) == grayRnd.total());
}
@ -181,9 +180,9 @@ public class coreTest extends OpenCVTestCase {
core.dct(gray0_32f_1d, dst);
assertMatEqual(gray0_32f_1d, dst);
Mat in = new Mat(1, 4, Mat.CvType.CV_32FC1);
Mat in = new Mat(1, 4, CvType.CV_32FC1);
in.put(0, 0, 135.22211, 50.811096, 102.27016, 207.6682);
Mat out = new Mat(1, 4, Mat.CvType.CV_32FC1);
Mat out = new Mat(1, 4, CvType.CV_32FC1);
out.put(0, 0, 247.98576, -61.252407, 94.904533, 14.013477);
core.dct(in, dst);
@ -281,8 +280,8 @@ public class coreTest extends OpenCVTestCase {
}
public void testHconcat() {
Mat e = new Mat(3, 3, Mat.CvType.CV_8UC1);
Mat eConcat = new Mat(1, 9, Mat.CvType.CV_8UC1);
Mat e = Mat.eye(3, 3, 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);
@ -359,13 +358,13 @@ public class coreTest extends OpenCVTestCase {
}
public void testLUTMatMatMat() {
Mat lut = new Mat(1, 256, Mat.CvType.CV_8UC1);
Mat lut = new Mat(1, 256, CvType.CV_8UC1);
lut.setTo(0);
lut.setTo(new Scalar(0));
core.LUT(grayRnd, lut, dst);
assertMatEqual(gray0, dst);
lut.setTo(255);
lut.setTo(new Scalar(255));
core.LUT(grayRnd, lut, dst);
assertMatEqual(gray255, dst);
}
@ -379,9 +378,9 @@ public class coreTest extends OpenCVTestCase {
}
public void testMahalanobis() {
Mat covar = new Mat(matSize, matSize, Mat.CvType.CV_32FC1);
Mat mean = new Mat(1, matSize, Mat.CvType.CV_32FC1);
core.calcCovarMatrix(grayRnd_32f, covar, mean, 8|1, Mat.CvType.CV_32F); //TODO: CV_COVAR_NORMAL instead of magic numbers
Mat covar = new Mat(matSize, matSize, CvType.CV_32FC1);
Mat mean = new Mat(1, matSize, CvType.CV_32FC1);
core.calcCovarMatrix(grayRnd_32f, covar, mean, 8|1, CvType.CV_32F); //TODO: CV_COVAR_NORMAL instead of magic numbers
covar.inv();
Mat line1 = grayRnd_32f.submat(0, 1, 0, grayRnd_32f.cols());

Loading…
Cancel
Save