Commit b486a966 authored by Andrey Kamaev's avatar Andrey Kamaev

Java API: refactored Core tests

parent 93a0237b
...@@ -42,7 +42,8 @@ public class OpenCVTestCase extends TestCase { ...@@ -42,7 +42,8 @@ public class OpenCVTestCase extends TestCase {
// - rename matrices // - rename matrices
// - create methods gray0() and create src1 explicitly // - create methods gray0() and create src1 explicitly
// - create some masks // - create some masks
// - use truth member everywhere - remove truth from base class - each test fixture should use own truth filed // - use truth member everywhere - remove truth from base class - each test
// fixture should use own truth filed
protected Mat gray0; protected Mat gray0;
protected Mat gray1; protected Mat gray1;
...@@ -167,6 +168,17 @@ public class OpenCVTestCase extends TestCase { ...@@ -167,6 +168,17 @@ public class OpenCVTestCase extends TestCase {
super.tearDown(); super.tearDown();
} }
protected Mat getMat(int type, double... vals)
{
return new Mat(matSize, matSize, type, new Scalar(vals));
}
protected Mat makeMask(Mat m, double... vals)
{
m.submat(0, m.rows(), 0, m.cols() / 2).setTo(new Scalar(vals));
return m;
}
public static <E extends Number> void assertListEquals(List<E> list1, List<E> list2) { public static <E extends Number> void assertListEquals(List<E> list1, List<E> list2) {
if (list1.size() != list2.size()) { if (list1.size() != list2.size()) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
...@@ -219,10 +231,11 @@ public class OpenCVTestCase extends TestCase { ...@@ -219,10 +231,11 @@ public class OpenCVTestCase extends TestCase {
} }
public static void assertRectEquals(Rect expected, Rect actual) { public static void assertRectEquals(Rect expected, Rect actual) {
assertEquals(expected.x, actual.x); String msg = "expected:<" + expected + "> but was:<" + actual + ">";
assertEquals(expected.y, actual.y); assertEquals(msg, expected.x, actual.x);
assertEquals(expected.width, actual.width); assertEquals(msg, expected.y, actual.y);
assertEquals(expected.height, actual.height); assertEquals(msg, expected.width, actual.width);
assertEquals(msg, expected.height, actual.height);
} }
public static void assertMatEqual(Mat m1, Mat m2) { public static void assertMatEqual(Mat m1, Mat m2) {
...@@ -242,12 +255,13 @@ public class OpenCVTestCase extends TestCase { ...@@ -242,12 +255,13 @@ public class OpenCVTestCase extends TestCase {
} }
public static void assertKeyPointEqual(KeyPoint expected, KeyPoint actual, double eps) { public static void assertKeyPointEqual(KeyPoint expected, KeyPoint actual, double eps) {
assertTrue(Math.hypot(expected.pt.x - actual.pt.x, expected.pt.y - actual.pt.y) < eps); String msg = "expected:<" + expected + "> but was:<" + actual + ">";
assertTrue(Math.abs(expected.size - actual.size) < eps); assertTrue(msg, Math.hypot(expected.pt.x - actual.pt.x, expected.pt.y - actual.pt.y) < eps);
assertTrue(Math.abs(expected.angle - actual.angle) < eps); assertTrue(msg, Math.abs(expected.size - actual.size) < eps);
assertTrue(Math.abs(expected.response - actual.response) < eps); assertTrue(msg, Math.abs(expected.angle - actual.angle) < eps);
assertEquals(expected.octave, actual.octave); assertTrue(msg, Math.abs(expected.response - actual.response) < eps);
assertEquals(expected.class_id, actual.class_id); assertEquals(msg, expected.octave, actual.octave);
assertEquals(msg, expected.class_id, actual.class_id);
} }
public static void assertListKeyPointEquals(List<KeyPoint> expected, List<KeyPoint> actual, double epsilon) { public static void assertListKeyPointEquals(List<KeyPoint> expected, List<KeyPoint> actual, double epsilon) {
...@@ -257,10 +271,19 @@ public class OpenCVTestCase extends TestCase { ...@@ -257,10 +271,19 @@ public class OpenCVTestCase extends TestCase {
} }
public static void assertDMatchEqual(DMatch expected, DMatch actual, double eps) { public static void assertDMatchEqual(DMatch expected, DMatch actual, double eps) {
assertEquals(expected.queryIdx, actual.queryIdx); String msg = "expected:<" + expected + "> but was:<" + actual + ">";
assertEquals(expected.trainIdx, actual.trainIdx); assertEquals(msg, expected.queryIdx, actual.queryIdx);
assertEquals(expected.imgIdx, actual.imgIdx); assertEquals(msg, expected.trainIdx, actual.trainIdx);
assertTrue(Math.abs(expected.distance - actual.distance) < eps); assertEquals(msg, expected.imgIdx, actual.imgIdx);
assertTrue(msg, Math.abs(expected.distance - actual.distance) < eps);
}
public static void assertScalarEqual(Scalar expected, Scalar actual, double eps) {
String msg = "expected:<" + expected + "> but was:<" + actual + ">";
assertTrue(msg, Math.abs(expected.val[0] - actual.val[0]) < eps);
assertTrue(msg, Math.abs(expected.val[1] - actual.val[1]) < eps);
assertTrue(msg, Math.abs(expected.val[2] - actual.val[2]) < eps);
assertTrue(msg, Math.abs(expected.val[3] - actual.val[3]) < eps);
} }
public static void assertListDMatchEquals(List<DMatch> expected, List<DMatch> actual, double epsilon) { public static void assertListDMatchEquals(List<DMatch> expected, List<DMatch> actual, double epsilon) {
...@@ -270,13 +293,14 @@ public class OpenCVTestCase extends TestCase { ...@@ -270,13 +293,14 @@ public class OpenCVTestCase extends TestCase {
} }
public static void assertPointEquals(Point expected, Point actual, double eps) { public static void assertPointEquals(Point expected, Point actual, double eps) {
assertEquals(expected.x, actual.x, eps); String msg = "expected:<" + expected + "> but was:<" + actual + ">";
assertEquals(expected.y, actual.y, eps); assertEquals(msg, expected.x, actual.x, eps);
assertEquals(msg, 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() || expected.rows() != actual.rows()) { if (expected.type() != actual.type() || expected.cols() != actual.cols() || expected.rows() != actual.rows()) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException("Can not compare " + expected + " and " + actual);
} }
if (expected.depth() == CvType.CV_32F || expected.depth() == CvType.CV_64F) { if (expected.depth() == CvType.CV_32F || expected.depth() == CvType.CV_64F) {
...@@ -304,7 +328,7 @@ public class OpenCVTestCase extends TestCase { ...@@ -304,7 +328,7 @@ public class OpenCVTestCase extends TestCase {
static private void compareMats(Mat expected, Mat actual, double eps, boolean isEqualityMeasured) { 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()) { if (expected.type() != actual.type() || expected.cols() != actual.cols() || expected.rows() != actual.rows()) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException("Can not compare " + expected + " and " + actual);
} }
Mat diff = new Mat(); Mat diff = new Mat();
......
...@@ -16,83 +16,101 @@ import org.opencv.core.Scalar; ...@@ -16,83 +16,101 @@ import org.opencv.core.Scalar;
import org.opencv.core.Size; import org.opencv.core.Size;
import org.opencv.core.TermCriteria; import org.opencv.core.TermCriteria;
import org.opencv.test.OpenCVTestCase; import org.opencv.test.OpenCVTestCase;
import org.opencv.utils.Converters;
public class CoreTest extends OpenCVTestCase { public class CoreTest extends OpenCVTestCase {
public void testAbsdiff() { public void testAbsdiff() {
Core.absdiff(gray128, gray255, dst); Core.absdiff(gray128, gray255, dst);
assertMatEqual(gray127, dst); assertMatEqual(gray127, dst);
} }
public void testAddMatMatMat() { public void testAddMatMatMat() {
Core.add(gray128, gray128, dst); Core.add(gray128, gray128, dst);
assertMatEqual(gray255, dst); assertMatEqual(gray255, dst);
} }
public void testAddMatMatMatMat() { public void testAddMatMatMatMat() {
Core.add(gray0, gray1, dst, gray1); Mat mask = makeMask(gray1.clone());
assertMatEqual(gray1, dst);
dst.setTo(new Scalar(127)); Core.add(gray127, gray1, dst, mask);
Core.add(gray0, gray1, dst, gray0);
assertMatEqual(gray127, dst); assertMatEqual(makeMask(gray128), dst);
/* TODO: !!!! BUG !!!!
* Explaination:
* 1) dst is uninitialized => add allocates it
* 2) left half of mask is zeor => add do not assign it
* 3) so left part of dst remains uninitialized => filled with random
* values */
} }
public void testAddMatMatMatMatInt() { public void testAddMatMatMatMatInt() {
Core.add(gray0, gray1, dst, gray1, CvType.CV_32F); Core.add(gray0, gray1, dst, gray1, CvType.CV_32F);
assertTrue(CvType.CV_32F == dst.depth());
assertEquals(CvType.CV_32F, dst.depth());
assertMatEqual(gray1_32f, dst, EPS); assertMatEqual(gray1_32f, dst, EPS);
} }
public void testAddWeightedMatDoubleMatDoubleDoubleMat() { public void testAddWeightedMatDoubleMatDoubleDoubleMat() {
Core.addWeighted(gray1, 126.0, gray127, 1.0, 2.0, dst); Core.addWeighted(gray1, 120.0, gray127, 1.0, 10.0, dst);
assertMatEqual(gray255, dst); assertMatEqual(gray255, dst);
} }
public void testAddWeightedMatDoubleMatDoubleDoubleMatInt() { public void testAddWeightedMatDoubleMatDoubleDoubleMatInt() {
Core.addWeighted(gray1, 126.0, gray127, 1.0, 2.0, dst, CvType.CV_32F); Core.addWeighted(gray1, 126.0, gray127, 1.0, 2.0, dst, CvType.CV_32F);
assertTrue(CvType.CV_32F == dst.depth());
assertEquals(CvType.CV_32F, dst.depth());
assertMatEqual(gray255_32f, dst, EPS); assertMatEqual(gray255_32f, dst, EPS);
} }
public void testBitwise_andMatMatMat() { public void testBitwise_andMatMatMat() {
Core.bitwise_and(gray3, gray2, dst); Core.bitwise_and(gray127, gray3, dst);
assertMatEqual(gray2, dst);
assertMatEqual(gray3, dst);
} }
public void testBitwise_andMatMatMatMat() { public void testBitwise_andMatMatMatMat() {
Core.bitwise_and(gray0, gray1, dst, gray255); Core.bitwise_and(gray3, gray1, dst, gray255);
assertMatEqual(gray0, dst);
assertMatEqual(gray1, dst);
} }
public void testBitwise_notMatMat() { public void testBitwise_notMatMat() {
Core.bitwise_not(gray255, dst); Core.bitwise_not(gray255, dst);
assertMatEqual(gray0, dst); assertMatEqual(gray0, dst);
} }
public void testBitwise_notMatMatMat() { public void testBitwise_notMatMatMat() {
Core.bitwise_not(gray255, dst, gray255); Core.bitwise_not(gray0, dst, gray1);
assertMatEqual(gray0, dst);
assertMatEqual(gray255, dst);
} }
public void testBitwise_orMatMatMat() { public void testBitwise_orMatMatMat() {
Core.bitwise_or(gray3, gray2, dst); Core.bitwise_or(gray1, gray2, dst);
assertMatEqual(gray3, dst); assertMatEqual(gray3, dst);
} }
public void testBitwise_orMatMatMatMat() { public void testBitwise_orMatMatMatMat() {
Core.bitwise_or(gray127, gray128, dst, gray255); Core.bitwise_or(gray127, gray3, dst, gray255);
assertMatEqual(gray255, dst);
assertMatEqual(gray127, dst);
} }
public void testBitwise_xorMatMatMat() { public void testBitwise_xorMatMatMat() {
Core.bitwise_xor(gray3, gray2, dst); Core.bitwise_xor(gray3, gray2, dst);
assertMatEqual(gray1, dst); assertMatEqual(gray1, dst);
} }
public void testBitwise_xorMatMatMatMat() { public void testBitwise_xorMatMatMatMat() {
Core.bitwise_or(gray127, gray128, dst, gray255); Core.bitwise_or(gray127, gray128, dst, gray255);
assertMatEqual(gray255, dst); assertMatEqual(gray255, dst);
} }
...@@ -111,41 +129,65 @@ public class CoreTest extends OpenCVTestCase { ...@@ -111,41 +129,65 @@ public class CoreTest extends OpenCVTestCase {
Mat mean = new Mat(1, matSize, CvType.CV_32F); Mat mean = new Mat(1, matSize, CvType.CV_32F);
Core.calcCovarMatrix(gray0_32f, covar, mean, Core.COVAR_ROWS | Core.COVAR_NORMAL, CvType.CV_32F); Core.calcCovarMatrix(gray0_32f, covar, mean, Core.COVAR_ROWS | Core.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);
} }
public void testCartToPolarMatMatMatMat() { public void testCartToPolarMatMatMatMat() {
Mat x = new Mat(1, 3, CvType.CV_32F); Mat x = new Mat(1, 3, CvType.CV_32F) {
Mat y = new Mat(1, 3, CvType.CV_32F); {
x.put(0, 0, 3.0, 6.0, 5, 0); put(0, 0, 3.0, 6.0, 5, 0);
y.put(0, 0, 4.0, 8.0, 12.0); }
};
Mat magnitude = new Mat(1, 3, CvType.CV_32F); Mat y = new Mat(1, 3, CvType.CV_32F) {
Mat angle = new Mat(1, 3, CvType.CV_32F); {
magnitude.put(0, 0, 5.0, 10.0, 13.0); put(0, 0, 4.0, 8.0, 12.0);
angle.put(0, 0, 0.92729962, 0.92729962, 1.1759995); }
};
Mat dst_angle = new Mat(); Mat dst_angle = new Mat();
Core.cartToPolar(x, y, dst, dst_angle); Core.cartToPolar(x, y, dst, dst_angle);
Mat magnitude = new Mat(1, 3, CvType.CV_32F) {
{
put(0, 0, 5.0, 10.0, 13.0);
}
};
Mat angle = new Mat(1, 3, CvType.CV_32F) {
{
put(0, 0, 0.92729962, 0.92729962, 1.1759995);
}
};
assertMatEqual(magnitude, dst, EPS); assertMatEqual(magnitude, dst, EPS);
assertMatEqual(angle, dst_angle, EPS); assertMatEqual(angle, dst_angle, EPS);
} }
public void testCartToPolarMatMatMatMatBoolean() { public void testCartToPolarMatMatMatMatBoolean() {
Mat x = new Mat(1, 3, CvType.CV_32F); Mat x = new Mat(1, 3, CvType.CV_32F) {
Mat y = new Mat(1, 3, CvType.CV_32F); {
x.put(0, 0, 3.0, 6.0, 5, 0); put(0, 0, 3.0, 6.0, 5, 0);
y.put(0, 0, 4.0, 8.0, 12.0); }
};
Mat magnitude = new Mat(1, 3, CvType.CV_32F); Mat y = new Mat(1, 3, CvType.CV_32F) {
Mat angle = new Mat(1, 3, CvType.CV_32F); {
put(0, 0, 4.0, 8.0, 12.0);
}
};
Mat dst_angle = new Mat();
magnitude.put(0, 0, 5.0, 10.0, 13.0); Core.cartToPolar(x, y, dst, dst_angle, true);
angle.put(0, 0, 0.92729962, 0.92729962, 1.1759995);
Mat dst_angle = new Mat(); Mat magnitude = new Mat(1, 3, CvType.CV_32F) {
Core.cartToPolar(x, y, dst, dst_angle, false); {
put(0, 0, 5.0, 10.0, 13.0);
}
};
Mat angle = new Mat(1, 3, CvType.CV_32F) {
{
put(0, 0, 53.130356, 53.130356, 67.379814);
}
};
assertMatEqual(magnitude, dst, EPS); assertMatEqual(magnitude, dst, EPS);
assertMatEqual(angle, dst_angle, EPS); assertMatEqual(angle, dst_angle, EPS);
} }
...@@ -185,24 +227,26 @@ public class CoreTest extends OpenCVTestCase { ...@@ -185,24 +227,26 @@ public class CoreTest extends OpenCVTestCase {
} }
public void testCheckRangeMatBooleanPointDouble() { public void testCheckRangeMatBooleanPointDouble() {
double minVal = 256; assertFalse(Core.checkRange(gray255, true, null, 256));
assertFalse(Core.checkRange(gray255, true, null, minVal)); assertTrue(Core.checkRange(gray0, true, null, 0));
minVal = 0;
assertTrue(Core.checkRange(gray0, true, null, minVal));
} }
public void testCheckRangeMatBooleanPointDoubleDouble() { public void testCheckRangeMatBooleanPointDoubleDouble() {
Mat inRange = new Mat(2, 3, CvType.CV_64F); Mat inRange = new Mat(2, 3, CvType.CV_64F) {
inRange.put(0, 0, 14, 48, 76, 33, 5, 99); {
Point pt = new Point(1, 0); put(0, 0, 14, 48, 76, 33, 5, 99);
double minVal = 5; }
double maxVal = 100; };
assertTrue(Core.checkRange(inRange, true, pt, minVal, maxVal));
Mat outOfRange = new Mat(2, 3, CvType.CV_64F); assertTrue(Core.checkRange(inRange, true, null, 5, 100));
outOfRange.put(0, 0, -4, 0, 6, 33, 4, 109);
assertFalse(Core.checkRange(outOfRange, true, pt, minVal, maxVal)); Mat outOfRange = new Mat(2, 3, CvType.CV_64F) {
{
put(0, 0, -4, 0, 6, 33, 4, 109);
}
};
assertFalse(Core.checkRange(outOfRange, true, null, 5, 100));
} }
public void testCircleMatPointIntScalar() { public void testCircleMatPointIntScalar() {
...@@ -210,8 +254,8 @@ public class CoreTest extends OpenCVTestCase { ...@@ -210,8 +254,8 @@ public class CoreTest extends OpenCVTestCase {
int radius = Math.min(gray0.cols() / 4, gray0.rows() / 4); int radius = Math.min(gray0.cols() / 4, gray0.rows() / 4);
Scalar color = new Scalar(128); Scalar color = new Scalar(128);
assertTrue(0 == Core.countNonZero(gray0));
Core.circle(gray0, center, radius, color); Core.circle(gray0, center, radius, color);
assertTrue(0 != Core.countNonZero(gray0)); assertTrue(0 != Core.countNonZero(gray0));
} }
...@@ -220,8 +264,8 @@ public class CoreTest extends OpenCVTestCase { ...@@ -220,8 +264,8 @@ public class CoreTest extends OpenCVTestCase {
int radius = Math.min(gray0.cols() / 4, gray0.rows() / 4); int radius = Math.min(gray0.cols() / 4, gray0.rows() / 4);
Scalar color = new Scalar(128); Scalar color = new Scalar(128);
assertTrue(0 == Core.countNonZero(gray0));
Core.circle(gray0, center, radius, color, Core.FILLED); Core.circle(gray0, center, radius, color, Core.FILLED);
assertTrue(0 != Core.countNonZero(gray0)); assertTrue(0 != Core.countNonZero(gray0));
} }
...@@ -230,8 +274,8 @@ public class CoreTest extends OpenCVTestCase { ...@@ -230,8 +274,8 @@ public class CoreTest extends OpenCVTestCase {
int radius = Math.min(gray0.cols() / 4, gray0.rows() / 4); int radius = Math.min(gray0.cols() / 4, gray0.rows() / 4);
Scalar color = new Scalar(128); Scalar color = new Scalar(128);
assertTrue(0 == Core.countNonZero(gray0));
Core.circle(gray0, center, radius, color, 2, Core.LINE_4); Core.circle(gray0, center, radius, color, 2, Core.LINE_4);
assertTrue(0 != Core.countNonZero(gray0)); assertTrue(0 != Core.countNonZero(gray0));
} }
...@@ -242,25 +286,26 @@ public class CoreTest extends OpenCVTestCase { ...@@ -242,25 +286,26 @@ public class CoreTest extends OpenCVTestCase {
Scalar color128 = new Scalar(128); Scalar color128 = new Scalar(128);
Scalar color0 = new Scalar(0); Scalar color0 = new Scalar(0);
assertTrue(0 == Core.countNonZero(gray0)); Core.circle(gray0, center2, radius * 2, color128, 2, Core.LINE_4, 1/* Number
Core.circle(gray0, center2, radius * 2, color128, 2, 4, 1/* Number of * of
* fractional * fractional
* bits */); * bits */);
Core.circle(gray0, center, radius, color0, 2, 4, 0); assertFalse(0 == Core.countNonZero(gray0));
Core.circle(gray0, center, radius, color0, 2, Core.LINE_4, 0);
assertTrue(0 == Core.countNonZero(gray0)); assertTrue(0 == Core.countNonZero(gray0));
} }
public void testClipLine() { public void testClipLine() {
Rect r = new Rect(10, 10, 10, 10); Rect r = new Rect(10, 10, 10, 10);
Point pt1 = new Point(5.0, 15.0); Point pt1 = new Point(5.0, 15.0);
Point pt2 = new Point(25.0, 15.0); Point pt2 = new Point(25.0, 15.0);
assertTrue(Core.clipLine(r, pt1, pt2));
Point pt1Clipped = new Point(10.0, 15.0); Point pt1Clipped = new Point(10.0, 15.0);
Point pt2Clipped = new Point(19.0, 15.0); Point pt2Clipped = new Point(19.0, 15.0);
boolean res = Core.clipLine(r, pt1, pt2);
assertEquals(true, res);
assertEquals(pt1Clipped, pt1); assertEquals(pt1Clipped, pt1);
assertEquals(pt2Clipped, pt2); assertEquals(pt2Clipped, pt2);
...@@ -269,201 +314,283 @@ public class CoreTest extends OpenCVTestCase { ...@@ -269,201 +314,283 @@ public class CoreTest extends OpenCVTestCase {
pt1Clipped = new Point(5.0, 5.0); pt1Clipped = new Point(5.0, 5.0);
pt2Clipped = new Point(25.0, 5.0); pt2Clipped = new Point(25.0, 5.0);
res = Core.clipLine(r, pt1, pt2); assertFalse(Core.clipLine(r, pt1, pt2));
assertEquals(false, res);
assertEquals(pt1Clipped, pt1); assertEquals(pt1Clipped, pt1);
assertEquals(pt2Clipped, pt2); assertEquals(pt2Clipped, pt2);
} }
public void testCompare() { public void testCompare() {
Core.compare(gray0, gray0, dst, Core.CMP_EQ); Core.compare(gray0, gray0, dst, Core.CMP_EQ);
assertMatEqual(dst, gray255); assertMatEqual(dst, gray255);
Core.compare(gray0, gray1, dst, Core.CMP_EQ); Core.compare(gray0, gray1, dst, Core.CMP_EQ);
assertMatEqual(dst, gray0); assertMatEqual(dst, gray0);
Core.compare(gray0, grayRnd, dst, Core.CMP_EQ); grayRnd.put(0, 0, 0, 0);
double nBlackPixels = Core.countNonZero(dst);
double nNonBlackpixels = Core.countNonZero(grayRnd); Core.compare(gray0, grayRnd, dst, Core.CMP_GE);
assertTrue((nBlackPixels + nNonBlackpixels) == grayRnd.total());
int expected = (int) (grayRnd.total() - Core.countNonZero(grayRnd));
assertEquals(expected, Core.countNonZero(dst));
} }
public void testCompleteSymmMat() { public void testCompleteSymmMat() {
Core.completeSymm(grayRnd_32f); Core.completeSymm(grayRnd_32f);
Core.transpose(grayRnd_32f, dst);
assertMatEqual(grayRnd_32f, dst, EPS); assertMatEqual(grayRnd_32f, grayRnd_32f.t(), EPS);
} }
public void testCompleteSymmMatBoolean() { public void testCompleteSymmMatBoolean() {
Mat grayRnd_32f2 = grayRnd_32f.clone();
Core.completeSymm(grayRnd_32f, true); Core.completeSymm(grayRnd_32f, true);
Core.transpose(grayRnd_32f, dst);
assertMatEqual(grayRnd_32f, dst, EPS); assertMatEqual(grayRnd_32f, grayRnd_32f.t(), EPS);
Core.completeSymm(grayRnd_32f2, false);
assertMatNotEqual(grayRnd_32f2, grayRnd_32f, EPS);
} }
public void testConvertScaleAbsMatMat() { public void testConvertScaleAbsMatMat() {
Core.convertScaleAbs(gray0, dst); Core.convertScaleAbs(gray0, dst);
assertMatEqual(gray0, dst, EPS); assertMatEqual(gray0, dst, EPS);
Core.convertScaleAbs(gray_16u_256, dst); Core.convertScaleAbs(gray_16u_256, dst);
assertMatEqual(gray255, dst, EPS); assertMatEqual(gray255, dst, EPS);
} }
public void testConvertScaleAbsMatMatDouble() { public void testConvertScaleAbsMatMatDouble() {
Core.convertScaleAbs(gray0, dst, 2); Core.convertScaleAbs(gray0, dst, 2);
assertMatEqual(gray0, dst); assertMatEqual(gray0, dst);
Core.convertScaleAbs(gray_16u_256, dst, 1); Core.convertScaleAbs(gray_16u_256, dst, 2);
assertMatEqual(gray255, dst); assertMatEqual(gray255, dst);
} }
public void testConvertScaleAbsMatMatDoubleDouble() { public void testConvertScaleAbsMatMatDoubleDouble() {
Core.convertScaleAbs(gray_16u_256, dst, 2, 2); Core.convertScaleAbs(gray_16u_256, dst, 2, -513);
assertMatEqual(gray255, dst);
assertMatEqual(gray1, dst);
} }
public void testCountNonZero() { public void testCountNonZero() {
assertEquals(0, Core.countNonZero(gray0)); assertEquals(0, Core.countNonZero(gray0));
gray0.put(0, 0, 255); gray0.put(0, 0, 255);
gray0.put(gray0.rows() - 1, gray0.cols() - 1, 255); gray0.put(gray0.rows() - 1, gray0.cols() - 1, 255);
assertEquals(2, Core.countNonZero(gray0)); assertEquals(2, Core.countNonZero(gray0));
} }
public void testCubeRoot() { public void testCubeRoot() {
float res = Core.cubeRoot(27.0f); float res = Core.cubeRoot(-27.0f);
assertEquals(3.0f, res);
assertEquals(-3.0f, res);
} }
public void testDctMatMat() { public void testDctMatMat() {
Core.dct(gray0_32f_1d, dst); Mat in = new Mat(1, 4, CvType.CV_32F) {
assertMatEqual(gray0_32f_1d, dst, EPS); {
put(0, 0, 135.22211, 50.811096, 102.27016, 207.6682);
Mat in = new Mat(1, 4, CvType.CV_32F); }
in.put(0, 0, 135.22211, 50.811096, 102.27016, 207.6682); };
Mat dst1 = new Mat();
Mat dst2 = new Mat();
truth = new Mat(1, 4, CvType.CV_32F); Core.dct(gray0_32f_1d, dst1);
truth.put(0, 0, 247.98576, -61.252407, 94.904533, 14.013477); Core.dct(in, dst2);
Core.dct(in, dst); truth = new Mat(1, 4, CvType.CV_32F) {
assertMatEqual(truth, dst, EPS); {
put(0, 0, 247.98576, -61.252407, 94.904533, 14.013477);
}
};
assertMatEqual(gray0_32f_1d, dst1, EPS);
assertMatEqual(truth, dst2, EPS);
} }
public void testDctMatMatInt() { public void testDctMatMatInt() {
Core.dct(gray0_32f_1d, dst); Mat in = new Mat(1, 4, CvType.CV_32F) {
assertMatEqual(gray0_32f_1d, dst, EPS); {
put(0, 0, 247.98576, -61.252407, 94.904533, 14.013477);
Mat in = new Mat(1, 8, CvType.CV_32F); }
in.put(0, 0, 0.203056, 0.980407, 0.35312, -0.106651, 0.0399382, 0.871475, -0.648355, 0.501067); };
Mat dst1 = new Mat();
Mat dst2 = new Mat();
truth = new Mat(1, 8, CvType.CV_32F); Core.dct(gray0_32f_1d, dst1, Core.DCT_INVERSE);
truth.put(0, 0, 0.77571625, 0.37270021, 0.18529896, 0.012146413, -0.32499927, -0.99302113, 0.55979407, -0.6251272); Core.dct(in, dst2, Core.DCT_INVERSE);
Core.dct(in, dst); truth = new Mat(1, 4, CvType.CV_32F) {
assertMatEqual(truth, dst, EPS); {
put(0, 0, 135.22211, 50.811096, 102.27016, 207.6682);
}
};
assertMatEqual(gray0_32f_1d, dst1, EPS);
assertMatEqual(truth, dst2, EPS);
} }
public void testDeterminant() { public void testDeterminant() {
Mat mat = new Mat(2, 2, CvType.CV_32F); Mat mat = new Mat(2, 2, CvType.CV_32F) {
mat.put(0, 0, 4.0); {
mat.put(0, 1, 2.0); put(0, 0, 4.0);
mat.put(1, 0, 4.0); put(0, 1, 2.0);
mat.put(1, 1, 4.0); put(1, 0, 4.0);
put(1, 1, 4.0);
}
};
double det = Core.determinant(mat); double det = Core.determinant(mat);
assertEquals(8.0, det); assertEquals(8.0, det);
} }
public void testDftMatMat() { public void testDftMatMat() {
Mat src = new Mat(1, 4, CvType.CV_32F); Core.dft(gray0_32f_1d, dst);
src.put(0, 0, 0, 0, 0, 0);
truth = new Mat(1, 4, CvType.CV_32F); assertMatEqual(gray0_32f_1d, dst, EPS);
truth.put(0, 0, 0, 0, 0, 0);
Core.dft(src, dst);
assertMatEqual(truth, dst, EPS);
} }
public void testDftMatMatInt() { public void testDftMatMatInt() {
Mat src = new Mat(1, 4, CvType.CV_32F); Mat src = new Mat(1, 4, CvType.CV_32F) {
truth = new Mat(1, 4, CvType.CV_32F); {
put(0, 0, 1, 2, 3, 4);
}
};
src.put(0, 0, 1, 2, 3, 4);
truth.put(0, 0, 10, -2, 2, -2);
Core.dft(src, dst, Core.DFT_REAL_OUTPUT); Core.dft(src, dst, Core.DFT_REAL_OUTPUT);
truth = new Mat(1, 4, CvType.CV_32F) {
{
put(0, 0, 10, -2, 2, -2);
}
};
assertMatEqual(truth, dst, EPS); assertMatEqual(truth, dst, EPS);
Core.dft(src, dst, Core.DFT_INVERSE); Core.dft(src, dst, Core.DFT_INVERSE);
truth.put(0, 0, 9, -9, 1, 3);
truth = new Mat(1, 4, CvType.CV_32F) {
{
put(0, 0, 9, -9, 1, 3);
}
};
assertMatEqual(truth, dst, EPS); assertMatEqual(truth, dst, EPS);
} }
public void testDftMatMatIntInt() { public void testDftMatMatIntInt() {
Mat src = new Mat(1, 4, CvType.CV_32F); Mat src1 = new Mat(2, 4, CvType.CV_32F) {
src.put(0, 0, 1, 2, 3, 4); {
put(0, 0, 1, 2, 3, 4);
put(1, 0, 1, 1, 1, 1);
}
};
Mat src2 = new Mat(2, 4, CvType.CV_32F) {
{
put(0, 0, 1, 2, 3, 4);
put(1, 0, 0, 0, 0, 0);
}
};
Mat dst1 = new Mat();
Mat dst2 = new Mat();
truth = new Mat(1, 4, CvType.CV_32F); Core.dft(src1, dst1, Core.DFT_REAL_OUTPUT, 1);
truth.put(0, 0, 10, -2, 2, -2); Core.dft(src2, dst2, Core.DFT_REAL_OUTPUT, 0);
Core.dft(src, dst, Core.DFT_REAL_OUTPUT, 1);
assertMatEqual(truth, dst, EPS); assertMatEqual(dst2, dst1, EPS);
} }
public void testDivideDoubleMatMat() { public void testDivideDoubleMatMat() {
Core.divide(4.0, gray2, dst); Core.divide(4.0, gray2, dst);
assertMatEqual(gray2, dst); assertMatEqual(gray2, dst);
Core.divide(4.0, gray0, dst);
assertMatEqual(gray0, dst);
} }
public void testDivideDoubleMatMatInt() { public void testDivideDoubleMatMatInt() {
Core.divide(9.0, gray3, dst, -1); Core.divide(9.0, gray3, dst, CvType.CV_32F);
assertMatEqual(gray3, dst);
assertMatEqual(gray3_32f, dst, EPS);
} }
public void testDivideMatMatMat() { public void testDivideMatMatMat() {
Core.divide(gray2, gray1, dst); Core.divide(gray9, gray3, dst);
assertMatEqual(gray2, dst);
assertMatEqual(gray3, dst);
} }
public void testDivideMatMatMatDouble() { public void testDivideMatMatMatDouble() {
Core.divide(gray2, gray2, dst, 2.0); Core.divide(gray1, gray2, dst, 6.0);
assertMatEqual(gray2, dst);
assertMatEqual(gray3, dst);
} }
public void testDivideMatMatMatDoubleInt() { public void testDivideMatMatMatDoubleInt() {
Core.divide(gray3, gray2, dst, 2.0, gray3.depth()); Core.divide(gray1, gray2, dst, 6.0, CvType.CV_32F);
assertMatEqual(gray3, dst);
assertMatEqual(gray3_32f, dst, EPS);
} }
public void testEigen() { public void testEigen() {
Mat src = new Mat(3, 3, CvType.CV_32FC1, new Scalar(2.0)); Mat src = new Mat(3, 3, CvType.CV_32FC1, new Scalar(2.0));
Mat eigenVals = new Mat(); Mat eigenVals = new Mat();
Mat eigenVecs = new Mat(); Mat eigenVecs = new Mat();
Core.eigen(src, true, eigenVals, eigenVecs);
Mat truthEigenVals = new Mat(3, 1, CvType.CV_32FC1); Core.eigen(src, true, eigenVals, eigenVecs);
truthEigenVals.put(0, 0, 6, 0, 0);
assertMatEqual(eigenVals, truthEigenVals, EPS);
Mat truthEigenVecs = new Mat(3, 3, CvType.CV_32FC1);
truthEigenVecs.put(0, 0, 0.57735026, 0.57735026, 0.57735032);
truthEigenVecs.put(1, 0, 0.70710677, -0.70710677, 0);
truthEigenVecs.put(2, 0, -0.40824831, -0.40824831, 0.81649661);
assertMatEqual(eigenVecs, truthEigenVecs, EPS);
Mat expectedEigenVals = new Mat(3, 1, CvType.CV_32FC1) {
{
put(0, 0, 6, 0, 0);
}
};
Mat expectedEigenVecs = new Mat(3, 3, CvType.CV_32FC1) {
{
put(0, 0, 0.57735026, 0.57735026, 0.57735032);
put(1, 0, 0.70710677, -0.70710677, 0);
put(2, 0, -0.40824831, -0.40824831, 0.81649661);
}
};
assertMatEqual(eigenVals, expectedEigenVals, EPS);
assertMatEqual(eigenVecs, expectedEigenVecs, EPS);
} }
public void testEllipse2Poly() { public void testEllipse2Poly() {
Point center = new Point(4, 4); Point center = new Point(4, 4);
Size axes = new Size(2, 2); Size axes = new Size(2, 2);
List<Point> pts = new ArrayList<Point>();
int angle = 30; int angle = 30;
int arcStart = 30; int arcStart = 30;
int arcEnd = 60; int arcEnd = 60;
int delta = 2; int delta = 2;
List<Point> pts = new ArrayList<Point>();
Core.ellipse2Poly(center, axes, angle, arcStart, arcEnd, delta, pts); Core.ellipse2Poly(center, axes, angle, arcStart, arcEnd, delta, pts);
dst = Converters.vector_Point_to_Mat(pts);
truth = new Mat(16, 1, CvType.CV_32SC2); List<Point> truth = Arrays.asList(
truth.put(0, 0, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, new Point(5, 6),
4, 6, 4, 6, 4, 6, 4, 6, 4, 6, 4, 6, 4, 6, 4, 6); new Point(5, 6),
assertMatEqual(truth, dst); new Point(5, 6),
new Point(5, 6),
new Point(5, 6),
new Point(5, 6),
new Point(5, 6),
new Point(5, 6),
new Point(4, 6),
new Point(4, 6),
new Point(4, 6),
new Point(4, 6),
new Point(4, 6),
new Point(4, 6),
new Point(4, 6),
new Point(4, 6));
assertListPointEquals(truth, pts, EPS);
} }
public void testEllipseMatPointSizeDoubleDoubleDoubleScalar() { public void testEllipseMatPointSizeDoubleDoubleDoubleScalar() {
...@@ -471,8 +598,8 @@ public class CoreTest extends OpenCVTestCase { ...@@ -471,8 +598,8 @@ public class CoreTest extends OpenCVTestCase {
Size axes = new Size(2, 2); Size axes = new Size(2, 2);
double angle = 30, startAngle = 60, endAngle = 90; double angle = 30, startAngle = 60, endAngle = 90;
assertTrue(0 == Core.countNonZero(gray0));
Core.ellipse(gray0, center, axes, angle, startAngle, endAngle, colorWhite); Core.ellipse(gray0, center, axes, angle, startAngle, endAngle, colorWhite);
assertTrue(0 != Core.countNonZero(gray0)); assertTrue(0 != Core.countNonZero(gray0));
} }
...@@ -481,8 +608,8 @@ public class CoreTest extends OpenCVTestCase { ...@@ -481,8 +608,8 @@ public class CoreTest extends OpenCVTestCase {
Size axes = new Size(2, 2); Size axes = new Size(2, 2);
double angle = 30, startAngle = 60, endAngle = 90; double angle = 30, startAngle = 60, endAngle = 90;
assertTrue(0 == Core.countNonZero(gray0));
Core.ellipse(gray0, center, axes, angle, startAngle, endAngle, colorWhite, Core.FILLED); Core.ellipse(gray0, center, axes, angle, startAngle, endAngle, colorWhite, Core.FILLED);
assertTrue(0 != Core.countNonZero(gray0)); assertTrue(0 != Core.countNonZero(gray0));
} }
...@@ -491,24 +618,30 @@ public class CoreTest extends OpenCVTestCase { ...@@ -491,24 +618,30 @@ public class CoreTest extends OpenCVTestCase {
Size axes = new Size(2, 2); Size axes = new Size(2, 2);
double angle = 30, startAngle = 0, endAngle = 30; double angle = 30, startAngle = 0, endAngle = 30;
assertTrue(0 == Core.countNonZero(gray0));
Core.ellipse(gray0, center, axes, angle, startAngle, endAngle, colorWhite, Core.FILLED, Core.LINE_4); Core.ellipse(gray0, center, axes, angle, startAngle, endAngle, colorWhite, Core.FILLED, Core.LINE_4);
assertTrue(0 != Core.countNonZero(gray0)); assertTrue(0 != Core.countNonZero(gray0));
} }
public void testEllipseMatPointSizeDoubleDoubleDoubleScalarIntIntInt() { public void testEllipseMatPointSizeDoubleDoubleDoubleScalarIntIntInt() {
Point center = new Point(gray0.cols() / 2, gray0.rows() / 2); Point center = new Point(gray0.cols() / 2, gray0.rows() / 2);
Size axes = new Size(2, 2); Size axes = new Size(2, 2);
Point center2 = new Point(gray0.cols(), gray0.rows());
Size axes2 = new Size(4, 4);
double angle = 30, startAngle = 0, endAngle = 30; double angle = 30, startAngle = 0, endAngle = 30;
int shift = 1;
Core.ellipse(gray0, center, axes, angle, startAngle, endAngle, colorWhite, Core.FILLED, Core.LINE_4, shift); Core.ellipse(gray0, center, axes, angle, startAngle, endAngle, colorWhite, Core.FILLED, Core.LINE_4, 0);
assertTrue(0 != Core.countNonZero(gray0)); assertTrue(0 != Core.countNonZero(gray0));
Core.ellipse(gray0, center2, axes2, angle, startAngle, endAngle, colorBlack, Core.FILLED, Core.LINE_4, 1);
assertEquals(0, Core.countNonZero(gray0));
} }
public void testEllipseMatRotatedRectScalar() { public void testEllipseMatRotatedRectScalar() {
int matSize = 10; int matSize = 10;
gray0 = Mat.zeros(matSize, matSize, CvType.CV_8U); Mat gray0 = Mat.zeros(matSize, matSize, CvType.CV_8U);
Point center = new Point(matSize / 2, matSize / 2); Point center = new Point(matSize / 2, matSize / 2);
Size size = new Size(matSize / 4, matSize / 2); Size size = new Size(matSize / 4, matSize / 2);
RotatedRect box = new RotatedRect(center, size, 45); RotatedRect box = new RotatedRect(center, size, 45);
...@@ -527,7 +660,7 @@ public class CoreTest extends OpenCVTestCase { ...@@ -527,7 +660,7 @@ public class CoreTest extends OpenCVTestCase {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
assertMatEqual(new Mat(gray0.size(), CvType.CV_8U) { assertMatEqual(new Mat(matSize, matSize, CvType.CV_8U) {
{ {
put(0, 0, truth); put(0, 0, truth);
} }
...@@ -557,30 +690,34 @@ public class CoreTest extends OpenCVTestCase { ...@@ -557,30 +690,34 @@ public class CoreTest extends OpenCVTestCase {
} }
public void testExp() { public void testExp() {
Mat destination = new Mat(matSize, matSize, CvType.CV_32F); Core.exp(gray0_32f, dst);
destination.setTo(new Scalar(0.0));
Core.exp(gray0_32f, destination); assertMatEqual(gray1_32f, dst, EPS);
assertMatEqual(gray1_32f, destination, EPS);
} }
public void testExtractChannel() { public void testExtractChannel() {
Core.extractChannel(rgba128, dst, 0); Core.extractChannel(rgba128, dst, 0);
assertMatEqual(gray128, dst); assertMatEqual(gray128, dst);
} }
public void testFastAtan2() { public void testFastAtan2() {
double delta = 0.01; double eps = 0.3;
float res = Core.fastAtan2(50, 50); float res = Core.fastAtan2(50, 50);
assertEquals(45, res, delta);
assertEquals(45, res, eps);
float res2 = Core.fastAtan2(80, 20); float res2 = Core.fastAtan2(80, 20);
assertEquals(75.96, res2, delta);
assertEquals(Math.atan2(80, 20) * 180 / Math.PI, res2, eps);
} }
public void testFillConvexPolyMatListOfPointScalar() { public void testFillConvexPolyMatListOfPointScalar() {
List<Point> polyline = Arrays.asList(new Point(1, 1), new Point(5, 0), new Point(6, 8), new Point(0, 9)); List<Point> polyline = Arrays.asList(new Point(1, 1), new Point(5, 0), new Point(6, 8), new Point(0, 9));
Core.fillConvexPoly(gray0, polyline, new Scalar(150)); Core.fillConvexPoly(gray0, polyline, new Scalar(150));
assertTrue(0 < Core.countNonZero(gray0)); assertTrue(0 < Core.countNonZero(gray0));
assertTrue(gray0.total() > Core.countNonZero(gray0)); assertTrue(gray0.total() > Core.countNonZero(gray0));
} }
...@@ -598,7 +735,7 @@ public class CoreTest extends OpenCVTestCase { ...@@ -598,7 +735,7 @@ public class CoreTest extends OpenCVTestCase {
public void testFillConvexPolyMatListOfPointScalarIntInt() { public void testFillConvexPolyMatListOfPointScalarIntInt() {
List<Point> polyline1 = Arrays.asList(new Point(1, 1), new Point(5, 1), new Point(5, 8), new Point(1, 8)); List<Point> polyline1 = Arrays.asList(new Point(1, 1), new Point(5, 1), new Point(5, 8), new Point(1, 8));
List<Point> polyline2 = Arrays.asList(new Point(2, 2), new Point(10, 2), new Point(10, 16), new Point(2, 16)); List<Point> polyline2 = Arrays.asList(new Point(2, 2), new Point(10, 2), new Point(10, 16), new Point(2, 16));
//FIXME: https://code.ros.org/trac/opencv/ticket/1284 // FIXME: https://code.ros.org/trac/opencv/ticket/1284
Core.fillConvexPoly(gray0, polyline1, colorWhite, Core.LINE_8, 0); Core.fillConvexPoly(gray0, polyline1, colorWhite, Core.LINE_8, 0);
...@@ -606,14 +743,13 @@ public class CoreTest extends OpenCVTestCase { ...@@ -606,14 +743,13 @@ public class CoreTest extends OpenCVTestCase {
assertTrue(gray0.total() > Core.countNonZero(gray0)); assertTrue(gray0.total() > Core.countNonZero(gray0));
Core.fillConvexPoly(gray0, polyline2, colorBlack, Core.LINE_8, 1); Core.fillConvexPoly(gray0, polyline2, colorBlack, Core.LINE_8, 1);
// OpenCVTestRunner.Log(gray0);
assertEquals("see https://code.ros.org/trac/opencv/ticket/1284", 0, Core.countNonZero(gray0)); assertEquals("see https://code.ros.org/trac/opencv/ticket/1284", 0, Core.countNonZero(gray0));
} }
public void testFillPolyMatListOfListOfPointScalar() { public void testFillPolyMatListOfListOfPointScalar() {
int matSize = 10; int matSize = 10;
gray0 = Mat.zeros(matSize, matSize, CvType.CV_8U); Mat gray0 = Mat.zeros(matSize, matSize, CvType.CV_8U);
List<Point> polyline = Arrays.asList(new Point(1, 4), new Point(1, 8), new Point(4, 1), new Point(7, 8), new Point(7, 4)); List<Point> polyline = Arrays.asList(new Point(1, 4), new Point(1, 8), new Point(4, 1), new Point(7, 8), new Point(7, 4));
List<List<Point>> polylines = new ArrayList<List<Point>>(); List<List<Point>> polylines = new ArrayList<List<Point>>();
polylines.add(polyline); polylines.add(polyline);
...@@ -689,190 +825,265 @@ public class CoreTest extends OpenCVTestCase { ...@@ -689,190 +825,265 @@ public class CoreTest extends OpenCVTestCase {
} }
public void testFlip() { public void testFlip() {
Mat src = new Mat(2, 2, CvType.CV_32F); Mat src = new Mat(2, 2, CvType.CV_32F) {
Mat des_f0 = new Mat(2, 2, CvType.CV_32F); {
src.put(0, 0, 1.0); put(0, 0, 1.0);
src.put(0, 1, 2.0); put(0, 1, 2.0);
src.put(1, 0, 3.0); put(1, 0, 3.0);
src.put(1, 1, 4.0); put(1, 1, 4.0);
des_f0.put(0, 0, 3.0);
des_f0.put(0, 1, 4.0);
des_f0.put(1, 0, 1.0);
des_f0.put(1, 1, 2.0);
Core.flip(src, dst, 0);
assertMatEqual(des_f0, dst, EPS);
Mat des_f1 = new Mat(2, 2, CvType.CV_32F);
des_f1.put(0, 0, 2.0);
des_f1.put(0, 1, 1.0);
des_f1.put(1, 0, 4.0);
des_f1.put(1, 1, 3.0);
Core.flip(src, dst, 1);
assertMatEqual(des_f1, dst, EPS);
} }
};
Mat dst1 = new Mat();
Mat dst2 = new Mat();
public void testGemmMatMatDoubleMatDoubleMat() { Core.flip(src, dst1, 0);
Mat m1 = new Mat(2, 2, CvType.CV_32FC1); Core.flip(src, dst2, 1);
Mat m2 = new Mat(2, 2, CvType.CV_32FC1);
Mat desired = new Mat(2, 2, CvType.CV_32FC1);
Mat dmatrix = new Mat(2, 2, CvType.CV_32FC1);
m1.put(0, 0, 1.0, 0.0);
m1.put(1, 0, 1.0, 0.0);
m2.put(0, 0, 1.0, 0.0);
m2.put(1, 0, 1.0, 0.0);
dmatrix.put(0, 0, 0.001, 0.001); Mat dst_f1 = new Mat(2, 2, CvType.CV_32F) {
dmatrix.put(1, 0, 0.001, 0.001); {
put(0, 0, 3.0);
put(0, 1, 4.0);
put(1, 0, 1.0);
put(1, 1, 2.0);
}
};
Mat dst_f2 = new Mat(2, 2, CvType.CV_32F) {
{
put(0, 0, 2.0);
put(0, 1, 1.0);
put(1, 0, 4.0);
put(1, 1, 3.0);
}
};
assertMatEqual(dst_f1, dst1, EPS);
assertMatEqual(dst_f2, dst2, EPS);
}
desired.put(0, 0, 1.001, 0.001); public void testGemmMatMatDoubleMatDoubleMat() {
desired.put(1, 0, 1.001, 0.001); Mat m1 = new Mat(2, 2, CvType.CV_32FC1) {
{
put(0, 0, 1.0, 0.0);
put(1, 0, 1.0, 0.0);
}
};
Mat m2 = new Mat(2, 2, CvType.CV_32FC1) {
{
put(0, 0, 1.0, 0.0);
put(1, 0, 1.0, 0.0);
}
};
Mat dmatrix = new Mat(2, 2, CvType.CV_32FC1) {
{
put(0, 0, 0.001, 0.001);
put(1, 0, 0.001, 0.001);
}
};
Core.gemm(m1, m2, 1.0, dmatrix, 1.0, dst); Core.gemm(m1, m2, 1.0, dmatrix, 1.0, dst);
assertMatEqual(desired, dst, EPS);
Mat expected = new Mat(2, 2, CvType.CV_32FC1) {
{
put(0, 0, 1.001, 0.001);
put(1, 0, 1.001, 0.001);
}
};
assertMatEqual(expected, dst, EPS);
} }
public void testGemmMatMatDoubleMatDoubleMatInt() { public void testGemmMatMatDoubleMatDoubleMatInt() {
Mat m1 = new Mat(2, 2, CvType.CV_32FC1); Mat m1 = new Mat(2, 2, CvType.CV_32FC1) {
Mat m2 = new Mat(2, 2, CvType.CV_32FC1); {
Mat desired = new Mat(2, 2, CvType.CV_32FC1); put(0, 0, 1.0, 0.0);
Mat dmatrix = new Mat(2, 2, CvType.CV_32FC1); put(1, 0, 1.0, 0.0);
}
m1.put(0, 0, 1.0, 0.0); };
m1.put(1, 0, 1.0, 0.0); Mat m2 = new Mat(2, 2, CvType.CV_32FC1) {
{
m2.put(0, 0, 1.0, 0.0); put(0, 0, 1.0, 0.0);
m2.put(1, 0, 1.0, 0.0); put(1, 0, 1.0, 0.0);
}
dmatrix.put(0, 0, 0.001, 0.001); };
dmatrix.put(1, 0, 0.001, 0.001); Mat dmatrix = new Mat(2, 2, CvType.CV_32FC1) {
{
desired.put(0, 0, 2.001, 0.001); put(0, 0, 0.001, 0.001);
desired.put(1, 0, 0.001, 0.001); put(1, 0, 0.001, 0.001);
}
};
Core.gemm(m1, m2, 1.0, dmatrix, 1.0, dst, Core.GEMM_1_T); Core.gemm(m1, m2, 1.0, dmatrix, 1.0, dst, Core.GEMM_1_T);
assertMatEqual(desired, dst, EPS);
Mat expected = new Mat(2, 2, CvType.CV_32FC1) {
{
put(0, 0, 2.001, 0.001);
put(1, 0, 0.001, 0.001);
}
};
assertMatEqual(expected, dst, EPS);
} }
public void testGetCPUTickCount() { public void testGetCPUTickCount() {
long cpuCountStart = 0, actualTickCount; long cpuCountStart = 0, actualTickCount;
cpuCountStart = Core.getCPUTickCount(); cpuCountStart = Core.getCPUTickCount();
Core.sumElems(gray255); Core.sumElems(gray255);
actualTickCount = Core.getCPUTickCount(); actualTickCount = Core.getCPUTickCount();
long expectedTickCount = actualTickCount - cpuCountStart; long expectedTickCount = actualTickCount - cpuCountStart;
assertTrue(expectedTickCount > 0); assertTrue(expectedTickCount > 0);
} }
public void testGetNumberOfCPUs() { public void testGetNumberOfCPUs() {
int cpus = Core.getNumberOfCPUs(); int cpus = Core.getNumberOfCPUs();
assertEquals(Runtime.getRuntime().availableProcessors(), cpus); assertEquals(Runtime.getRuntime().availableProcessors(), cpus);
} }
public void testGetOptimalDFTSize() { public void testGetOptimalDFTSize() {
int vecsize = Core.getOptimalDFTSize(0); assertEquals(1, Core.getOptimalDFTSize(0));
assertEquals(1, vecsize); assertEquals(135, Core.getOptimalDFTSize(133));
assertEquals(15, Core.getOptimalDFTSize(13));
int largeVecSize = Core.getOptimalDFTSize(133);
assertEquals(135, largeVecSize);
largeVecSize = Core.getOptimalDFTSize(13);
assertEquals(15, largeVecSize);
} }
public void testGetTextSize() { public void testGetTextSize() {
String text = "Android all the way"; String text = "Android all the way";
double fontScale = 2; double fontScale = 2;
int thickness = 3; int thickness = 3;
int baseLine[] = { 1 }; int baseLine[] = new int[1];
Core.getTextSize(text, Core.FONT_HERSHEY_SCRIPT_SIMPLEX, fontScale, thickness, null);
Size res = Core.getTextSize(text, Core.FONT_HERSHEY_SCRIPT_SIMPLEX, fontScale, thickness, baseLine); Size res = Core.getTextSize(text, Core.FONT_HERSHEY_SCRIPT_SIMPLEX, fontScale, thickness, baseLine);
assertEquals(543.0, res.width); assertEquals(543.0, res.width);
assertEquals(44.0, res.height); assertEquals(44.0, res.height);
assertEquals(20, baseLine[0]);
} }
public void testGetTickCount() { public void testGetTickCount() {
long startCount, endCount, count; long startCount, endCount, count;
startCount = Core.getTickCount(); startCount = Core.getTickCount();
Core.divide(gray2, gray1, dst); Core.divide(gray2, gray1, dst);
endCount = Core.getTickCount(); endCount = Core.getTickCount();
count = endCount - startCount; count = endCount - startCount;
assertTrue(count > 0); assertTrue(count > 0);
} }
public void testGetTickFrequency() { public void testGetTickFrequency() {
double freq = 0.0; double freq1 = Core.getTickFrequency();
freq = Core.getTickFrequency(); Core.divide(gray2, gray1, dst);
assertTrue(0.0 != freq); double freq2 = Core.getTickFrequency();
assertTrue(0 < freq1);
assertEquals(freq1, freq2);
} }
public void testHconcat() { public void testHconcat() {
Mat e = Mat.eye(3, 3, CvType.CV_8UC1); List<Mat> mats = Arrays.asList(Mat.eye(3, 3, CvType.CV_8U), Mat.zeros(3, 2, CvType.CV_8U));
Mat eConcat = new Mat(1, 9, CvType.CV_8UC1);
eConcat.put(0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1); Core.hconcat(mats, dst);
Core.hconcat(e, dst); assertMatEqual(Mat.eye(3, 5, CvType.CV_8U), dst);
assertMatEqual(eConcat, dst);
} }
public void testIdctMatMat() { public void testIdctMatMat() {
Mat in = new Mat(1, 8, CvType.CV_32F); Mat in = new Mat(1, 8, CvType.CV_32F) {
in.put(0, 0, 1.0, 2.0, 1.0, 0.0, 1.0, 2.0, 3.0, 1.0); {
put(0, 0, 1.0, 2.0, 1.0, 0.0, 1.0, 2.0, 3.0, 1.0);
truth = new Mat(1, 8, CvType.CV_32F); }
truth.put(0, 0, 3.3769724, -1.6215782, 2.3608727, 0.20730907, -0.86502546, 0.028082132, -0.7673766, 0.10917115); };
Core.idct(in, dst); Core.idct(in, dst);
truth = new Mat(1, 8, CvType.CV_32F) {
{
put(0, 0, 3.3769724, -1.6215782, 2.3608727, 0.20730907, -0.86502546, 0.028082132, -0.7673766, 0.10917115);
}
};
assertMatEqual(truth, dst, EPS); assertMatEqual(truth, dst, EPS);
} }
public void testIdctMatMatInt() { public void testIdctMatMatInt() {
Mat in = new Mat(1, 8, CvType.CV_32F); Mat in = new Mat(2, 8, CvType.CV_32F) {
in.put(0, 0, 1.0, 2.0, 1.0, 0.0, 1.0, 2.0, 3.0, 1.0); {
put(0, 0, 1.0, 2.0, 1.0, 0.0, 1.0, 2.0, 3.0, 1.0);
truth = new Mat(1, 8, CvType.CV_32F); put(1, 0, 1.0, 2.0, 1.0, 0.0, 1.0, 2.0, 3.0, 1.0);
truth.put(0, 0, 3.3769724, -1.6215782, 2.3608727, 0.20730907, -0.86502546, 0.028082132, -0.7673766, 0.10917115); }
};
Core.idct(in, dst, Core.DCT_ROWS); Core.idct(in, dst, Core.DCT_ROWS);
truth = new Mat(2, 8, CvType.CV_32F) {
{
put(0, 0, 3.3769724, -1.6215782, 2.3608727, 0.20730907, -0.86502546, 0.028082132, -0.7673766, 0.10917115);
put(1, 0, 3.3769724, -1.6215782, 2.3608727, 0.20730907, -0.86502546, 0.028082132, -0.7673766, 0.10917115);
}
};
assertMatEqual(truth, dst, EPS); assertMatEqual(truth, dst, EPS);
} }
public void testIdftMatMat() { public void testIdftMatMat() {
Mat in = new Mat(1, 4, CvType.CV_32F); Mat in = new Mat(1, 4, CvType.CV_32F) {
in.put(0, 0, 1.0, 2.0, 3.0, 4.0); {
put(0, 0, 1.0, 2.0, 3.0, 4.0);
truth = new Mat(1, 4, CvType.CV_32F); }
truth.put(0, 0, 9, -9, 1, 3); };
Core.idft(in, dst); Core.idft(in, dst);
truth = new Mat(1, 4, CvType.CV_32F) {
{
put(0, 0, 9, -9, 1, 3);
}
};
assertMatEqual(truth, dst, EPS); assertMatEqual(truth, dst, EPS);
} }
public void testIdftMatMatInt() { public void testIdftMatMatInt() {
Mat in = new Mat(1, 4, CvType.CV_32F); Mat in = new Mat(1, 4, CvType.CV_32F) {
in.put(0, 0, 1.0, 2.0, 3.0, 4.0); {
put(0, 0, 1.0, 2.0, 3.0, 4.0);
}
};
Core.idft(in, dst, Core.DFT_SCALE);
truth = new Mat(1, 4, CvType.CV_32F); truth = new Mat(1, 4, CvType.CV_32F) {
truth.put(0, 0, 9, -9, 1, 3); {
Core.idft(in, dst, Core.DFT_REAL_OUTPUT); put(0, 0, 2.25, -2.25, 0.25, 0.75);
}
};
assertMatEqual(truth, dst, EPS); assertMatEqual(truth, dst, EPS);
} }
public void testIdftMatMatIntInt() { public void testIdftMatMatIntInt() {
Mat in = new Mat(1, 4, CvType.CV_32F); Mat in = new Mat(2, 4, CvType.CV_32F) {
in.put(0, 0, 1.0, 2.0, 3.0, 4.0); {
put(0, 0, 1.0, 2.0, 3.0, 4.0);
put(1, 0, 1.0, 2.0, 3.0, 4.0);
}
};
Mat dst = new Mat();
truth = new Mat(1, 4, CvType.CV_32F);
truth.put(0, 0, 9, -9, 1, 3);
Core.idft(in, dst, Core.DFT_REAL_OUTPUT, 1); Core.idft(in, dst, Core.DFT_REAL_OUTPUT, 1);
truth = new Mat(2, 4, CvType.CV_32F) {
{
put(0, 0, 18, -18, 2, 6);
put(1, 0, 0, 0, 0, 0);
}
};
assertMatEqual(truth, dst, EPS); assertMatEqual(truth, dst, EPS);
} }
public void testInRange() { public void testInRange() {
gray0.put(1, 1, 100, 150, 200); gray0.put(1, 1, 100, 150, 200);
Core.inRange(gray0, new Scalar(120), new Scalar(160), dst); Core.inRange(gray0, new Scalar(120), new Scalar(160), dst);
byte vals[] = new byte[3]; byte vals[] = new byte[3];
dst.get(1, 1, vals); dst.get(1, 1, vals);
assertEquals(0, vals[0]); assertEquals(0, vals[0]);
assertEquals(-1, vals[1]); assertEquals(-1, vals[1]);
assertEquals(0, vals[2]); assertEquals(0, vals[2]);
...@@ -884,40 +1095,43 @@ public class CoreTest extends OpenCVTestCase { ...@@ -884,40 +1095,43 @@ public class CoreTest extends OpenCVTestCase {
Core.insertChannel(gray0, rgba128, 1); Core.insertChannel(gray0, rgba128, 1);
Core.insertChannel(gray0, rgba128, 2); Core.insertChannel(gray0, rgba128, 2);
Core.insertChannel(gray0, rgba128, 3); Core.insertChannel(gray0, rgba128, 3);
assertMatEqual(rgba0, rgba128); assertMatEqual(rgba0, rgba128);
} }
public void testInvertMatMat() { public void testInvertMatMat() {
Mat src = new Mat(2, 2, CvType.CV_32F); Mat src = new Mat(2, 2, CvType.CV_32F) {
src.put(0, 0, 1.0); {
src.put(0, 1, 2.0); put(0, 0, 1.0);
src.put(1, 0, 1.5); put(0, 1, 2.0);
src.put(1, 1, 4.0); put(1, 0, 1.5);
put(1, 1, 4.0);
truth = new Mat(2, 2, CvType.CV_32F); }
truth.put(0, 0, 4.0); };
truth.put(0, 1, -2.0);
truth.put(1, 0, -1.5);
truth.put(1, 1, 1.0);
Core.invert(src, dst); Core.invert(src, dst);
assertMatEqual(truth, dst, EPS);
Core.gemm(grayRnd_32f, grayRnd_32f.inv(), 1.0, new Mat(), 0.0, dst); truth = new Mat(2, 2, CvType.CV_32F) {
assertMatEqual(grayE_32f, dst, EPS); {
put(0, 0, 4.0);
put(0, 1, -2.0);
put(1, 0, -1.5);
put(1, 1, 1.0);
}
};
assertMatEqual(truth, dst, EPS);
} }
public void testInvertMatMatInt() { public void testInvertMatMatInt() {
Mat src = Mat.eye(3, 3, CvType.CV_32FC1); Mat src = Mat.eye(3, 3, CvType.CV_32FC1);
src.put(0, 2, 1);
truth = Mat.eye(3, 3, CvType.CV_32FC1); double cond = Core.invert(src, dst, Core.DECOMP_SVD);
Core.invert(src, dst, Core.DECOMP_CHOLESKY); truth = Mat.eye(3, 3, CvType.CV_32FC1);
truth.put(0, 2, -1);
assertMatEqual(truth, dst, EPS); assertMatEqual(truth, dst, EPS);
assertEquals(0.3819660544395447, cond);
Core.invert(src, dst, Core.DECOMP_LU);
double det = Core.determinant(src);
assertTrue(det > 0.0);
} }
public void testKmeansMatIntMatTermCriteriaIntInt() { public void testKmeansMatIntMatTermCriteriaIntInt() {
...@@ -937,13 +1151,11 @@ public class CoreTest extends OpenCVTestCase { ...@@ -937,13 +1151,11 @@ public class CoreTest extends OpenCVTestCase {
int[] first_center = new int[1]; int[] first_center = new int[1];
labels.get(0, 0, first_center); labels.get(0, 0, first_center);
final int c1 = first_center[0]; final int c1 = first_center[0];
Mat expected_labels = new Mat(4, 1, CvType.CV_32S) { Mat expected_labels = new Mat(4, 1, CvType.CV_32S) {
{ {
put(0, 0, c1, c1, 1 - c1, 1 - c1); put(0, 0, c1, c1, 1 - c1, 1 - c1);
} }
}; };
assertMatEqual(expected_labels, labels); assertMatEqual(expected_labels, labels);
} }
...@@ -965,7 +1177,6 @@ public class CoreTest extends OpenCVTestCase { ...@@ -965,7 +1177,6 @@ public class CoreTest extends OpenCVTestCase {
int[] first_center = new int[1]; int[] first_center = new int[1];
labels.get(0, 0, first_center); labels.get(0, 0, first_center);
final int c1 = first_center[0]; final int c1 = first_center[0];
Mat expected_labels = new Mat(4, 1, CvType.CV_32S) { Mat expected_labels = new Mat(4, 1, CvType.CV_32S) {
{ {
put(0, 0, c1, c1, 1 - c1, 1 - c1); put(0, 0, c1, c1, 1 - c1, 1 - c1);
...@@ -977,35 +1188,33 @@ public class CoreTest extends OpenCVTestCase { ...@@ -977,35 +1188,33 @@ public class CoreTest extends OpenCVTestCase {
put(1 - c1, 0, 5.5, 4.5, 3.5, 2.5, 1.5); put(1 - c1, 0, 5.5, 4.5, 3.5, 2.5, 1.5);
} }
}; };
assertMatEqual(expected_labels, labels); assertMatEqual(expected_labels, labels);
assertMatEqual(expected_centers, centers, EPS); assertMatEqual(expected_centers, centers, EPS);
} }
public void testLineMatPointPointScalar() { public void testLineMatPointPointScalar() {
int nPoints = Math.min(gray0.cols(), gray0.rows()); int nPoints = Math.min(gray0.cols(), gray0.rows());
Point point1 = new Point(0, 0); Point point1 = new Point(0, 0);
Point point2 = new Point(nPoints, nPoints); Point point2 = new Point(nPoints, nPoints);
Scalar color = new Scalar(255); Scalar color = new Scalar(255);
Core.line(gray0, point1, point2, color); Core.line(gray0, point1, point2, color);
assertTrue(nPoints == Core.countNonZero(gray0)); assertTrue(nPoints == Core.countNonZero(gray0));
} }
public void testLineMatPointPointScalarInt() { public void testLineMatPointPointScalarInt() {
int nPoints = Math.min(gray0.cols(), gray0.rows()); int nPoints = Math.min(gray0.cols(), gray0.rows());
Point point1 = new Point(0, 0); Point point1 = new Point(0, 0);
Point point2 = new Point(nPoints, nPoints); Point point2 = new Point(nPoints, nPoints);
Core.line(gray0, point1, point2, colorWhite, 0); Core.line(gray0, point1, point2, colorWhite, 0);
assertTrue(nPoints == Core.countNonZero(gray0)); assertTrue(nPoints == Core.countNonZero(gray0));
} }
public void testLineMatPointPointScalarIntInt() { public void testLineMatPointPointScalarIntInt() {
int nPoints = Math.min(gray0.cols(), gray0.rows()); int nPoints = Math.min(gray0.cols(), gray0.rows());
Point point1 = new Point(0, 3); Point point1 = new Point(0, 3);
Point point2 = new Point(nPoints, nPoints); Point point2 = new Point(nPoints, nPoints);
...@@ -1020,12 +1229,10 @@ public class CoreTest extends OpenCVTestCase { ...@@ -1020,12 +1229,10 @@ public class CoreTest extends OpenCVTestCase {
public void testLineMatPointPointScalarIntIntInt() { public void testLineMatPointPointScalarIntIntInt() {
int nPoints = Math.min(gray0.cols(), gray0.rows()); int nPoints = Math.min(gray0.cols(), gray0.rows());
Point point1 = new Point(3, 4); Point point1 = new Point(3, 4);
Point point2 = new Point(nPoints, nPoints); Point point2 = new Point(nPoints, nPoints);
Point point1_4 = new Point(3 * 4, 4 * 4);
Point point1_4 = new Point(3*4, 4*4); Point point2_4 = new Point(nPoints * 4, nPoints * 4);
Point point2_4 = new Point(nPoints*4, nPoints*4);
Core.line(gray0, point2, point1, colorWhite, 2, Core.LINE_8, 0); Core.line(gray0, point2, point1, colorWhite, 2, Core.LINE_8, 0);
...@@ -1037,47 +1244,63 @@ public class CoreTest extends OpenCVTestCase { ...@@ -1037,47 +1244,63 @@ public class CoreTest extends OpenCVTestCase {
} }
public void testLog() { public void testLog() {
Mat in = new Mat(1, 4, CvType.CV_32FC1); Mat in = new Mat(1, 4, CvType.CV_32FC1) {
Mat desired = new Mat(1, 4, CvType.CV_32FC1); {
in.put(0, 0, 1.0, 10.0, 100.0, 1000.0); put(0, 0, 1.0, 10.0, 100.0, 1000.0);
desired.put(0, 0, 0, 2.3025851, 4.6051702, 6.9077554); }
};
Core.log(in, dst); Core.log(in, dst);
assertMatEqual(desired, dst, EPS);
Mat expected = new Mat(1, 4, CvType.CV_32FC1) {
{
put(0, 0, 0, 2.3025851, 4.6051702, 6.9077554);
}
};
assertMatEqual(expected, dst, EPS);
} }
public void testLUTMatMatMat() { public void testLUTMatMatMat() {
Mat lut = new Mat(1, 256, CvType.CV_8UC1); Mat lut = new Mat(1, 256, CvType.CV_8UC1);
lut.setTo(new Scalar(0)); lut.setTo(new Scalar(0));
Core.LUT(grayRnd, lut, dst); Core.LUT(grayRnd, lut, dst);
assertMatEqual(gray0, dst); assertMatEqual(gray0, dst);
lut.setTo(new Scalar(255)); lut.setTo(new Scalar(255));
Core.LUT(grayRnd, lut, dst); Core.LUT(grayRnd, lut, dst);
assertMatEqual(gray255, dst); assertMatEqual(gray255, dst);
} }
public void testLUTMatMatMatInt() { public void testLUTMatMatMatInt() {
Mat lut = new Mat(1, 256, CvType.CV_8UC1); Mat lut = new Mat(1, 256, CvType.CV_8UC1);
lut.setTo(new Scalar(255)); // TODO: ban this overload
Core.LUT(grayRnd, lut, dst, 0); try
assertMatEqual(gray255, dst); {
Core.LUT(grayRnd, lut, dst, 1);
fail("Last parameter for LUT was not supported");
} catch (CvException e) {
// expected
}
} }
public void testMagnitude() { public void testMagnitude() {
Mat x = new Mat(1, 4, CvType.CV_32F); Mat x = new Mat(1, 4, CvType.CV_32F);
Mat y = new Mat(1, 4, CvType.CV_32F); Mat y = new Mat(1, 4, CvType.CV_32F);
Mat out = new Mat(1, 4, CvType.CV_32F);
x.put(0, 0, 3.0, 5.0, 9.0, 6.0); x.put(0, 0, 3.0, 5.0, 9.0, 6.0);
y.put(0, 0, 4.0, 12.0, 40.0, 8.0); y.put(0, 0, 4.0, 12.0, 40.0, 8.0);
out.put(0, 0, 5.0, 13.0, 41.0, 10.0);
Core.magnitude(x, y, dst); Core.magnitude(x, y, dst);
Mat out = new Mat(1, 4, CvType.CV_32F);
out.put(0, 0, 5.0, 13.0, 41.0, 10.0);
assertMatEqual(out, dst, EPS); assertMatEqual(out, dst, EPS);
Core.magnitude(gray0_32f, gray255_32f, dst); Core.magnitude(gray0_32f, gray255_32f, dst);
assertMatEqual(gray255_32f, dst, EPS); assertMatEqual(gray255_32f, dst, EPS);
} }
...@@ -1085,110 +1308,109 @@ public class CoreTest extends OpenCVTestCase { ...@@ -1085,110 +1308,109 @@ 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(grayRnd_32f, covar, mean, Core.COVAR_ROWS | Core.COVAR_NORMAL, CvType.CV_32F); Core.calcCovarMatrix(grayRnd_32f, covar, mean, Core.COVAR_ROWS | Core.COVAR_NORMAL, CvType.CV_32F);
covar.inv(); covar = covar.inv();
Mat line1 = grayRnd_32f.row(0);
Mat line2 = grayRnd_32f.row(1);
Mat line1 = grayRnd_32f.submat(0, 1, 0, grayRnd_32f.cols()); double d = Core.Mahalanobis(line1, line1, covar);
Mat line2 = grayRnd_32f.submat(1, 2, 0, grayRnd_32f.cols());
double d = 0.0;
d = Core.Mahalanobis(line1, line1, covar);
assertEquals(0.0, d); assertEquals(0.0, d);
d = Core.Mahalanobis(line1, line2, covar); d = Core.Mahalanobis(line1, line2, covar);
assertTrue(d > 0.0); assertTrue(d > 0.0);
} }
public void testMax() { public void testMax() {
Core.min(gray0, gray255, dst); Core.max(gray0, gray255, dst);
assertMatEqual(gray0, dst);
assertMatEqual(gray255, dst);
Mat x = new Mat(1, 1, CvType.CV_32F); Mat x = new Mat(1, 1, CvType.CV_32F);
Mat y = new Mat(1, 1, CvType.CV_32F); Mat y = new Mat(1, 1, CvType.CV_32F);
Mat dst = new Mat(1, 1, CvType.CV_32F);
x.put(0, 0, 23.0); x.put(0, 0, 23.0);
y.put(0, 0, 4.0); y.put(0, 0, 4.0);
dst.put(0, 0, 23.0);
Core.max(x, y, dst); Core.max(x, y, dst);
assertMatEqual(dst, dst, EPS);
Mat truth = new Mat(1, 1, CvType.CV_32F);
truth.put(0, 0, 23.0);
assertMatEqual(truth, dst, EPS);
} }
public void testMeanMat() { public void testMeanMat() {
Scalar mean = null; Scalar mean = Core.mean(makeMask(gray128));
mean = Core.mean(gray128); assertScalarEqual(new Scalar(64), mean, EPS);
assertEquals(new Scalar(128), mean);
} }
public void testMeanMatMat() { public void testMeanMatMat() {
Scalar mean = null; Mat mask1 = makeMask(gray1.clone());
Mat mask = gray0.clone(); Mat mask2 = makeMask(gray0, 1);
mean = Core.mean(gray128, mask);
assertEquals(new Scalar(0), mean);
mean = null; Scalar mean1 = Core.mean(grayRnd, mask1);
mask = gray1.clone(); Scalar mean2 = Core.mean(grayRnd, mask2);
mean = Core.mean(gray128, mask); Scalar mean = Core.mean(grayRnd, gray1);
assertEquals(new Scalar(128), mean);
assertScalarEqual(mean, new Scalar(0.5 * (mean1.val[0] + mean2.val[0])), EPS);
} }
public void testMeanStdDevMatMatMat() { public void testMeanStdDevMatMatMat() {
Mat mean = new Mat(); Mat mean = new Mat();
Mat stddev = new Mat(); Mat stddev = new Mat();
Core.meanStdDev(rgba0, mean, stddev); Core.meanStdDev(rgbLena, mean, stddev);
assertEquals(0, Core.countNonZero(mean));
assertEquals(0, Core.countNonZero(stddev)); Mat expectedMean = new Mat(3, 1, CvType.CV_64F) {
{
put(0, 0, 105.3989906311035, 99.56269836425781, 179.7303047180176);
}
};
Mat expectedDev = new Mat(3, 1, CvType.CV_64F) {
{
put(0, 0, 33.74205485167219, 52.8734582803278, 49.01569488056406);
}
};
assertMatEqual(expectedMean, mean, EPS);
assertMatEqual(expectedDev, stddev, EPS);
} }
public void testMeanStdDevMatMatMatMat() { public void testMeanStdDevMatMatMatMat() {
Mat mean = new Mat();
Mat stddev = new Mat();
Core.meanStdDev(rgba0, mean, stddev, gray255);
assertEquals(0, Core.countNonZero(mean));
assertEquals(0, Core.countNonZero(stddev));
Mat submat = grayRnd.submat(0, grayRnd.rows() / 2, 0, grayRnd.cols() / 2); Mat submat = grayRnd.submat(0, grayRnd.rows() / 2, 0, grayRnd.cols() / 2);
submat.setTo(new Scalar(33)); submat.setTo(new Scalar(33));
Mat mask = gray0.clone(); Mat mask = gray0.clone();
submat = mask.submat(0, mask.rows() / 2, 0, mask.cols() / 2); submat = mask.submat(0, mask.rows() / 2, 0, mask.cols() / 2);
submat.setTo(new Scalar(1)); submat.setTo(new Scalar(1));
Mat mean = new Mat();
Mat stddev = new Mat();
Core.meanStdDev(grayRnd, mean, stddev, mask); Core.meanStdDev(grayRnd, mean, stddev, mask);
Mat desiredMean = new Mat(1, 1, CvType.CV_64F, new Scalar(33));
assertMatEqual(desiredMean, mean, EPS);
assertEquals(0, Core.countNonZero(stddev));
Core.meanStdDev(grayRnd, mean, stddev, gray1); Mat expectedMean = new Mat(1, 1, CvType.CV_64F, new Scalar(33));
assertTrue(0 != Core.countNonZero(mean)); Mat expectedDev = new Mat(1, 1, CvType.CV_64F, new Scalar(0));
assertTrue(0 != Core.countNonZero(stddev)); assertMatEqual(expectedMean, mean, EPS);
assertMatEqual(expectedDev, stddev, EPS);
} }
public void testMerge() { public void testMerge() {
Mat src1 = new Mat(2, 2, CvType.CV_32FC1, new Scalar(1)); Mat src1 = new Mat(2, 2, CvType.CV_32FC1, new Scalar(1));
Mat src2 = new Mat(2, 2, CvType.CV_32FC1, new Scalar(2)); Mat src2 = new Mat(2, 2, CvType.CV_32FC1, new Scalar(2));
Mat src3 = new Mat(2, 2, CvType.CV_32FC1, new Scalar(3)); Mat src3 = new Mat(2, 2, CvType.CV_32FC1, new Scalar(3));
List<Mat> listMat = new ArrayList<Mat>(); List<Mat> listMat = Arrays.asList(src1, src2, src3);
listMat.add(src1);
listMat.add(src2);
listMat.add(src3);
Core.merge(listMat, dst); Core.merge(listMat, dst);
truth = new Mat(2, 2, CvType.CV_32FC3); truth = new Mat(2, 2, CvType.CV_32FC3, new Scalar(1, 2, 3));
truth.put(0, 0, 1, 2, 3, 1, 2, 3);
truth.put(1, 0, 1, 2, 3, 1, 2, 3);
assertMatEqual(truth, dst, EPS); assertMatEqual(truth, dst, EPS);
} }
public void testMin() { public void testMin() {
Core.min(gray0, gray255, dst); Core.min(gray0, gray255, dst);
assertMatEqual(gray0, dst); assertMatEqual(gray0, dst);
} }
public void testMinMaxLoc() { public void testMinMaxLocMat() {
double minVal = 1; double minVal = 1;
double maxVal = 10; double maxVal = 10;
Point minLoc = new Point(gray3.cols() / 4, gray3.rows() / 2); Point minLoc = new Point(gray3.cols() / 4, gray3.rows() / 2);
...@@ -1198,225 +1420,261 @@ public class CoreTest extends OpenCVTestCase { ...@@ -1198,225 +1420,261 @@ public class CoreTest extends OpenCVTestCase {
Core.MinMaxLocResult mmres = Core.minMaxLoc(gray3); Core.MinMaxLocResult mmres = Core.minMaxLoc(gray3);
assertTrue(mmres.minVal == minVal); assertEquals(minVal, mmres.minVal);
assertTrue(mmres.maxVal == maxVal); assertEquals(maxVal, mmres.maxVal);
assertTrue(mmres.minLoc.equals(minLoc)); assertPointEquals(minLoc, mmres.minLoc, EPS);
assertTrue(mmres.maxLoc.equals(maxLoc)); assertPointEquals(maxLoc, mmres.maxLoc, EPS);
} }
public void testMinMaxLocMat() { public void testMinMaxLocMatMat() {
MinMaxLocResult res = new MinMaxLocResult(); Mat src = new Mat(4, 4, CvType.CV_8U) {
res = Core.minMaxLoc(gray0); {
assertEquals(0.0, res.minVal); put(0, 0, 2, 4, 27, 3);
assertEquals(0.0, res.maxVal); put(1, 0, 0, 8, 7, 130);
assertEquals(new Point(0, 0), res.minLoc); put(2, 0, 13, 4, 13, 4);
assertEquals(new Point(0, 0), res.maxLoc); put(3, 0, 6, 4, 2, 13);
} }
};
Mat mask = new Mat(4, 4, CvType.CV_8U, new Scalar(0));
mask.submat(1, 3, 1, 4).setTo(new Scalar(1));
public void testMinMaxLocMatMat() { MinMaxLocResult res = Core.minMaxLoc(src, mask);
Mat src = new Mat(4, 4, CvType.CV_8U);
src.put(0, 0, 2, 4, 27, 3); assertEquals(4.0, res.minVal);
src.put(1, 0, 0, 8, 7, 130);
src.put(2, 0, 13, 4, 13, 4);
src.put(3, 0, 6, 4, 2, 13);
Mat mask = src.submat(2, src.rows() / 2, 2, src.cols() / 2);
MinMaxLocResult res = new MinMaxLocResult();
res = Core.minMaxLoc(src, mask);
assertEquals(0.0, res.minVal);
assertEquals(130.0, res.maxVal); assertEquals(130.0, res.maxVal);
assertEquals(new Point(0, 1), res.minLoc); assertPointEquals(new Point(1, 2), res.minLoc, EPS);
assertEquals(new Point(3, 1), res.maxLoc); assertPointEquals(new Point(3, 1), res.maxLoc, EPS);
} }
public void testMixChannels() { public void testMixChannels() {
rgba0.setTo(new Scalar(10, 20, 30, 40)); rgba0.setTo(new Scalar(10, 20, 30, 40));
List<Mat> src = Arrays.asList(rgba0);
List<Mat> result = new ArrayList<Mat>(); List<Mat> dst = Arrays.asList(gray3, gray2, gray1, gray0, getMat(CvType.CV_8UC3, 0, 0, 0));
Core.split(rgba0, result); List<Integer> fromTo = Arrays.asList(
assertEquals(10, (int) result.get(0).get(0, 0)[0]); 3, 0,
assertEquals(20, (int) result.get(1).get(0, 0)[0]); 3, 1,
assertEquals(30, (int) result.get(2).get(0, 0)[0]); 2, 2,
assertEquals(40, (int) result.get(3).get(0, 0)[0]); 0, 3,
2, 4,
List<Mat> src = new ArrayList<Mat>(1); 1, 5,
src.add(rgba0); 0, 6);
List<Mat> dst = new ArrayList<Mat>(4);
dst.add(gray3);
dst.add(gray2);
dst.add(gray1);
dst.add(gray0);
List<Integer> fromTo = new ArrayList<Integer>(8);
fromTo.add(0);
fromTo.add(3);
fromTo.add(1);
fromTo.add(2);
fromTo.add(2);
fromTo.add(1);
fromTo.add(3);
fromTo.add(0);
Core.mixChannels(src, dst, fromTo); Core.mixChannels(src, dst, fromTo);
assertMatEqual(result.get(0), gray0); assertMatEqual(getMat(CvType.CV_8U, 40), dst.get(0));
assertMatEqual(result.get(1), gray1); assertMatEqual(getMat(CvType.CV_8U, 40), dst.get(1));
assertMatEqual(result.get(2), gray2); assertMatEqual(getMat(CvType.CV_8U, 30), dst.get(2));
assertMatEqual(result.get(3), gray3); assertMatEqual(getMat(CvType.CV_8U, 10), dst.get(3));
assertMatEqual(getMat(CvType.CV_8UC3, 30, 20, 10), dst.get(4));
} }
public void testMulSpectrumsMatMatMatInt() { public void testMulSpectrumsMatMatMatInt() {
Mat src1 = new Mat(1, 4, CvType.CV_32F); Mat src1 = new Mat(1, 4, CvType.CV_32F) {
Mat src2 = new Mat(1, 4, CvType.CV_32F); {
Mat out = new Mat(1, 4, CvType.CV_32F); put(0, 0, 1.0, 2.0, 3.0, 4.0);
src1.put(0, 0, 1.0, 2.0, 3.0, 4.0); }
src2.put(0, 0, 1.0, 2.0, 3.0, 4.0); };
out.put(0, 0, 1, -5, 12, 16); Mat src2 = new Mat(1, 4, CvType.CV_32F) {
{
put(0, 0, 1.0, 2.0, 3.0, 4.0);
}
};
Core.mulSpectrums(src1, src2, dst, Core.DFT_ROWS); Core.mulSpectrums(src1, src2, dst, Core.DFT_ROWS);
assertMatEqual(out, dst, EPS);
Mat expected = new Mat(1, 4, CvType.CV_32F) {
{
put(0, 0, 1, -5, 12, 16);
}
};
assertMatEqual(expected, dst, EPS);
} }
public void testMulSpectrumsMatMatMatIntBoolean() { public void testMulSpectrumsMatMatMatIntBoolean() {
Mat src1 = new Mat(1, 4, CvType.CV_32F); Mat src1 = new Mat(1, 4, CvType.CV_32F) {
Mat src2 = new Mat(1, 4, CvType.CV_32F); {
Mat out = new Mat(1, 4, CvType.CV_32F); put(0, 0, 1.0, 2.0, 3.0, 4.0);
src1.put(0, 0, 1.0, 2.0, 3.0, 4.0); }
src2.put(0, 0, 1.0, 2.0, 3.0, 4.0); };
out.put(0, 0, 1, 13, 0, 16); Mat src2 = new Mat(1, 4, CvType.CV_32F) {
{
put(0, 0, 1.0, 2.0, 3.0, 4.0);
}
};
Core.mulSpectrums(src1, src2, dst, Core.DFT_ROWS, true); Core.mulSpectrums(src1, src2, dst, Core.DFT_ROWS, true);
assertMatEqual(out, dst, EPS);
Mat expected = new Mat(1, 4, CvType.CV_32F) {
{
put(0, 0, 1, 13, 0, 16);
}
};
assertMatEqual(expected, dst, EPS);
} }
public void testMultiplyMatMatMat() { public void testMultiplyMatMatMat() {
Core.multiply(gray0, gray255, dst); Core.multiply(gray0, gray255, dst);
assertMatEqual(gray0, dst); assertMatEqual(gray0, dst);
} }
public void testMultiplyMatMatMatDouble() { public void testMultiplyMatMatMatDouble() {
Core.multiply(gray1, gray0, dst, 2.0); Core.multiply(gray1, gray1, dst, 2.0);
assertMatEqual(gray0, dst);
assertMatEqual(gray2, dst);
} }
public void testMultiplyMatMatMatDoubleInt() { public void testMultiplyMatMatMatDoubleInt() {
Core.multiply(gray1, gray0, dst, 2.0, -1); Core.multiply(gray1, gray2, dst, 1.5, CvType.CV_32F);
assertMatEqual(gray0, dst);
assertMatEqual(gray3_32f, dst, EPS);
} }
public void testMulTransposedMatMatBoolean() { public void testMulTransposedMatMatBoolean() {
Core.mulTransposed(grayE_32f, dst, true); Core.mulTransposed(grayE_32f, dst, true);
assertMatEqual(grayE_32f, dst, EPS); assertMatEqual(grayE_32f, dst, EPS);
} }
public void testMulTransposedMatMatBooleanMat() { public void testMulTransposedMatMatBooleanMat() {
Core.mulTransposed(grayRnd_32f, dst, true, grayRnd_32f); Core.mulTransposed(grayRnd_32f, dst, false, grayRnd_32f);
assertMatEqual(gray0_32f, dst, EPS);
Mat grayDelta = new Mat(matSize, matSize, CvType.CV_32F); assertMatEqual(gray0_32f, dst, EPS);
grayDelta.setTo(new Scalar(0.0));
Core.mulTransposed(grayE_32f, dst, true, grayDelta);
assertMatEqual(grayE_32f, dst, EPS);
} }
public void testMulTransposedMatMatBooleanMatDouble() { public void testMulTransposedMatMatBooleanMatDouble() {
Mat grayDelta = new Mat(matSize, matSize, CvType.CV_32F); Core.mulTransposed(grayE_32f, dst, true, gray0_32f, 2);
grayDelta.setTo(new Scalar(0.0));
Core.mulTransposed(grayE_32f, dst, true, grayDelta, 1); truth = gray0_32f;
assertMatEqual(grayE_32f, dst, EPS); truth.diag().setTo(new Scalar(2));
assertMatEqual(truth, dst, EPS);
} }
public void testMulTransposedMatMatBooleanMatDoubleInt() { public void testMulTransposedMatMatBooleanMatDoubleInt() {
Mat a = new Mat(3, 3, CvType.CV_32F); Mat a = getMat(CvType.CV_32F, 1);
Mat grayDelta = new Mat(3, 3, CvType.CV_8U);
grayDelta.setTo(new Scalar(0.0001)); Core.mulTransposed(a, dst, true, gray0_32f, 3, CvType.CV_64F);
Mat res = new Mat(3, 3, CvType.CV_32F);
a.put(0, 0, 1, 1, 1); assertMatEqual(getMat(CvType.CV_64F, 3 * a.rows()), dst, EPS);
a.put(1, 0, 1, 1, 1);
a.put(2, 0, 1, 1, 1);
res.put(0, 0, 3, 3, 3);
res.put(1, 0, 3, 3, 3);
res.put(2, 0, 3, 3, 3);
Core.mulTransposed(a, dst, true, grayDelta, 1.0, 1);
assertMatEqual(res, dst, EPS);
} }
public void testNormalizeMatMat() { public void testNormalizeMatMat() {
Core.normalize(gray0, dst); Mat m = gray0.clone();
m.diag().setTo(new Scalar(2));
Core.normalize(m, dst);
assertMatEqual(gray0, dst); assertMatEqual(gray0, dst);
} }
public void testNormalizeMatMatDouble() { public void testNormalizeMatMatDouble() {
Core.normalize(gray0, dst, 0.0); Mat m = gray0;
assertMatEqual(gray0, dst); m.diag().setTo(new Scalar(1));
Core.normalize(m, dst, 255);
truth = Mat.eye(matSize, matSize, CvType.CV_8U);
truth.diag().setTo(new Scalar(81));
assertMatEqual(truth, dst);
} }
public void testNormalizeMatMatDoubleDouble() { public void testNormalizeMatMatDoubleDouble() {
Core.normalize(gray0, dst, 0.0, 1.0); Core.normalize(gray0, dst, 0.0, 1.0);
// TODO: ban this overload
assertMatEqual(gray0, dst); assertMatEqual(gray0, dst);
} }
public void testNormalizeMatMatDoubleDoubleInt() { public void testNormalizeMatMatDoubleDoubleInt() {
Mat src = new Mat(1, 4, CvType.CV_32F); Mat src = new Mat(1, 4, CvType.CV_32F) {
Mat out = new Mat(1, 4, CvType.CV_32F); {
src.put(0, 0, 1.0, 2.0, 3.0, 4.0); put(0, 0, 1.0, 2.0, 3.0, 4.0);
out.put(0, 0, 0.25, 0.5, 0.75, 1); }
};
Core.normalize(src, dst, 1.0, 2.0, Core.NORM_INF); Core.normalize(src, dst, 1.0, 2.0, Core.NORM_INF);
assertMatEqual(out, dst, EPS);
Mat expected = new Mat(1, 4, CvType.CV_32F) {
{
put(0, 0, 0.25, 0.5, 0.75, 1);
}
};
assertMatEqual(expected, dst, EPS);
} }
public void testNormalizeMatMatDoubleDoubleIntInt() { public void testNormalizeMatMatDoubleDoubleIntInt() {
Mat src = new Mat(1, 4, CvType.CV_32F); Mat src = new Mat(1, 5, CvType.CV_32F) {
Mat out = new Mat(1, 4, CvType.CV_32F); {
put(0, 0, 0, 1, 2, 3, 4);
}
};
src.put(0, 0, 1.0, 2.0, 3.0, 4.0); Core.normalize(src, dst, 1, 2, Core.NORM_MINMAX, CvType.CV_64F);
out.put(0, 0, 0.25, 0.5, 0.75, 1);
Core.normalize(src, dst, 1.0, 2.0, Core.NORM_INF, -1); Mat expected = new Mat(1, 5, CvType.CV_64F) {
assertMatEqual(out, dst, EPS); {
put(0, 0, 1, 1.25, 1.5, 1.75, 2);
}
};
assertMatEqual(expected, dst, EPS);
} }
public void testNormalizeMatMatDoubleDoubleIntIntMat() { public void testNormalizeMatMatDoubleDoubleIntIntMat() {
Mat src = new Mat(1, 4, CvType.CV_32F); Mat src = new Mat(1, 5, CvType.CV_32F) {
Mat out = new Mat(1, 4, CvType.CV_32F); {
Mat mask = new Mat(1, 4, CvType.CV_8U, new Scalar(1)); put(0, 0, 0, 1, 2, 3, 4);
}
src.put(0, 0, 1.0, 2.0, 3.0, 4.0); };
out.put(0, 0, 0.25, 0.5, 0.75, 1); Mat mask = new Mat(1, 5, CvType.CV_8U) {
{
put(0, 0, 1, 0, 0, 0, 1);
}
};
Core.normalize(src, dst, 1.0, 2.0, Core.NORM_INF, -1, mask); Core.normalize(src, dst, 1, 2, Core.NORM_MINMAX, CvType.CV_32F, mask);
assertMatEqual(out, dst, EPS); // OpenCVTestRunner.Log(dst);
Mat expected = new Mat(1, 5, CvType.CV_32F) {
{
put(0, 0, 1, 1, 2, 3, 2);
}
};
assertMatEqual(expected, dst, EPS);
} }
public void testNormMat() { public void testNormMat() {
double n = Core.norm(gray0); double n = Core.norm(gray1);
assertTrue(0.0 == n);
assertEquals(10., n);
} }
public void testNormMatInt() { public void testNormMatInt() {
double n = Core.norm(gray127, Core.NORM_INF); double n = Core.norm(gray127, Core.NORM_INF);
assertTrue(127 == n);
assertEquals(127., n);
} }
public void testNormMatIntMat() { public void testNormMatIntMat() {
double n = Core.norm(gray3, Core.NORM_L1, gray0); double n = Core.norm(gray3, Core.NORM_L1, gray0);
assertEquals(0.0, n); assertEquals(0.0, n);
} }
public void testNormMatMat() { public void testNormMatMat() {
double n = Core.norm(gray255, gray255); double n = Core.norm(gray0, gray1);
assertEquals(0.0, n);
assertEquals(10.0, n);
} }
public void testNormMatMatInt() { public void testNormMatMatInt() {
double n = Core.norm(gray127, gray0, Core.NORM_INF); double n = Core.norm(gray127, gray1, Core.NORM_INF);
assertEquals(127.0, n);
assertEquals(126.0, n);
} }
public void testNormMatMatIntMat() { public void testNormMatMatIntMat() {
double n = Core.norm(gray3, gray0, Core.NORM_L1, gray0); double n = Core.norm(gray3, gray0, Core.NORM_L1, makeMask(gray0.clone(), 1));
assertEquals(0.0, n);
assertEquals(150.0, n);
} }
public void testPCABackProject() { public void testPCABackProject() {
...@@ -1446,7 +1704,6 @@ public class CoreTest extends OpenCVTestCase { ...@@ -1446,7 +1704,6 @@ public class CoreTest extends OpenCVTestCase {
put(2, 0, 0, 0, 0, 0); put(2, 0, 0, 0, 0, 0);
} }
}; };
assertMatEqual(truth, result, EPS); assertMatEqual(truth, result, EPS);
} }
...@@ -1537,7 +1794,6 @@ public class CoreTest extends OpenCVTestCase { ...@@ -1537,7 +1794,6 @@ public class CoreTest extends OpenCVTestCase {
public void testPerspectiveTransform() { public void testPerspectiveTransform() {
Mat src = new Mat(matSize, matSize, CvType.CV_32FC2); Mat src = new Mat(matSize, matSize, CvType.CV_32FC2);
Core.randu(src, 0, 256); Core.randu(src, 0, 256);
Mat transformMatrix = Mat.eye(3, 3, CvType.CV_32F); Mat transformMatrix = Mat.eye(3, 3, CvType.CV_32F);
Core.perspectiveTransform(src, dst, transformMatrix); Core.perspectiveTransform(src, dst, transformMatrix);
...@@ -1546,9 +1802,7 @@ public class CoreTest extends OpenCVTestCase { ...@@ -1546,9 +1802,7 @@ public class CoreTest extends OpenCVTestCase {
public void testPerspectiveTransform3D() { public void testPerspectiveTransform3D() {
Mat src = new Mat(matSize, matSize, CvType.CV_32FC3); Mat src = new Mat(matSize, matSize, CvType.CV_32FC3);
Core.randu(src, 0, 256); Core.randu(src, 0, 256);
Mat transformMatrix = Mat.eye(4, 4, CvType.CV_32F); Mat transformMatrix = Mat.eye(4, 4, CvType.CV_32F);
Core.perspectiveTransform(src, dst, transformMatrix); Core.perspectiveTransform(src, dst, transformMatrix);
...@@ -1557,96 +1811,127 @@ public class CoreTest extends OpenCVTestCase { ...@@ -1557,96 +1811,127 @@ public class CoreTest extends OpenCVTestCase {
} }
public void testPhaseMatMatMat() { public void testPhaseMatMatMat() {
Mat x = new Mat(1, 4, CvType.CV_32F); Mat x = new Mat(1, 4, CvType.CV_32F) {
Mat y = new Mat(1, 4, CvType.CV_32F); {
Mat res = new Mat(1, 4, CvType.CV_32F); put(0, 0, 10.0, 10.0, 20.0, 5.0);
}
x.put(0, 0, 10.0, 10.0, 20.0, 5.0); };
y.put(0, 0, 20.0, 15.0, 20.0, 20.0); Mat y = new Mat(1, 4, CvType.CV_32F) {
res.put(0, 0, 1.1071469, 0.98280007, 0.78539175, 1.3258134); {
put(0, 0, 20.0, 15.0, 20.0, 20.0);
}
};
Core.phase(x, y, dst); Core.phase(x, y, dst);
Mat res = new Mat(1, 4, CvType.CV_32F) {
{
put(0, 0, 1.1071469, 0.98280007, 0.78539175, 1.3258134);
}
};
assertMatEqual(res, dst, EPS); assertMatEqual(res, dst, EPS);
} }
public void testPhaseMatMatMatBoolean() { public void testPhaseMatMatMatBoolean() {
Mat x = new Mat(1, 4, CvType.CV_32F); Mat x = new Mat(1, 4, CvType.CV_32F) {
Mat y = new Mat(1, 4, CvType.CV_32F); {
Mat res = new Mat(1, 4, CvType.CV_32F); put(0, 0, 10.0, 10.0, 20.0, 5.0);
}
x.put(0, 0, 10.0, 10.0, 20.0, 5.0); };
y.put(0, 0, 20.0, 15.0, 20.0, 20.0); Mat y = new Mat(1, 4, CvType.CV_32F) {
res.put(0, 0, 63.434, 56.310, 44.999, 75.963); {
put(0, 0, 20.0, 15.0, 20.0, 20.0);
}
};
Core.phase(x, y, dst, true); Core.phase(x, y, dst, true);
Mat res = new Mat(1, 4, CvType.CV_32F) {
{
put(0, 0, 63.434, 56.310, 44.999, 75.963);
}
};
assertMatEqual(res, dst, EPS);
} }
public void testPolarToCartMatMatMatMat() { public void testPolarToCartMatMatMatMat() {
Mat magnitude = new Mat(1, 3, CvType.CV_32F); Mat magnitude = new Mat(1, 3, CvType.CV_32F) {
Mat angle = new Mat(1, 3, CvType.CV_32F); {
Mat x = new Mat(1, 3, CvType.CV_32F); put(0, 0, 5.0, 10.0, 13.0);
Mat y = new Mat(1, 3, CvType.CV_32F); }
};
Mat angle = new Mat(1, 3, CvType.CV_32F) {
{
put(0, 0, 0.92729962, 0.92729962, 1.1759995);
}
};
Mat xCoordinate = new Mat(); Mat xCoordinate = new Mat();
Mat yCoordinate = new Mat(); Mat yCoordinate = new Mat();
magnitude.put(0, 0, 5.0, 10.0, 13.0);
angle.put(0, 0, 0.92729962, 0.92729962, 1.1759995);
x.put(0, 0, 3.0, 6.0, 5, 0);
y.put(0, 0, 4.0, 8.0, 12.0);
Core.polarToCart(magnitude, angle, xCoordinate, yCoordinate); Core.polarToCart(magnitude, angle, xCoordinate, yCoordinate);
Mat x = new Mat(1, 3, CvType.CV_32F) {
{
put(0, 0, 3.0, 6.0, 5, 0);
}
};
Mat y = new Mat(1, 3, CvType.CV_32F) {
{
put(0, 0, 4.0, 8.0, 12.0);
}
};
assertMatEqual(x, xCoordinate, EPS); assertMatEqual(x, xCoordinate, EPS);
assertMatEqual(y, yCoordinate, EPS); assertMatEqual(y, yCoordinate, EPS);
} }
public void testPolarToCartMatMatMatMatBoolean() { public void testPolarToCartMatMatMatMatBoolean() {
Mat magnitude = new Mat(1, 2, CvType.CV_32F); Mat magnitude = new Mat(1, 3, CvType.CV_32F) {
Mat angle = new Mat(1, 2, CvType.CV_32F); {
Mat x = new Mat(1, 2, CvType.CV_32F); put(0, 0, 5.0, 10.0, 13.0);
Mat y = new Mat(1, 2, CvType.CV_32F); }
};
Mat angle = new Mat(1, 3, CvType.CV_32F) {
{
put(0, 0, 0.92729962, 0.92729962, 1.1759995);
}
};
Mat xCoordinate = new Mat(); Mat xCoordinate = new Mat();
Mat yCoordinate = new Mat(); Mat yCoordinate = new Mat();
magnitude.put(0, 0, 16.0, 10.0);
angle.put(0, 0, 0.92729962, 0.92729962);
x.put(0, 0, 15.997906, 9.9986916);
y.put(0, 0, 0.25893959, 0.16183725);
Core.polarToCart(magnitude, angle, xCoordinate, yCoordinate, true); Core.polarToCart(magnitude, angle, xCoordinate, yCoordinate, true);
Mat x = new Mat(1, 3, CvType.CV_32F) {
{
put(0, 0, 4.9993458, 9.9986916, 12.997262);
}
};
Mat y = new Mat(1, 3, CvType.CV_32F) {
{
put(0, 0, 0.080918625, 0.16183725, 0.26680708);
}
};
assertMatEqual(x, xCoordinate, EPS); assertMatEqual(x, xCoordinate, EPS);
assertMatEqual(y, yCoordinate, EPS); assertMatEqual(y, yCoordinate, EPS);
} }// TODO:FIX
public void testPolylinesMatListOfListOfPointBooleanScalar() { public void testPolylinesMatListOfListOfPointBooleanScalar() {
Mat img = gray0; Mat img = gray0;
List<Point> pts = new ArrayList<Point>();
pts.add(new Point(1, 1));
pts.add(new Point(7, 1));
pts.add(new Point(7, 6));
pts.add(new Point(1, 6));
List<List<Point>> polyline = new ArrayList<List<Point>>(); List<List<Point>> polyline = new ArrayList<List<Point>>();
polyline.add(pts); polyline.add(Arrays.asList(new Point(1, 1), new Point(7, 1), new Point(7, 6), new Point(1, 6)));
Core.polylines(img, polyline, true, new Scalar(100)); Core.polylines(img, polyline, true, new Scalar(100));
assertEquals(22, Core.countNonZero(img)); assertEquals(22, Core.countNonZero(img));
Core.polylines(img, polyline, false, new Scalar(0)); Core.polylines(img, polyline, false, new Scalar(0));
assertEquals(4, Core.countNonZero(img)); assertEquals(4, Core.countNonZero(img));
} }
public void testPolylinesMatListOfListOfPointBooleanScalarInt() { public void testPolylinesMatListOfListOfPointBooleanScalarInt() {
Mat img = gray0; Mat img = gray0;
List<Point> pts = new ArrayList<Point>();
pts.add(new Point(1, 1));
pts.add(new Point(7, 1));
pts.add(new Point(7, 6));
pts.add(new Point(1, 6));
List<List<Point>> polyline = new ArrayList<List<Point>>(); List<List<Point>> polyline = new ArrayList<List<Point>>();
polyline.add(pts); polyline.add(Arrays.asList(new Point(1, 1), new Point(7, 1), new Point(7, 6), new Point(1, 6)));
Core.polylines(img, polyline, true, new Scalar(100), 2); Core.polylines(img, polyline, true, new Scalar(100), 2);
...@@ -1655,14 +1940,8 @@ public class CoreTest extends OpenCVTestCase { ...@@ -1655,14 +1940,8 @@ public class CoreTest extends OpenCVTestCase {
public void testPolylinesMatListOfListOfPointBooleanScalarIntInt() { public void testPolylinesMatListOfListOfPointBooleanScalarIntInt() {
Mat img = gray0; Mat img = gray0;
List<Point> pts = new ArrayList<Point>();
pts.add(new Point(1, 1));
pts.add(new Point(4, 1));
pts.add(new Point(3, 6));
pts.add(new Point(1, 3));
List<List<Point>> polyline = new ArrayList<List<Point>>(); List<List<Point>> polyline = new ArrayList<List<Point>>();
polyline.add(pts); polyline.add(Arrays.asList(new Point(1, 1), new Point(4, 1), new Point(3, 6), new Point(1, 3)));
Core.polylines(img, polyline, true, new Scalar(100), 2, Core.LINE_4); Core.polylines(img, polyline, true, new Scalar(100), 2, Core.LINE_4);
...@@ -1671,10 +1950,8 @@ public class CoreTest extends OpenCVTestCase { ...@@ -1671,10 +1950,8 @@ public class CoreTest extends OpenCVTestCase {
public void testPolylinesMatListOfListOfPointBooleanScalarIntIntInt() { public void testPolylinesMatListOfListOfPointBooleanScalarIntIntInt() {
Mat img = gray0; Mat img = gray0;
List<List<Point>> polyline1 = new ArrayList<List<Point>>(); List<List<Point>> polyline1 = new ArrayList<List<Point>>();
polyline1.add(Arrays.asList(new Point(1, 1), new Point(7, 1), new Point(7, 6), new Point(1, 6))); polyline1.add(Arrays.asList(new Point(1, 1), new Point(7, 1), new Point(7, 6), new Point(1, 6)));
List<List<Point>> polyline2 = new ArrayList<List<Point>>(); List<List<Point>> polyline2 = new ArrayList<List<Point>>();
polyline2.add(Arrays.asList(new Point(2, 2), new Point(14, 2), new Point(14, 12), new Point(2, 12))); polyline2.add(Arrays.asList(new Point(2, 2), new Point(14, 2), new Point(14, 12), new Point(2, 12)));
...@@ -1688,14 +1965,14 @@ public class CoreTest extends OpenCVTestCase { ...@@ -1688,14 +1965,14 @@ public class CoreTest extends OpenCVTestCase {
} }
public void testPow() { public void testPow() {
Core.pow(gray3, 2.0, dst); Core.pow(gray2, 7, dst);
assertMatEqual(gray9, dst);
assertMatEqual(gray128, dst);
} }
public void testPutTextMatStringPointIntDoubleScalar() { public void testPutTextMatStringPointIntDoubleScalar() {
String text = "Hello World"; String text = "Hello World";
Size labelSize = new Size(175, 22); Size labelSize = new Size(175, 22);
Mat img = new Mat(20 + (int) labelSize.height, 20 + (int) labelSize.width, CvType.CV_8U, colorBlack); Mat img = new Mat(20 + (int) labelSize.height, 20 + (int) labelSize.width, CvType.CV_8U, colorBlack);
Point origin = new Point(10, labelSize.height + 10); Point origin = new Point(10, labelSize.height + 10);
...@@ -1710,7 +1987,6 @@ public class CoreTest extends OpenCVTestCase { ...@@ -1710,7 +1987,6 @@ public class CoreTest extends OpenCVTestCase {
public void testPutTextMatStringPointIntDoubleScalarInt() { public void testPutTextMatStringPointIntDoubleScalarInt() {
String text = "Hello World"; String text = "Hello World";
Size labelSize = new Size(176, 22); Size labelSize = new Size(176, 22);
Mat img = new Mat(20 + (int) labelSize.height, 20 + (int) labelSize.width, CvType.CV_8U, colorBlack); Mat img = new Mat(20 + (int) labelSize.height, 20 + (int) labelSize.width, CvType.CV_8U, colorBlack);
Point origin = new Point(10, labelSize.height + 10); Point origin = new Point(10, labelSize.height + 10);
...@@ -1753,14 +2029,17 @@ public class CoreTest extends OpenCVTestCase { ...@@ -1753,14 +2029,17 @@ public class CoreTest extends OpenCVTestCase {
} }
public void testRandn() { public void testRandn() {
assertEquals(0, Core.countNonZero(gray0)); Core.randn(gray0, 100, 23);
Core.randn(gray0, 0, 256);
assertTrue(0 < Core.countNonZero(gray0)); assertEquals(100., Core.mean(gray0).val[0], 23 / 2);
} }
public void testRandShuffleMat() { public void testRandShuffleMat() {
Mat original = new Mat(1, 5, CvType.CV_32F); Mat original = new Mat(1, 5, CvType.CV_32F) {
original.put(0, 0, 7, 5, 2, 8, 1); {
put(0, 0, 7, 5, 2, 8, 1);
}
};
Mat shuffled = original.clone(); Mat shuffled = original.clone();
Core.randShuffle(shuffled); Core.randShuffle(shuffled);
...@@ -1774,8 +2053,11 @@ public class CoreTest extends OpenCVTestCase { ...@@ -1774,8 +2053,11 @@ public class CoreTest extends OpenCVTestCase {
} }
public void testRandShuffleMatDouble() { public void testRandShuffleMatDouble() {
Mat original = new Mat(1, 5, CvType.CV_32F); Mat original = new Mat(1, 5, CvType.CV_32F) {
original.put(0, 0, 7, 5, 2, 8, 1); {
put(0, 0, 7, 5, 2, 8, 1);
}
};
Mat shuffled = original.clone(); Mat shuffled = original.clone();
Core.randShuffle(shuffled, 10); Core.randShuffle(shuffled, 10);
...@@ -1789,169 +2071,222 @@ public class CoreTest extends OpenCVTestCase { ...@@ -1789,169 +2071,222 @@ public class CoreTest extends OpenCVTestCase {
} }
public void testRandu() { public void testRandu() {
assertTrue(0 == Core.countNonZero(gray0)); Core.randu(gray0, 3, 23);
Core.randu(gray0, 0, 256);
assertTrue(0 != Core.countNonZero(gray0)); assertTrue(Core.checkRange(gray0, true, null, 3, 23));
} }
public void testRectangleMatPointPointScalar() { public void testRectangleMatPointPointScalar() {
Point center = new Point(gray0.cols() / 2, gray0.rows() / 2); Point bottomRight = new Point(gray0.cols() / 2, gray0.rows() / 2);
Point origin = new Point(0, 0); Point topLeft = new Point(0, 0);
Scalar color = new Scalar(128); Scalar color = new Scalar(128);
assertTrue(0 == Core.countNonZero(gray0)); Core.rectangle(gray0, bottomRight, topLeft, color);
Core.rectangle(gray0, center, origin, color);
assertTrue(0 != Core.countNonZero(gray0)); assertTrue(0 != Core.countNonZero(gray0));
} }
public void testRectangleMatPointPointScalarInt() { public void testRectangleMatPointPointScalarInt() {
Point center = new Point(gray0.cols(), gray0.rows()); Point bottomRight = new Point(gray0.cols(), gray0.rows());
Point origin = new Point(0, 0); Point topLeft = new Point(0, 0);
Scalar color = new Scalar(128); Scalar color = new Scalar(128);
assertTrue(0 == Core.countNonZero(gray0)); Core.rectangle(gray0, bottomRight, topLeft, color, 2);
Core.rectangle(gray0, center, origin, color, 2); Core.rectangle(gray0, bottomRight, topLeft, colorBlack);
assertTrue(0 != Core.countNonZero(gray0)); assertTrue(0 != Core.countNonZero(gray0));
} }
public void testRectangleMatPointPointScalarIntInt() { public void testRectangleMatPointPointScalarIntInt() {
Point center = new Point(gray0.cols() / 2, gray0.rows() / 2); Point bottomRight = new Point(gray0.cols() / 2, gray0.rows() / 2);
Point origin = new Point(0, 0); Point topLeft = new Point(0, 0);
Scalar color = new Scalar(128); Scalar color = new Scalar(128);
assertTrue(0 == Core.countNonZero(gray0)); Core.rectangle(gray0, bottomRight, topLeft, color, 2, Core.LINE_AA);
Core.rectangle(gray0, center, origin, color, 2, Core.LINE_8); Core.rectangle(gray0, bottomRight, topLeft, colorBlack, 2, Core.LINE_4);
assertTrue(0 != Core.countNonZero(gray0)); assertTrue(0 != Core.countNonZero(gray0));
} }
public void testRectangleMatPointPointScalarIntIntInt() { public void testRectangleMatPointPointScalarIntIntInt() {
Point center = new Point(gray0.cols(), gray0.rows()); Point bottomRight1 = new Point(gray0.cols(), gray0.rows());
Point origin = new Point(0, 0); Point bottomRight2 = new Point(gray0.cols() / 2, gray0.rows() / 2);
Point topLeft = new Point(0, 0);
Scalar color = new Scalar(128); Scalar color = new Scalar(128);
assertTrue(0 == Core.countNonZero(gray0)); Core.rectangle(gray0, bottomRight1, topLeft, color, 2, Core.LINE_8, 1);
Core.rectangle(gray0, center, origin, color, 2, Core.LINE_4, 2);
assertTrue(0 != Core.countNonZero(gray0)); assertTrue(0 != Core.countNonZero(gray0));
Core.rectangle(gray0, bottomRight2, topLeft, colorBlack, 2, Core.LINE_8);
assertEquals(0, Core.countNonZero(gray0));
} }
public void testReduceMatMatIntInt() { public void testReduceMatMatIntInt() {
Mat src = new Mat(2, 2, CvType.CV_32F); Mat src = new Mat(2, 2, CvType.CV_32F) {
Mat out = new Mat(1, 2, CvType.CV_32F); {
src.put(0, 0, 1, 0); put(0, 0, 1, 0);
src.put(1, 0, 1, 0); put(1, 0, 3, 0);
}
};
out.put(0, 0, 1, 0); Core.reduce(src, dst, 0, Core.REDUCE_AVG);
Core.reduce(src, dst, 0, 2); Mat out = new Mat(1, 2, CvType.CV_32F) {
{
put(0, 0, 2, 0);
}
};
assertMatEqual(out, dst, EPS); assertMatEqual(out, dst, EPS);
} }
public void testReduceMatMatIntIntInt() { public void testReduceMatMatIntIntInt() {
Mat src = new Mat(2, 2, CvType.CV_32F); Mat src = new Mat(2, 2, CvType.CV_32F) {
Mat out = new Mat(1, 2, CvType.CV_32F); {
src.put(0, 0, 1, 0); put(0, 0, 1, 0);
src.put(1, 0, 1, 0); put(1, 0, 2, 3);
}
};
out.put(0, 0, 1, 0); Core.reduce(src, dst, 1, Core.REDUCE_SUM, CvType.CV_64F);
Core.reduce(src, dst, 0, 2, -1); Mat out = new Mat(2, 1, CvType.CV_64F) {
{
put(0, 0, 1, 5);
}
};
assertMatEqual(out, dst, EPS); assertMatEqual(out, dst, EPS);
} }
public void testRepeat() { public void testRepeat() {
Mat src = new Mat(1, 3, CvType.CV_32F); Mat src = new Mat(1, 2, CvType.CV_32F, new Scalar(0));
Mat des1 = new Mat(1, 3, CvType.CV_32F);
Mat des2 = new Mat(1, 6, CvType.CV_32F);
src.put(0, 0, 1, 2, 3);
des1.put(0, 0, 1, 2, 3); Core.repeat(src, matSize, matSize / 2, dst);
des2.put(0, 0, 1, 2, 3, 1, 2, 3);
Core.repeat(src, 1, 1, dst); assertMatEqual(gray0_32f, dst, EPS);
assertMatEqual(des1, dst, EPS);
Core.repeat(src, 1, 2, dst);
assertMatEqual(des2, dst, EPS);
} }
public void testScaleAdd() { public void testScaleAdd() {
Core.scaleAdd(gray3, 2.0, gray3, dst); Core.scaleAdd(gray3, 2.0, gray3, dst);
assertMatEqual(dst, gray9);
assertMatEqual(gray9, dst);
} }
public void testSetIdentityMat() { public void testSetIdentityMat() {
Core.setIdentity(gray0_32f); Core.setIdentity(gray0_32f);
assertMatEqual(grayE_32f, gray0_32f, EPS); assertMatEqual(grayE_32f, gray0_32f, EPS);
} }
public void testSetIdentityMatScalar() { public void testSetIdentityMatScalar() {
Core.gemm(grayE_32f, grayE_32f, 5.0, new Mat(), 0.0, dst); Mat m = gray0_32f;
Core.setIdentity(gray0_32f, new Scalar(5));
assertMatEqual(dst, gray0_32f, EPS); Core.setIdentity(m, new Scalar(5));
truth = new Mat(m.size(), m.type(), new Scalar(0));
truth.diag().setTo(new Scalar(5));
assertMatEqual(truth, m, EPS);
} }
public void testSolveCubic() { public void testSolveCubic() {
Mat coeffs = new Mat(1, 4, CvType.CV_32F); Mat coeffs = new Mat(1, 4, CvType.CV_32F) {
Mat roots = new Mat(3, 1, CvType.CV_32F); {
coeffs.put(0, 0, 1, 6, 11, 6); put(0, 0, 1, 6, 11, 6);
roots.put(0, 0, -3, -1, -2); }
Core.solveCubic(coeffs, dst); };
assertEquals(3, Core.solveCubic(coeffs, dst));
Mat roots = new Mat(3, 1, CvType.CV_32F) {
{
put(0, 0, -3, -1, -2);
}
};
assertMatEqual(roots, dst, EPS); assertMatEqual(roots, dst, EPS);
} }
public void testSolveMatMatMat() { public void testSolveMatMatMat() {
Mat a = new Mat(3, 3, CvType.CV_32F); Mat a = new Mat(3, 3, CvType.CV_32F) {
Mat b = new Mat(3, 1, CvType.CV_32F); {
Mat res = new Mat(3, 1, CvType.CV_32F); put(0, 0, 1, 1, 1);
a.put(0, 0, 1, 1, 1); put(1, 0, 1, -2, 2);
a.put(1, 0, 1, -2, 2); put(2, 0, 1, 2, 1);
a.put(2, 0, 1, 2, 1); }
};
Mat b = new Mat(3, 1, CvType.CV_32F) {
{
put(0, 0, 0, 4, 2);
}
};
b.put(0, 0, 0, 4, 2); assertTrue(Core.solve(a, b, dst));
res.put(0, 0, -12, 2, 10);
Core.solve(a, b, dst); Mat res = new Mat(3, 1, CvType.CV_32F) {
{
put(0, 0, -12, 2, 10);
}
};
assertMatEqual(res, dst, EPS); assertMatEqual(res, dst, EPS);
} }
public void testSolveMatMatMatInt() { public void testSolveMatMatMatInt() {
Mat a = new Mat(3, 3, CvType.CV_32F); Mat a = new Mat(3, 3, CvType.CV_32F) {
Mat b = new Mat(3, 1, CvType.CV_32F); {
Mat res = new Mat(3, 1, CvType.CV_32F); put(0, 0, 1, 1, 1);
put(1, 0, 1, -2, 2);
a.put(0, 0, 1, 1, 1); put(2, 0, 1, 2, 1);
a.put(1, 0, 1, -2, 2); }
a.put(2, 0, 1, 2, 1); };
Mat b = new Mat(3, 1, CvType.CV_32F) {
{
put(0, 0, 0, 4, 2);
}
};
b.put(0, 0, 0, 4, 2); assertTrue(Core.solve(a, b, dst, Core.DECOMP_QR | Core.DECOMP_NORMAL));
res.put(0, 0, -12, 2, 10);
Core.solve(a, b, dst, 3); Mat res = new Mat(3, 1, CvType.CV_32F) {
{
put(0, 0, -12, 2, 10);
}
};
assertMatEqual(res, dst, EPS); assertMatEqual(res, dst, EPS);
} }
public void testSolvePolyMatMat() { public void testSolvePolyMatMat() {
Mat coeffs = new Mat(4, 1, CvType.CV_32F); Mat coeffs = new Mat(4, 1, CvType.CV_32F) {
Mat roots = new Mat(3, 1, CvType.CV_32F); {
put(0, 0, -6, 11, -6, 1);
coeffs.put(0, 0, -6, 11, -6, 1); }
};
Mat roots = new Mat();
truth = new Mat(3, 1, CvType.CV_32FC2); assertEquals(0.0, Core.solvePoly(coeffs, roots));
truth.put(0, 0, 1, 0, 2, 0, 3, 0);
Core.solvePoly(coeffs, roots); truth = new Mat(3, 1, CvType.CV_32FC2) {
{
put(0, 0, 1, 0, 2, 0, 3, 0);
}
};
assertMatEqual(truth, roots, EPS); assertMatEqual(truth, roots, EPS);
} }
public void testSolvePolyMatMatInt() { public void testSolvePolyMatMatInt() {
Mat coeffs = new Mat(4, 1, CvType.CV_32F); Mat coeffs = new Mat(4, 1, CvType.CV_32F) {
Mat roots = new Mat(3, 1, CvType.CV_32F); {
put(0, 0, -6, 11, -6, 1);
coeffs.put(0, 0, -6, 11, -6, 1); }
};
Mat roots = new Mat();
truth = new Mat(3, 1, CvType.CV_32FC2); assertEquals(10.198039027185569, Core.solvePoly(coeffs, roots, 1));
truth.put(0, 0, 1, 0, -1, 2, -2, 12);
Core.solvePoly(coeffs, roots, 1); truth = new Mat(3, 1, CvType.CV_32FC2) {
{
put(0, 0, 1, 0, -1, 2, -2, 12);
}
};
assertMatEqual(truth, roots, EPS); assertMatEqual(truth, roots, EPS);
} }
...@@ -1960,11 +2295,14 @@ public class CoreTest extends OpenCVTestCase { ...@@ -1960,11 +2295,14 @@ public class CoreTest extends OpenCVTestCase {
submat.setTo(new Scalar(1.0)); submat.setTo(new Scalar(1.0));
Core.sort(gray0, dst, Core.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, Core.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));
} }
...@@ -1972,64 +2310,68 @@ public class CoreTest extends OpenCVTestCase { ...@@ -1972,64 +2310,68 @@ public class CoreTest extends OpenCVTestCase {
Mat a = Mat.eye(3, 3, CvType.CV_8UC1); Mat a = Mat.eye(3, 3, CvType.CV_8UC1);
Mat b = new Mat(); Mat b = new Mat();
truth = new Mat(3, 3, CvType.CV_32SC1); Core.sortIdx(a, b, Core.SORT_EVERY_ROW | Core.SORT_ASCENDING);
truth.put(0, 0, 1, 2, 0);
truth.put(1, 0, 0, 2, 1);
truth.put(2, 0, 0, 1, 2);
Core.sortIdx(a, b, Core.SORT_EVERY_ROW + Core.SORT_ASCENDING); truth = new Mat(3, 3, CvType.CV_32SC1) {
{
put(0, 0, 1, 2, 0);
put(1, 0, 0, 2, 1);
put(2, 0, 0, 1, 2);
}
};
assertMatEqual(truth, b); assertMatEqual(truth, b);
} }
public void testSplit() { public void testSplit() {
Mat m = getMat(CvType.CV_8UC3, 1, 2, 3);
ArrayList<Mat> cois = new ArrayList<Mat>(); ArrayList<Mat> cois = new ArrayList<Mat>();
Core.split(rgba0, cois);
for (Mat coi : cois) { Core.split(m, cois);
assertMatEqual(gray0, coi);
} assertMatEqual(gray1, cois.get(0));
assertMatEqual(gray2, cois.get(1));
assertMatEqual(gray3, cois.get(2));
} }
public void testSqrt() { public void testSqrt() {
Core.sqrt(gray9_32f, dst); Core.sqrt(gray9_32f, dst);
assertMatEqual(gray3_32f, dst, EPS); assertMatEqual(gray3_32f, dst, EPS);
Mat rgba144 = new Mat(matSize, matSize, CvType.CV_32FC4); Mat rgba144 = new Mat(matSize, matSize, CvType.CV_32FC4, Scalar.all(144));
Mat rgba12 = new Mat(matSize, matSize, CvType.CV_32FC4); Mat rgba12 = new Mat(matSize, matSize, CvType.CV_32FC4, Scalar.all(12));
rgba144.setTo(Scalar.all(144));
rgba12.setTo(Scalar.all(12));
Core.sqrt(rgba144, dst); Core.sqrt(rgba144, dst);
assertMatEqual(rgba12, dst, EPS); assertMatEqual(rgba12, dst, EPS);
} }
public void testSubtractMatMatMat() { public void testSubtractMatMatMat() {
Core.subtract(gray128, gray1, dst); Core.subtract(gray128, gray1, dst);
assertMatEqual(gray127, dst); assertMatEqual(gray127, dst);
} }
public void testSubtractMatMatMatMat() { public void testSubtractMatMatMatMat() {// TODO: fix
Mat mask = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(0)); Mat mask = makeMask(gray1.clone());
Mat submask = mask.submat(0, mask.rows() / 2, 0, mask.cols() / 2);
submask.setTo(new Scalar(1));
dst = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(0)); Core.subtract(gray128, gray1, dst, mask);
Core.subtract(gray3, gray2, dst, mask);
assertTrue(submask.total() == Core.countNonZero(dst)); assertMatEqual(makeMask(gray127), dst);
} }
public void testSubtractMatMatMatMatInt() { public void testSubtractMatMatMatMatInt() {
Core.subtract(gray3, gray2, dst, gray1, CvType.CV_32F); Core.subtract(gray3, gray2, dst, gray1, CvType.CV_32F);
assertTrue(CvType.CV_32F == dst.depth());
assertMatEqual(gray1_32f, dst, EPS); assertMatEqual(gray1_32f, dst, EPS);
} }
public void testSumElems() { public void testSumElems() {
Mat src = new Mat(4, 4, CvType.CV_8U, new Scalar(10)); Mat src = new Mat(4, 4, CvType.CV_8U, new Scalar(10));
Scalar res1 = Core.sumElems(src); Scalar res1 = Core.sumElems(src);
assertEquals(new Scalar(160), res1);
Scalar res2 = Core.sumElems(gray0); assertScalarEqual(new Scalar(160), res1, EPS);
assertEquals(new Scalar(0), res2);
} }
public void testSVBackSubst() { public void testSVBackSubst() {
...@@ -2045,27 +2387,35 @@ public class CoreTest extends OpenCVTestCase { ...@@ -2045,27 +2387,35 @@ public class CoreTest extends OpenCVTestCase {
} }
public void testSVDecompMatMatMatMat() { public void testSVDecompMatMatMatMat() {
Mat src = new Mat(1, 4, CvType.CV_32FC1); Mat src = new Mat(1, 4, CvType.CV_32FC1) {
src.put(0, 0, 1, 4, 8, 6); {
put(0, 0, 1, 4, 8, 6);
}
};
Mat w = new Mat(); Mat w = new Mat();
Mat u = new Mat(); Mat u = new Mat();
Mat vt = new Mat(); Mat vt = new Mat();
Core.SVDecomp(src, w, u, vt); Core.SVDecomp(src, w, u, vt);
Mat truthW = new Mat(1, 1, CvType.CV_32FC1, new Scalar(10.816654)); Mat truthW = new Mat(1, 1, CvType.CV_32FC1, new Scalar(10.816654));
assertMatEqual(truthW, w, EPS);
Mat truthU = new Mat(1, 1, CvType.CV_32FC1, new Scalar(1)); Mat truthU = new Mat(1, 1, CvType.CV_32FC1, new Scalar(1));
Mat truthVT = new Mat(1, 4, CvType.CV_32FC1) {
{
put(0, 0, 0.09245003, 0.36980012, 0.73960024, 0.5547002);
}
};
assertMatEqual(truthW, w, EPS);
assertMatEqual(truthU, u, EPS); assertMatEqual(truthU, u, EPS);
Mat truthVT = new Mat(1, 4, CvType.CV_32FC1);
truthVT.put(0, 0, 0.09245003, 0.36980012, 0.73960024, 0.5547002);
assertMatEqual(truthVT, vt, EPS); assertMatEqual(truthVT, vt, EPS);
} }
public void testSVDecompMatMatMatMatInt() { public void testSVDecompMatMatMatMatInt() {
Mat src = new Mat(1, 4, CvType.CV_32FC1); Mat src = new Mat(1, 4, CvType.CV_32FC1) {
src.put(0, 0, 1, 4, 8, 6); {
put(0, 0, 1, 4, 8, 6);
}
};
Mat w = new Mat(); Mat w = new Mat();
Mat u = new Mat(); Mat u = new Mat();
Mat vt = new Mat(); Mat vt = new Mat();
...@@ -2079,8 +2429,9 @@ public class CoreTest extends OpenCVTestCase { ...@@ -2079,8 +2429,9 @@ public class CoreTest extends OpenCVTestCase {
} }
public void testTrace() { public void testTrace() {
Scalar s = Core.trace(gray0); Scalar s = Core.trace(gray1);
assertEquals(new Scalar(0), s);
assertEquals(new Scalar(matSize), s);
} }
public void testTransform() { public void testTransform() {
...@@ -2088,18 +2439,28 @@ public class CoreTest extends OpenCVTestCase { ...@@ -2088,18 +2439,28 @@ public class CoreTest extends OpenCVTestCase {
Mat m = Mat.eye(2, 2, CvType.CV_32FC1); Mat m = Mat.eye(2, 2, CvType.CV_32FC1);
Core.transform(src, dst, m); Core.transform(src, dst, m);
truth = new Mat(2, 2, CvType.CV_32FC2, new Scalar(55, 1)); truth = new Mat(2, 2, CvType.CV_32FC2, new Scalar(55, 1));
assertMatEqual(truth, dst, EPS); assertMatEqual(truth, dst, EPS);
} }
public void testTranspose() { public void testTranspose() {
Mat subgray0 = gray0.submat(0, gray0.rows() / 2, 0, gray0.cols()); gray0.submat(0, gray0.rows() / 2, 0, gray0.cols()).setTo(new Scalar(1));
Mat destination = new Mat(matSize, matSize, CvType.CV_8U); Mat destination = getMat(CvType.CV_8U, 0);
destination.setTo(new Scalar(0));
Mat subdst = destination.submat(0, destination.rows(), 0, destination.cols() / 2);
subgray0.setTo(new Scalar(1));
Core.transpose(gray0, destination); Core.transpose(gray0, destination);
Mat subdst = destination.submat(0, destination.rows(), 0, destination.cols() / 2);
assertTrue(subdst.total() == Core.countNonZero(subdst)); assertTrue(subdst.total() == Core.countNonZero(subdst));
} }
public void testVconcat() {
List<Mat> mats = Arrays.asList(Mat.eye(3, 3, CvType.CV_8U), Mat.zeros(2, 3, CvType.CV_8U));
Core.vconcat(mats, dst);
assertMatEqual(Mat.eye(5, 3, CvType.CV_8U), dst);
}
} }
...@@ -16,7 +16,6 @@ import org.opencv.core.Size; ...@@ -16,7 +16,6 @@ import org.opencv.core.Size;
import org.opencv.core.TermCriteria; import org.opencv.core.TermCriteria;
import org.opencv.imgproc.Imgproc; import org.opencv.imgproc.Imgproc;
import org.opencv.test.OpenCVTestCase; import org.opencv.test.OpenCVTestCase;
import org.opencv.test.OpenCVTestRunner;
public class ImgprocTest extends OpenCVTestCase { public class ImgprocTest extends OpenCVTestCase {
...@@ -33,17 +32,6 @@ public class ImgprocTest extends OpenCVTestCase { ...@@ -33,17 +32,6 @@ public class ImgprocTest extends OpenCVTestCase {
size = new Size(3, 3); size = new Size(3, 3);
} }
private Mat getMat(int type, double... vals)
{
return new Mat(matSize, matSize, type, new Scalar(vals));
}
private Mat makeMask(Mat m, double... vals)
{
m.submat(0, m.rows(), 0, m.cols() / 2).setTo(new Scalar(vals));
return m;
}
public void testAccumulateMatMat() { public void testAccumulateMatMat() {
Mat src = getMat(CvType.CV_64F, 2); Mat src = getMat(CvType.CV_64F, 2);
Mat dst = getMat(CvType.CV_64F, 0); Mat dst = getMat(CvType.CV_64F, 0);
...@@ -1321,7 +1309,6 @@ public class ImgprocTest extends OpenCVTestCase { ...@@ -1321,7 +1309,6 @@ public class ImgprocTest extends OpenCVTestCase {
Core.circle(gray0, new Point(matSize / 2, matSize / 2), 2, colorWhite, Core.FILLED); Core.circle(gray0, new Point(matSize / 2, matSize / 2), 2, colorWhite, Core.FILLED);
Imgproc.inpaint(gray255, gray0, dst, 3, Imgproc.INPAINT_TELEA); Imgproc.inpaint(gray255, gray0, dst, 3, Imgproc.INPAINT_TELEA);
OpenCVTestRunner.Log(dst);// TODO:remove
assertMatEqual(getMat(CvType.CV_8U, 255), dst); assertMatEqual(getMat(CvType.CV_8U, 255), dst);
} }
...@@ -1849,7 +1836,6 @@ public class ImgprocTest extends OpenCVTestCase { ...@@ -1849,7 +1836,6 @@ public class ImgprocTest extends OpenCVTestCase {
public void testResizeMatMatSizeDoubleDouble() { public void testResizeMatMatSizeDoubleDouble() {
Imgproc.resize(gray255, dst, new Size(), 0.5, 0.5); Imgproc.resize(gray255, dst, new Size(), 0.5, 0.5);
OpenCVTestRunner.Log(dst);
truth = new Mat((int) (matSize * 0.5), (int) (matSize * 0.5), CvType.CV_8U, new Scalar(255)); truth = new Mat((int) (matSize * 0.5), (int) (matSize * 0.5), CvType.CV_8U, new Scalar(255));
assertMatEqual(truth, dst); assertMatEqual(truth, dst);
......
...@@ -124,6 +124,7 @@ missing_consts = \ ...@@ -124,6 +124,7 @@ missing_consts = \
('SVD_MODIFY_A', 1), ('SVD_NO_UV', 2), ('SVD_FULL_UV', 4), ('SVD_MODIFY_A', 1), ('SVD_NO_UV', 2), ('SVD_FULL_UV', 4),
('FILLED', -1), ('FILLED', -1),
('LINE_AA', 16), ('LINE_8', 8), ('LINE_4', 4), ('LINE_AA', 16), ('LINE_8', 8), ('LINE_4', 4),
('REDUCE_SUM', 0), ('REDUCE_AVG', 1), ('REDUCE_MAX', 2), ('REDUCE_MIN', 3),
) #public ) #public
}, # Core }, # Core
...@@ -461,7 +462,6 @@ JNIEXPORT jdoubleArray JNICALL Java_org_opencv_core_Core_n_1getTextSize ...@@ -461,7 +462,6 @@ JNIEXPORT jdoubleArray JNICALL Java_org_opencv_core_Core_n_1getTextSize
"checkHardwareSupport" : {'j_code' : '', 'jn_code' : '', 'cpp_code' : '' }, "checkHardwareSupport" : {'j_code' : '', 'jn_code' : '', 'cpp_code' : '' },
"setUseOptimized" : {'j_code' : '', 'jn_code' : '', 'cpp_code' : '' }, "setUseOptimized" : {'j_code' : '', 'jn_code' : '', 'cpp_code' : '' },
"useOptimized" : {'j_code' : '', 'jn_code' : '', 'cpp_code' : '' }, "useOptimized" : {'j_code' : '', 'jn_code' : '', 'cpp_code' : '' },
"vconcat" : {'j_code' : '', 'jn_code' : '', 'cpp_code' : '' },
}, # Core }, # Core
...@@ -695,6 +695,9 @@ func_arg_fix = { ...@@ -695,6 +695,9 @@ func_arg_fix = {
'pointPolygonTest' : { 'contour' : 'vector_Point2f', }, 'pointPolygonTest' : { 'contour' : 'vector_Point2f', },
'minAreaRect' : { 'points' : 'vector_Point2f', }, 'minAreaRect' : { 'points' : 'vector_Point2f', },
'getAffineTransform' : { 'src' : 'vector_Point2f', 'dst' : 'vector_Point2f', }, 'getAffineTransform' : { 'src' : 'vector_Point2f', 'dst' : 'vector_Point2f', },
'hconcat' : { 'src' : 'vector_Mat', },
'vconcat' : { 'src' : 'vector_Mat', },
}, # '', i.e. no class }, # '', i.e. no class
} # func_arg_fix } # func_arg_fix
......
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