Commit edead9a2 authored by Kirill Kornyakov's avatar Kirill Kornyakov

java tests: added some new asserts, and new tests by Hussein Abdinoor

parent c11a7184
package org.opencv.test; package org.opencv.test;
import java.util.ArrayList;
import java.util.List;
public class ConvertersTest extends OpenCVTestCase { public class ConvertersTest extends OpenCVTestCase {
......
package org.opencv.test; package org.opencv.test;
import java.util.List;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.opencv.core.CvType; import org.opencv.core.CvType;
...@@ -14,10 +16,13 @@ public class OpenCVTestCase extends TestCase { ...@@ -14,10 +16,13 @@ public class OpenCVTestCase extends TestCase {
protected static int matSize = 10; protected static int matSize = 10;
protected static double EPS = 0.001; protected static double EPS = 0.001;
protected static double weakEPS = 0.5;
protected static Mat dst; protected static Mat dst;
protected static Mat truth; protected static Mat truth;
protected static Scalar colorBlack;
// Naming notation: <channels info>_[depth]_[dimensions]_value // Naming notation: <channels info>_[depth]_[dimensions]_value
// examples: gray0 - single channel 8U 2d Mat filled with 0 // examples: gray0 - single channel 8U 2d Mat filled with 0
// grayRnd - single channel 8U 2d Mat filled with random numbers // grayRnd - single channel 8U 2d Mat filled with random numbers
...@@ -72,6 +77,8 @@ public class OpenCVTestCase extends TestCase { ...@@ -72,6 +77,8 @@ public class OpenCVTestCase extends TestCase {
truth = new Mat(); truth = new Mat();
assertTrue(truth.empty()); assertTrue(truth.empty());
colorBlack = new Scalar(0);
gray0 = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(0)); gray0 = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(0));
gray1 = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(1)); gray1 = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(1));
gray2 = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(2)); gray2 = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(2));
...@@ -82,8 +89,7 @@ public class OpenCVTestCase extends TestCase { ...@@ -82,8 +89,7 @@ public class OpenCVTestCase extends TestCase {
gray255 = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(255)); gray255 = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(255));
gray_16u_256 = new Mat(matSize, matSize, CvType.CV_16U, new Scalar(256)); gray_16u_256 = new Mat(matSize, matSize, CvType.CV_16U, new Scalar(256));
gray_16s_1024 = new Mat(matSize, matSize, CvType.CV_16S, new Scalar( gray_16s_1024 = new Mat(matSize, matSize, CvType.CV_16S, new Scalar(1024));
1024));
grayRnd = new Mat(matSize, matSize, CvType.CV_8U); grayRnd = new Mat(matSize, matSize, CvType.CV_8U);
Core.randu(grayRnd, new Scalar(0), new Scalar(256)); Core.randu(grayRnd, new Scalar(0), new Scalar(256));
...@@ -151,6 +157,16 @@ public class OpenCVTestCase extends TestCase { ...@@ -151,6 +157,16 @@ public class OpenCVTestCase extends TestCase {
super.tearDown(); super.tearDown();
} }
public static void assertListEqual(List<Float> list1, List<Float> list2, double epsilon)
{
if (list1.size() != list2.size()) {
throw new UnsupportedOperationException();
}
for (int i = 0; i < list1.size(); i++)
assertTrue(Math.abs(list1.get(i) - list2.get(i)) <= epsilon);
}
public static void assertMatEqual(Mat m1, Mat m2) { public static void assertMatEqual(Mat m1, Mat m2) {
compareMats(m1, m2, true); compareMats(m1, m2, true);
} }
...@@ -176,6 +192,11 @@ public class OpenCVTestCase extends TestCase { ...@@ -176,6 +192,11 @@ public class OpenCVTestCase extends TestCase {
assertEquals(expected.class_id, actual.class_id); assertEquals(expected.class_id, actual.class_id);
} }
public static void assertPointEquals(Point expected, Point actual, double eps){
assertEquals(expected.x, actual.x, eps);
assertEquals(expected.y, actual.y, eps);
}
static private void compareMats(Mat expected, Mat actual, boolean isEqualityMeasured) { static private void compareMats(Mat expected, Mat actual, boolean isEqualityMeasured) {
if (expected.type() != actual.type() || expected.cols() != actual.cols() if (expected.type() != actual.type() || expected.cols() != actual.cols()
|| expected.rows() != actual.rows()) { || expected.rows() != actual.rows()) {
......
...@@ -99,10 +99,8 @@ public class coreTest extends OpenCVTestCase { ...@@ -99,10 +99,8 @@ public class coreTest extends OpenCVTestCase {
Mat covar = new Mat(matSize, matSize, CvType.CV_64FC1); Mat covar = new Mat(matSize, matSize, CvType.CV_64FC1);
Mat mean = new Mat(1, matSize, CvType.CV_64FC1); Mat mean = new Mat(1, matSize, CvType.CV_64FC1);
Core.calcCovarMatrix(gray0_32f, covar, mean, 8 | 1/* Core.calcCovarMatrix(gray0_32f, covar, mean, Core.COVAR_ROWS | Core.COVAR_NORMAL);
* TODO:
* CV_COVAR_NORMAL
*/);
assertMatEqual(gray0_64f, covar, EPS); assertMatEqual(gray0_64f, covar, EPS);
assertMatEqual(gray0_64f_1d, mean, EPS); assertMatEqual(gray0_64f_1d, mean, EPS);
} }
...@@ -111,10 +109,7 @@ public class coreTest extends OpenCVTestCase { ...@@ -111,10 +109,7 @@ public class coreTest extends OpenCVTestCase {
Mat covar = new Mat(matSize, matSize, CvType.CV_32F); Mat covar = new Mat(matSize, matSize, CvType.CV_32F);
Mat mean = new Mat(1, matSize, CvType.CV_32F); Mat mean = new Mat(1, matSize, CvType.CV_32F);
Core.calcCovarMatrix(gray0_32f, covar, mean, 8 | 1/* Core.calcCovarMatrix(gray0_32f, covar, mean, Core.COVAR_ROWS | Core.COVAR_NORMAL, CvType.CV_32F);
* TODO:
* CV_COVAR_NORMAL
*/, CvType.CV_32F);
assertMatEqual(gray0_32f, covar, EPS); assertMatEqual(gray0_32f, covar, EPS);
assertMatEqual(gray0_32f_1d, mean, EPS); assertMatEqual(gray0_32f_1d, mean, EPS);
} }
...@@ -744,11 +739,8 @@ public class coreTest extends OpenCVTestCase { ...@@ -744,11 +739,8 @@ public class coreTest extends OpenCVTestCase {
Core.invert(src, dst); Core.invert(src, dst);
assertMatEqual(truth, dst, EPS); assertMatEqual(truth, dst, EPS);
// TODO: needs epsilon comparison Core.gemm(grayRnd_32f, grayRnd_32f.inv(), 1.0, new Mat(), 0.0, dst);
// Mat m = grayRnd_32f.clone(); assertMatEqual(grayE_32f, dst, EPS);
// 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() {
...@@ -852,10 +844,7 @@ public class coreTest extends OpenCVTestCase { ...@@ -852,10 +844,7 @@ public class coreTest extends OpenCVTestCase {
public void testMahalanobis() { public void testMahalanobis() {
Mat covar = new Mat(matSize, matSize, CvType.CV_32F); Mat covar = new Mat(matSize, matSize, CvType.CV_32F);
Mat mean = new Mat(1, matSize, CvType.CV_32F); Mat mean = new Mat(1, matSize, CvType.CV_32F);
Core.calcCovarMatrix(grayRnd_32f, covar, mean, 8 | 1/* Core.calcCovarMatrix(grayRnd_32f, covar, mean, Core.COVAR_ROWS | Core.COVAR_NORMAL, CvType.CV_32F);
* TODO:
* CV_COVAR_NORMAL
*/, CvType.CV_32F);
covar.inv(); covar.inv();
Mat line1 = grayRnd_32f.submat(0, 1, 0, grayRnd_32f.cols()); Mat line1 = grayRnd_32f.submat(0, 1, 0, grayRnd_32f.cols());
...@@ -1222,18 +1211,12 @@ public class coreTest extends OpenCVTestCase { ...@@ -1222,18 +1211,12 @@ public class coreTest extends OpenCVTestCase {
Mat xCoordinate = new Mat(); Mat xCoordinate = new Mat();
Mat yCoordinate = 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); magnitude.put(0, 0, 5.0, 10.0, 13.0);
angle.put(0, 0, 0.92729962, 0.92729962, 1.1759995); angle.put(0, 0, 0.92729962, 0.92729962, 1.1759995);
x.put(0, 0, 3.0, 6.0, 5, 0); x.put(0, 0, 3.0, 6.0, 5, 0);
y.put(0, 0, 4.0, 8.0, 12.0); y.put(0, 0, 4.0, 8.0, 12.0);
// TODO: needs epsilon comparison
Core.polarToCart(magnitude, angle, xCoordinate, yCoordinate); Core.polarToCart(magnitude, angle, xCoordinate, yCoordinate);
assertMatEqual(x, xCoordinate, EPS); assertMatEqual(x, xCoordinate, EPS);
} }
...@@ -1504,11 +1487,11 @@ public class coreTest extends OpenCVTestCase { ...@@ -1504,11 +1487,11 @@ public class coreTest extends OpenCVTestCase {
Mat submat = gray0.submat(0, gray0.rows() / 2, 0, gray0.cols() / 2); Mat submat = gray0.submat(0, gray0.rows() / 2, 0, gray0.cols() / 2);
submat.setTo(new Scalar(1.0)); submat.setTo(new Scalar(1.0));
Core.sort(gray0, dst, 0/* TODO: CV_SORT_EVERY_ROW */); Core.sort(gray0, dst, Core.SORT_EVERY_ROW);
submat = dst.submat(0, dst.rows() / 2, dst.cols() / 2, dst.cols()); submat = dst.submat(0, dst.rows() / 2, dst.cols() / 2, dst.cols());
assertTrue(submat.total() == Core.countNonZero(submat)); assertTrue(submat.total() == Core.countNonZero(submat));
Core.sort(gray0, dst, 1/* TODO: CV_SORT_EVERY_COLUMN */); Core.sort(gray0, dst, Core.SORT_EVERY_COLUMN);
submat = dst.submat(dst.rows() / 2, dst.rows(), 0, dst.cols() / 2); submat = dst.submat(dst.rows() / 2, dst.rows(), 0, dst.cols() / 2);
assertTrue(submat.total() == Core.countNonZero(submat)); assertTrue(submat.total() == Core.countNonZero(submat));
} }
...@@ -1522,7 +1505,7 @@ public class coreTest extends OpenCVTestCase { ...@@ -1522,7 +1505,7 @@ public class coreTest extends OpenCVTestCase {
truth.put(1, 0, 0, 2, 1); truth.put(1, 0, 0, 2, 1);
truth.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, Core.SORT_EVERY_ROW + Core.SORT_ASCENDING);
assertMatEqual(truth, b); assertMatEqual(truth, b);
} }
......
package org.opencv.test.features2d; package org.opencv.test.features2d;
import java.util.LinkedList;
import java.util.List;
import org.opencv.core.Core; import org.opencv.core.Core;
import org.opencv.core.CvType; import org.opencv.core.CvType;
import org.opencv.core.Mat; import org.opencv.core.Mat;
import org.opencv.core.Point; import org.opencv.core.Point;
import org.opencv.core.RotatedRect;
import org.opencv.core.Scalar; import org.opencv.core.Scalar;
import org.opencv.core.Size;
import org.opencv.features2d.KeyPoint; import org.opencv.features2d.KeyPoint;
import org.opencv.features2d.StarDetector; import org.opencv.features2d.StarDetector;
import org.opencv.test.OpenCVTestCase; import org.opencv.test.OpenCVTestCase;
import org.opencv.test.OpenCVTestRunner;
import java.util.LinkedList;
import java.util.List;
public class StarDetectorTest extends OpenCVTestCase { public class StarDetectorTest extends OpenCVTestCase {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment