Commit 039fd554 authored by Andrey Kamaev's avatar Andrey Kamaev

Added several Android tests

parent 26bd6b3f
...@@ -8,64 +8,63 @@ import org.opencv.core.Scalar; ...@@ -8,64 +8,63 @@ import org.opencv.core.Scalar;
import org.opencv.core.Core; import org.opencv.core.Core;
import org.opencv.highgui.Highgui; import org.opencv.highgui.Highgui;
public class OpenCVTestCase extends TestCase { 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 Mat dst; protected static Mat dst;
protected static Mat truth; protected static Mat truth;
//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
// gray0_32f_1d // gray0_32f_1d
//TODO: OpenCVTestCase refactorings // TODO: OpenCVTestCase refactorings
// - rename matrices // - rename matrices
// - create some masks // - create some masks
// - use truth member everywhere // - use truth member everywhere
protected static Mat gray0; protected static Mat gray0;
protected static Mat gray1; protected static Mat gray1;
protected static Mat gray2; protected static Mat gray2;
protected static Mat gray3; protected static Mat gray3;
protected static Mat gray9; protected static Mat gray9;
protected static Mat gray127; protected static Mat gray127;
protected static Mat gray128; protected static Mat gray128;
protected static Mat gray255; protected static Mat gray255;
protected static Mat grayRnd; protected static Mat grayRnd;
protected static Mat gray_16u_256; protected static Mat gray_16u_256;
protected static Mat gray_16s_1024; protected static Mat gray_16s_1024;
protected static Mat gray0_32f; protected static Mat gray0_32f;
protected static Mat gray1_32f; protected static Mat gray1_32f;
protected static Mat gray3_32f; protected static Mat gray3_32f;
protected static Mat gray9_32f; protected static Mat gray9_32f;
protected static Mat gray255_32f; protected static Mat gray255_32f;
protected static Mat grayE_32f; protected static Mat grayE_32f;
protected static Mat grayRnd_32f; protected static Mat grayRnd_32f;
protected static Mat gray0_32f_1d; protected static Mat gray0_32f_1d;
protected static Mat gray0_64f; protected static Mat gray0_64f;
protected static Mat gray0_64f_1d; protected static Mat gray0_64f_1d;
protected static Mat rgba0; protected static Mat rgba0;
protected static Mat rgba128; protected static Mat rgba128;
protected static Mat rgbLena; protected static Mat rgbLena;
protected static Mat grayChess; protected static Mat grayChess;
protected static Mat v1; protected static Mat v1;
protected static Mat v2; protected static Mat v2;
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
dst = new Mat(); dst = new Mat();
assertTrue(dst.empty()); assertTrue(dst.empty());
truth = new Mat(); truth = new Mat();
...@@ -79,99 +78,102 @@ public class OpenCVTestCase extends TestCase { ...@@ -79,99 +78,102 @@ public class OpenCVTestCase extends TestCase {
gray127 = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(127)); gray127 = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(127));
gray128 = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(128)); gray128 = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(128));
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(1024)); gray_16s_1024 = new Mat(matSize, matSize, CvType.CV_16S, new Scalar(
1024));
Mat low = new Mat(1, 1, CvType.CV_16UC1, new Scalar(0));
Mat low = new Mat(1, 1, CvType.CV_16UC1, new Scalar(0));
Mat high = new Mat(1, 1, CvType.CV_16UC1, new Scalar(256)); 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); grayRnd = new Mat(matSize, matSize, CvType.CV_8U);
Core.randu(grayRnd, low, high);
gray0_32f = new Mat(matSize, matSize, CvType.CV_32F, new Scalar(0.0)); gray0_32f = new Mat(matSize, matSize, CvType.CV_32F, new Scalar(0.0));
gray1_32f = new Mat(matSize, matSize, CvType.CV_32F, new Scalar(1.0)); gray1_32f = new Mat(matSize, matSize, CvType.CV_32F, new Scalar(1.0));
gray3_32f = new Mat(matSize, matSize, CvType.CV_32F, new Scalar(3.0)); gray3_32f = new Mat(matSize, matSize, CvType.CV_32F, new Scalar(3.0));
gray9_32f = new Mat(matSize, matSize, CvType.CV_32F, new Scalar(9.0)); gray9_32f = new Mat(matSize, matSize, CvType.CV_32F, new Scalar(9.0));
gray255_32f = new Mat(matSize, matSize, CvType.CV_32F, new Scalar(255.0)); gray255_32f = new Mat(matSize, matSize, CvType.CV_32F,
grayE_32f = new Mat(matSize, matSize, CvType.CV_32F); grayE_32f = Mat.eye(matSize, matSize, CvType.CV_32FC1); new Scalar(255.0));
grayRnd_32f = new Mat(matSize, matSize, CvType.CV_32F); Core.randu(grayRnd_32f, low, high); 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, CvType.CV_32F, new Scalar(0.0)); gray0_32f_1d = new Mat(1, matSize, CvType.CV_32F, new Scalar(0.0));
gray0_64f = new Mat(matSize, matSize, CvType.CV_64F, new Scalar(0.0)); gray0_64f = new Mat(matSize, matSize, CvType.CV_64F, new Scalar(0.0));
gray0_64f_1d = new Mat(1, matSize, CvType.CV_64F, new Scalar(0.0)); gray0_64f_1d = new Mat(1, matSize, CvType.CV_64F, new Scalar(0.0));
rgba0 = new Mat(matSize, matSize, CvType.CV_8UC4, Scalar.all(0)); rgba0 = new Mat(matSize, matSize, CvType.CV_8UC4, Scalar.all(0));
rgba128 = new Mat(matSize, matSize, CvType.CV_8UC4, Scalar.all(128)); rgba128 = new Mat(matSize, matSize, CvType.CV_8UC4, Scalar.all(128));
rgbLena = Highgui.imread(OpenCVTestRunner.LENA_PATH); rgbLena = Highgui.imread(OpenCVTestRunner.LENA_PATH);
grayChess = Highgui.imread(OpenCVTestRunner.CHESS_PATH, 0); grayChess = Highgui.imread(OpenCVTestRunner.CHESS_PATH, 0);
v1 = new Mat(1, 3, CvType.CV_32F); v1.put(0, 0, 1.0, 3.0, 2.0); v1 = new Mat(1, 3, CvType.CV_32F);
v2 = new Mat(1, 3, CvType.CV_32F); v2.put(0, 0, 2.0, 1.0, 3.0); v1.put(0, 0, 1.0, 3.0, 2.0);
v2 = new Mat(1, 3, CvType.CV_32F);
v2.put(0, 0, 2.0, 1.0, 3.0);
} }
public static void assertMatEqual(Mat m1, Mat m2) { public static void assertMatEqual(Mat m1, Mat m2) {
compareMats(m1, m2, true); compareMats(m1, m2, true);
} }
public static void assertMatNotEqual(Mat m1, Mat m2) { public static void assertMatNotEqual(Mat m1, Mat m2) {
compareMats(m1, m2, false); compareMats(m1, m2, false);
} }
static private void compareMats(Mat m1, Mat m2, boolean isEqualityMeasured) { static private void compareMats(Mat m1, Mat m2, boolean isEqualityMeasured) {
//OpenCVTestRunner.Log(m1.toString()); // OpenCVTestRunner.Log(m1.toString());
//OpenCVTestRunner.Log(m2.toString()); // OpenCVTestRunner.Log(m2.toString());
if (m1.type() != m2.type() || if (m1.type() != m2.type() || m1.cols() != m2.cols()
m1.cols() != m2.cols() || m1.rows() != m2.rows()) { || m1.rows() != m2.rows()) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} } else if (m1.channels() == 1) {
else if (m1.channels() == 1) { if (isEqualityMeasured) {
if (isEqualityMeasured) { assertTrue(CalcPercentageOfDifference(m1, m2) == 0.0);
assertTrue(CalcPercentageOfDifference(m1, m2) == 0.0); } else {
} assertTrue(CalcPercentageOfDifference(m1, m2) != 0.0);
else { }
assertTrue(CalcPercentageOfDifference(m1, m2) != 0.0); } else {
} for (int coi = 0; coi < m1.channels(); coi++) {
} Mat m1c = getCOI(m1, coi);
else { Mat m2c = getCOI(m2, coi);
for (int coi = 0; coi < m1.channels(); coi++) { if (isEqualityMeasured) {
Mat m1c = getCOI(m1, coi); assertTrue(CalcPercentageOfDifference(m1c, m2c) == 0.0);
Mat m2c = getCOI(m2, coi); } else {
if (isEqualityMeasured) { assertTrue(CalcPercentageOfDifference(m1c, m2c) != 0.0);
assertTrue(CalcPercentageOfDifference(m1c, m2c) == 0.0); }
} }
else { }
assertTrue(CalcPercentageOfDifference(m1c, m2c) != 0.0);
}
}
}
} }
static private Mat getCOI(Mat m, int coi) { static private Mat getCOI(Mat m, int coi) {
Mat ch = new Mat(m.rows(), m.cols(), m.depth()); Mat ch = new Mat(m.rows(), m.cols(), m.depth());
for (int i = 0; i < m.rows(); i++) for (int i = 0; i < m.rows(); i++)
for (int j = 0; j < m.cols(); j++) for (int j = 0; j < m.cols(); j++) {
{ double pixel[] = m.get(i, j);
double pixel[] = m.get(i, j); ch.put(i, j, pixel[coi]);
ch.put(i, j, pixel[coi]); }
}
return ch;
return ch;
} }
static private double CalcPercentageOfDifference(Mat m1, Mat m2) { static private double CalcPercentageOfDifference(Mat m1, Mat m2) {
Mat cmp = new Mat(0, 0, CvType.CV_8U); Mat cmp = new Mat(0, 0, CvType.CV_8U);
Core.compare(m1, m2, cmp, Core.CMP_EQ); Core.compare(m1, m2, cmp, Core.CMP_EQ);
double difference = 100.0 * double difference = 100.0 * (1.0 - Double.valueOf(Core
(1.0 - Double.valueOf(Core.countNonZero(cmp)) / Double.valueOf(cmp.rows() * cmp.cols())); .countNonZero(cmp)) / Double.valueOf(cmp.rows() * cmp.cols()));
return difference; return difference;
} }
public void test_1(String label) { public void test_1(String label) {
OpenCVTestRunner.Log("================================================"); OpenCVTestRunner
OpenCVTestRunner.Log("=============== " + label); .Log("================================================");
OpenCVTestRunner.Log("=============== " + label);
} }
} }
package org.opencv.test.core; package org.opencv.test.core;
import org.opencv.core.Point;
import org.opencv.core.Rect;
import org.opencv.test.OpenCVTestCase; import org.opencv.test.OpenCVTestCase;
public class RectTest extends OpenCVTestCase { public class RectTest extends OpenCVTestCase {
...@@ -21,7 +23,21 @@ public class RectTest extends OpenCVTestCase { ...@@ -21,7 +23,21 @@ public class RectTest extends OpenCVTestCase {
} }
public void testContains() { public void testContains() {
fail("Not yet implemented"); Rect r = new Rect(0,0,10,10);
Point p_inner = new Point(5,5);
Point p_outer = new Point(5,55);
Point p_bl = new Point(0,0);
Point p_br = new Point(10,0);
Point p_tl = new Point(0,10);
Point p_tr = new Point(10,10);
assertTrue(r.contains(p_inner));
assertTrue(r.contains(p_bl));
assertFalse(r.contains(p_outer));
assertFalse(r.contains(p_br));
assertFalse(r.contains(p_tl));
assertFalse(r.contains(p_tr));
} }
public void testEqualsObject() { public void testEqualsObject() {
......
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