mirror of
https://github.com/opencv/opencv.git
synced 2024-11-29 05:29:54 +08:00
Added some tests; Added assertion for comparing Mats with epsilon.
This commit is contained in:
parent
5ba826d297
commit
c966d077c0
@ -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());
|
||||
|
@ -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() {
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user