From: Andrey Kamaev Date: Wed, 27 Jul 2011 14:19:45 +0000 (+0000) Subject: Added some tests; Added assertion for comparing Mats with epsilon. X-Git-Tag: accepted/2.0/20130307.220821~2261 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c966d077c036df60305fb4fa9bb132abe498feea;p=profile%2Fivi%2Fopencv.git Added some tests; Added assertion for comparing Mats with epsilon. --- diff --git a/modules/java/android_test/src/org/opencv/test/OpenCVTestCase.java b/modules/java/android_test/src/org/opencv/test/OpenCVTestCase.java index 383e703..de8d163 100644 --- a/modules/java/android_test/src/org/opencv/test/OpenCVTestCase.java +++ b/modules/java/android_test/src/org/opencv/test/OpenCVTestCase.java @@ -4,6 +4,7 @@ import junit.framework.TestCase; import org.opencv.core.CvType; import org.opencv.core.Mat; +import org.opencv.core.Point; import org.opencv.core.Scalar; import org.opencv.core.Core; import org.opencv.highgui.Highgui; @@ -123,6 +124,14 @@ public class OpenCVTestCase extends TestCase { public static void assertMatNotEqual(Mat m1, Mat m2) { compareMats(m1, m2, false); } + + public static void assertMatEqual(Mat expected, Mat actual, double eps){ + compareMats(expected, actual, eps, true); + } + + public static void assertMatNotEqual(Mat expected, Mat actual, double eps){ + compareMats(expected, actual, eps, false); + } static private void compareMats(Mat m1, Mat m2, boolean isEqualityMeasured) { // OpenCVTestRunner.Log(m1.toString()); @@ -149,6 +158,22 @@ public class OpenCVTestCase extends TestCase { } } } + + static private void compareMats(Mat expected, Mat actual, double eps, boolean isEqualityMeasured) { + if (expected.type() != actual.type() || expected.cols() != actual.cols() + || expected.rows() != actual.rows()) { + throw new UnsupportedOperationException(); + } + Mat diff = new Mat(); + Core.absdiff(expected, actual, diff); + OpenCVTestRunner.Log(diff + " \n " + diff.dump()); + if(isEqualityMeasured) + assertTrue("Max difference between expected and actiual values is bigger than " + eps, + Core.checkRange(diff, true, new Point(), 0.0, eps)); + else + assertFalse("Max difference between expected and actiual values is less than " + eps, + Core.checkRange(diff, true, new Point(), 0.0, eps)); + } static private Mat getCOI(Mat m, int coi) { Mat ch = new Mat(m.rows(), m.cols(), m.depth()); diff --git a/modules/java/android_test/src/org/opencv/test/calib3d/calib3dTest.java b/modules/java/android_test/src/org/opencv/test/calib3d/calib3dTest.java index e6c9cf6..47e9c01 100644 --- a/modules/java/android_test/src/org/opencv/test/calib3d/calib3dTest.java +++ b/modules/java/android_test/src/org/opencv/test/calib3d/calib3dTest.java @@ -341,7 +341,21 @@ public class calib3dTest extends OpenCVTestCase { } public void testRodriguesMatMat() { - fail("Not yet implemented"); + Mat r = new Mat(3,1,CvType.CV_32F); + Mat R = new Mat(3,3,CvType.CV_32F); + + r.put(0, 0, Math.PI, 0, 0); + + Calib3d.Rodrigues(r, R); + + truth = new Mat(3,3,CvType.CV_32F); + truth.put(0, 0, 1, 0 ,0, 0, -1, 0, 0, 0, -1); + assertMatEqual(truth, R, EPS); + + Mat r2 = new Mat(); + Calib3d.Rodrigues(R, r2); + + assertMatEqual(r, r2, EPS); } public void testRodriguesMatMatMat() { diff --git a/modules/java/android_test/src/org/opencv/test/core/coreTest.java b/modules/java/android_test/src/org/opencv/test/core/coreTest.java index 0107722..88782bb 100644 --- a/modules/java/android_test/src/org/opencv/test/core/coreTest.java +++ b/modules/java/android_test/src/org/opencv/test/core/coreTest.java @@ -2,8 +2,6 @@ package org.opencv.test.core; import java.util.ArrayList; -import org.hamcrest.core.IsInstanceOf; -import org.junit.internal.runners.statements.ExpectException; import org.opencv.core.CvException; import org.opencv.core.CvType; import org.opencv.core.Mat;