Added some tests; Added assertion for comparing Mats with epsilon.
This commit is contained in:
		| @@ -4,6 +4,7 @@ import junit.framework.TestCase; | |||||||
|  |  | ||||||
| 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.Scalar; | 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; | ||||||
| @@ -124,6 +125,14 @@ public class OpenCVTestCase extends TestCase { | |||||||
|         compareMats(m1, m2, false); |         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) { |     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()); | ||||||
| @@ -150,6 +159,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) { |     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()); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -341,7 +341,21 @@ public class calib3dTest extends OpenCVTestCase { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void testRodriguesMatMat() { |     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() { |     public void testRodriguesMatMatMat() { | ||||||
|   | |||||||
| @@ -2,8 +2,6 @@ package org.opencv.test.core; | |||||||
|  |  | ||||||
| import java.util.ArrayList; | 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.CvException; | ||||||
| import org.opencv.core.CvType; | import org.opencv.core.CvType; | ||||||
| import org.opencv.core.Mat; | import org.opencv.core.Mat; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Andrey Kamaev
					Andrey Kamaev