Commit 51338ec7 authored by Andrey Pavlenko's avatar Andrey Pavlenko

Java API: fixing Core tests; minor enchantments in CvVector-s API

parent 5a93b275
...@@ -205,6 +205,26 @@ public class OpenCVTestCase extends TestCase { ...@@ -205,6 +205,26 @@ public class OpenCVTestCase extends TestCase {
assertTrue(Math.abs(list1.get(i).doubleValue() - list2.get(i).doubleValue()) <= epsilon); assertTrue(Math.abs(list1.get(i).doubleValue() - list2.get(i).doubleValue()) <= epsilon);
} }
public static <E extends Number> void assertArrayEquals(E[] ar1, E[] ar2, double epsilon) {
if (ar1.length != ar2.length) {
fail("Arrays have different sizes.");
}
for (int i = 0; i < ar1.length; i++)
assertEquals(ar1[i].doubleValue(), ar2[i].doubleValue(), epsilon);
//assertTrue(Math.abs(ar1[i].doubleValue() - ar2[i].doubleValue()) <= epsilon);
}
public static void assertArrayEquals(double[] ar1, double[] ar2, double epsilon) {
if (ar1.length != ar2.length) {
fail("Arrays have different sizes.");
}
for (int i = 0; i < ar1.length; i++)
assertEquals(ar1[i], ar2[i], epsilon);
//assertTrue(Math.abs(ar1[i].doubleValue() - ar2[i].doubleValue()) <= epsilon);
}
public static void assertListMatEquals(List<Mat> list1, List<Mat> list2, double epsilon) { public static void assertListMatEquals(List<Mat> list1, List<Mat> list2, double epsilon) {
if (list1.size() != list2.size()) { if (list1.size() != list2.size()) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
...@@ -223,6 +243,14 @@ public class OpenCVTestCase extends TestCase { ...@@ -223,6 +243,14 @@ public class OpenCVTestCase extends TestCase {
assertPointEquals(list1.get(i), list2.get(i), epsilon); assertPointEquals(list1.get(i), list2.get(i), epsilon);
} }
public static void assertArrayPointsEquals(Point[] vp1, Point[] vp2, double epsilon) {
if (vp1.length != vp2.length) {
fail("Arrays have different sizes.");
}
for (int i = 0; i < vp1.length; i++)
assertPointEquals(vp1[i], vp2[i], epsilon);
}
public static void assertListPoint3Equals(List<Point3> list1, List<Point3> list2, double epsilon) { public static void assertListPoint3Equals(List<Point3> list1, List<Point3> list2, double epsilon) {
if (list1.size() != list2.size()) { if (list1.size() != list2.size()) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
......
...@@ -4,6 +4,9 @@ import org.opencv.core.Core; ...@@ -4,6 +4,9 @@ import org.opencv.core.Core;
import org.opencv.core.Core.MinMaxLocResult; import org.opencv.core.Core.MinMaxLocResult;
import org.opencv.core.CvException; import org.opencv.core.CvException;
import org.opencv.core.CvType; import org.opencv.core.CvType;
import org.opencv.core.CvVectorDouble;
import org.opencv.core.CvVectorInt;
import org.opencv.core.CvVectorPoint;
import org.opencv.core.Mat; import org.opencv.core.Mat;
import org.opencv.core.Point; import org.opencv.core.Point;
import org.opencv.core.Rect; import org.opencv.core.Rect;
...@@ -482,11 +485,11 @@ public class CoreTest extends OpenCVTestCase { ...@@ -482,11 +485,11 @@ public class CoreTest extends OpenCVTestCase {
int arcStart = 30; int arcStart = 30;
int arcEnd = 60; int arcEnd = 60;
int delta = 2; int delta = 2;
List<Point> pts = new ArrayList<Point>(); CvVectorPoint pts = new CvVectorPoint();
Core.ellipse2Poly(center, axes, angle, arcStart, arcEnd, delta, pts); Core.ellipse2Poly(center, axes, angle, arcStart, arcEnd, delta, pts);
List<Point> truth = Arrays.asList( Point truth[] = {
new Point(5, 6), new Point(5, 6),
new Point(5, 6), new Point(5, 6),
new Point(5, 6), new Point(5, 6),
...@@ -502,8 +505,9 @@ public class CoreTest extends OpenCVTestCase { ...@@ -502,8 +505,9 @@ public class CoreTest extends OpenCVTestCase {
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); };
assertArrayPointsEquals(truth, pts.toArray(new Point[0]), EPS);
} }
public void testEllipseMatPointSizeDoubleDoubleDoubleScalar() { public void testEllipseMatPointSizeDoubleDoubleDoubleScalar() {
...@@ -617,7 +621,7 @@ public class CoreTest extends OpenCVTestCase { ...@@ -617,7 +621,7 @@ public class CoreTest extends OpenCVTestCase {
} }
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)); CvVectorPoint polyline = new CvVectorPoint(new Point[]{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));
...@@ -626,8 +630,8 @@ public class CoreTest extends OpenCVTestCase { ...@@ -626,8 +630,8 @@ public class CoreTest extends OpenCVTestCase {
} }
public void testFillConvexPolyMatListOfPointScalarIntInt() { public void testFillConvexPolyMatListOfPointScalarIntInt() {
List<Point> polyline1 = Arrays.asList(new Point(2, 1), new Point(5, 1), new Point(5, 7), new Point(2, 7)); CvVectorPoint polyline1 = new CvVectorPoint(new Point(2, 1), new Point(5, 1), new Point(5, 7), new Point(2, 7));
List<Point> polyline2 = Arrays.asList(new Point(4, 2), new Point(10, 2), new Point(10, 14), new Point(4, 14)); CvVectorPoint polyline2 = new CvVectorPoint(new Point(4, 2), new Point(10, 2), new Point(10, 14), new Point(4, 14));
// current implementation of fixed-point version of fillConvexPoly // current implementation of fixed-point version of fillConvexPoly
// requires image to be at least 2-pixel wider in each direction than // requires image to be at least 2-pixel wider in each direction than
...@@ -645,8 +649,8 @@ public class CoreTest extends OpenCVTestCase { ...@@ -645,8 +649,8 @@ public class CoreTest extends OpenCVTestCase {
public void testFillPolyMatListOfListOfPointScalar() { public void testFillPolyMatListOfListOfPointScalar() {
int matSize = 10; int matSize = 10;
Mat 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)); CvVectorPoint polyline = new CvVectorPoint(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<CvVectorPoint> polylines = new ArrayList<CvVectorPoint>();
polylines.add(polyline); polylines.add(polyline);
Core.fillPoly(gray0, polylines, new Scalar(1)); Core.fillPoly(gray0, polylines, new Scalar(1));
...@@ -671,13 +675,13 @@ public class CoreTest extends OpenCVTestCase { ...@@ -671,13 +675,13 @@ public class CoreTest extends OpenCVTestCase {
} }
public void testFillPolyMatListOfListOfPointScalarIntIntPoint() { public void testFillPolyMatListOfListOfPointScalarIntIntPoint() {
List<Point> polyline1 = Arrays.asList(new Point(1, 4), new Point(1, 8), new Point(4, 1), new Point(7, 8), new Point(7, 4)); CvVectorPoint polyline1 = new CvVectorPoint(new Point(1, 4), new Point(1, 8), new Point(4, 1), new Point(7, 8), new Point(7, 4));
List<Point> polyline2 = Arrays.asList(new Point(0, 3), new Point(0, 7), new Point(3, 0), new Point(6, 7), new Point(6, 3)); CvVectorPoint polyline2 = new CvVectorPoint(new Point(0, 3), new Point(0, 7), new Point(3, 0), new Point(6, 7), new Point(6, 3));
List<List<Point>> polylines1 = new ArrayList<List<Point>>(); List<CvVectorPoint> polylines1 = new ArrayList<CvVectorPoint>();
polylines1.add(polyline1); polylines1.add(polyline1);
List<List<Point>> polylines2 = new ArrayList<List<Point>>(); List<CvVectorPoint> polylines2 = new ArrayList<CvVectorPoint>();
polylines2.add(polyline2); polylines2.add(polyline2);
Core.fillPoly(gray0, polylines1, new Scalar(1), Core.LINE_8, 0, new Point(0, 0)); Core.fillPoly(gray0, polylines1, new Scalar(1), Core.LINE_8, 0, new Point(0, 0));
...@@ -1190,18 +1194,18 @@ public class CoreTest extends OpenCVTestCase { ...@@ -1190,18 +1194,18 @@ public class CoreTest extends OpenCVTestCase {
} }
public void testMeanStdDevMatMatMat() { public void testMeanStdDevMatMatMat() {
List<Double> mean = new ArrayList<Double>(); CvVectorDouble mean = new CvVectorDouble();
List<Double> stddev = new ArrayList<Double>(); CvVectorDouble stddev = new CvVectorDouble();
Core.meanStdDev(rgbLena, mean, stddev); Core.meanStdDev(rgbLena, mean, stddev);
List<Double> expectedMean = Arrays.asList( new Double[] double expectedMean[] = new double[]
{105.3989906311035, 99.56269836425781, 179.7303047180176} ); {105.3989906311035, 99.56269836425781, 179.7303047180176};
List<Double> expectedDev = Arrays.asList( new Double[] double expectedDev[] = new double[]
{33.74205485167219, 52.8734582803278, 49.01569488056406} ); {33.74205485167219, 52.8734582803278, 49.01569488056406};
assertListEquals(expectedMean, mean, EPS); assertArrayEquals(expectedMean, mean.toArray(null), EPS);
assertListEquals(expectedDev, stddev, EPS); assertArrayEquals(expectedDev, stddev.toArray(null), EPS);
} }
public void testMeanStdDevMatMatMatMat() { public void testMeanStdDevMatMatMatMat() {
...@@ -1210,16 +1214,16 @@ public class CoreTest extends OpenCVTestCase { ...@@ -1210,16 +1214,16 @@ public class CoreTest extends OpenCVTestCase {
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));
List<Double> mean = new ArrayList<Double>(); CvVectorDouble mean = new CvVectorDouble();
List<Double> stddev = new ArrayList<Double>(); CvVectorDouble stddev = new CvVectorDouble();
Core.meanStdDev(grayRnd, mean, stddev, mask); Core.meanStdDev(grayRnd, mean, stddev, mask);
List<Double> expectedMean = Arrays.asList( new Double[] {33d} ); double expectedMean[] = new double[] {33d};
List<Double> expectedDev = Arrays.asList( new Double[] {0d} ); double expectedDev[] = new double[] {0d};
assertListEquals(expectedMean, mean, EPS); assertArrayEquals(expectedMean, mean.toArray(null), EPS);
assertListEquals(expectedDev, stddev, EPS); assertArrayEquals(expectedDev, stddev.toArray(null), EPS);
} }
public void testMerge() { public void testMerge() {
...@@ -1280,14 +1284,15 @@ public class CoreTest extends OpenCVTestCase { ...@@ -1280,14 +1284,15 @@ public class CoreTest extends OpenCVTestCase {
rgba0.setTo(new Scalar(10, 20, 30, 40)); rgba0.setTo(new Scalar(10, 20, 30, 40));
List<Mat> src = Arrays.asList(rgba0); List<Mat> src = Arrays.asList(rgba0);
List<Mat> dst = Arrays.asList(gray3, gray2, gray1, gray0, getMat(CvType.CV_8UC3, 0, 0, 0)); List<Mat> dst = Arrays.asList(gray3, gray2, gray1, gray0, getMat(CvType.CV_8UC3, 0, 0, 0));
List<Integer> fromTo = Arrays.asList( CvVectorInt fromTo = new CvVectorInt(1, new int[]
3, 0, { 3, 0,
3, 1, 3, 1,
2, 2, 2, 2,
0, 3, 0, 3,
2, 4, 2, 4,
1, 5, 1, 5,
0, 6); 0, 6 }
);
Core.mixChannels(src, dst, fromTo); Core.mixChannels(src, dst, fromTo);
...@@ -1740,8 +1745,8 @@ public class CoreTest extends OpenCVTestCase { ...@@ -1740,8 +1745,8 @@ public class CoreTest extends OpenCVTestCase {
public void testPolylinesMatListOfListOfPointBooleanScalar() { public void testPolylinesMatListOfListOfPointBooleanScalar() {
Mat img = gray0; Mat img = gray0;
List<List<Point>> polyline = new ArrayList<List<Point>>(); List<CvVectorPoint> polyline = new ArrayList<CvVectorPoint>();
polyline.add(Arrays.asList(new Point(1, 1), new Point(7, 1), new Point(7, 6), new Point(1, 6))); polyline.add(new CvVectorPoint(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));
...@@ -1754,8 +1759,8 @@ public class CoreTest extends OpenCVTestCase { ...@@ -1754,8 +1759,8 @@ public class CoreTest extends OpenCVTestCase {
public void testPolylinesMatListOfListOfPointBooleanScalarInt() { public void testPolylinesMatListOfListOfPointBooleanScalarInt() {
Mat img = gray0; Mat img = gray0;
List<List<Point>> polyline = new ArrayList<List<Point>>(); List<CvVectorPoint> polyline = new ArrayList<CvVectorPoint>();
polyline.add(Arrays.asList(new Point(1, 1), new Point(7, 1), new Point(7, 6), new Point(1, 6))); polyline.add(new CvVectorPoint(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);
...@@ -1764,10 +1769,10 @@ public class CoreTest extends OpenCVTestCase { ...@@ -1764,10 +1769,10 @@ 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<CvVectorPoint> polyline1 = new ArrayList<CvVectorPoint>();
polyline1.add(Arrays.asList(new Point(1, 1), new Point(7, 1), new Point(7, 6), new Point(1, 6))); polyline1.add(new CvVectorPoint(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<CvVectorPoint> polyline2 = new ArrayList<CvVectorPoint>();
polyline2.add(Arrays.asList(new Point(2, 2), new Point(14, 2), new Point(14, 12), new Point(2, 12))); polyline2.add(new CvVectorPoint(new Point(2, 2), new Point(14, 2), new Point(14, 12), new Point(2, 12)));
Core.polylines(img, polyline1, true, new Scalar(100), 2, Core.LINE_8, 0); Core.polylines(img, polyline1, true, new Scalar(100), 2, Core.LINE_8, 0);
......
...@@ -7,6 +7,10 @@ public class CvVectorByte extends CvVector { ...@@ -7,6 +7,10 @@ public class CvVectorByte extends CvVector {
super(_d, ch); super(_d, ch);
} }
public CvVectorByte() {
super(_d, 1);
}
public CvVectorByte(int ch, long addr) { public CvVectorByte(int ch, long addr) {
super(_d, ch, addr); super(_d, ch, addr);
} }
......
...@@ -17,9 +17,9 @@ public class CvVectorDMatch extends CvVectorFloat { ...@@ -17,9 +17,9 @@ public class CvVectorDMatch extends CvVectorFloat {
super(_ch, m); super(_ch, m);
} }
public CvVectorDMatch(DMatch[] a) { public CvVectorDMatch(DMatch...a) {
super(_ch); super(_ch);
if(a==null) if(a==null || a.length==0)
return; return;
int cnt = a.length; int cnt = a.length;
create(cnt); create(cnt);
......
...@@ -7,6 +7,10 @@ public class CvVectorDouble extends CvVector { ...@@ -7,6 +7,10 @@ public class CvVectorDouble extends CvVector {
super(_d, ch); super(_d, ch);
} }
public CvVectorDouble() {
super(_d, 1);
}
public CvVectorDouble(int ch, long addr) { public CvVectorDouble(int ch, long addr) {
super(_d, ch, addr); super(_d, ch, addr);
} }
......
...@@ -7,6 +7,10 @@ public class CvVectorFloat extends CvVector { ...@@ -7,6 +7,10 @@ public class CvVectorFloat extends CvVector {
super(_d, ch); super(_d, ch);
} }
public CvVectorFloat() {
super(_d, 1);
}
public CvVectorFloat(int ch, long addr) { public CvVectorFloat(int ch, long addr) {
super(_d, ch, addr); super(_d, ch, addr);
} }
......
...@@ -8,6 +8,10 @@ public class CvVectorInt extends CvVector { ...@@ -8,6 +8,10 @@ public class CvVectorInt extends CvVector {
super(_d, ch); super(_d, ch);
} }
public CvVectorInt() {
super(_d, 1);
}
public CvVectorInt(int ch, long addr) { public CvVectorInt(int ch, long addr) {
super(_d, ch, addr); super(_d, ch, addr);
} }
......
...@@ -17,9 +17,9 @@ public class CvVectorKeyPoint extends CvVectorFloat { ...@@ -17,9 +17,9 @@ public class CvVectorKeyPoint extends CvVectorFloat {
super(_ch, m); super(_ch, m);
} }
public CvVectorKeyPoint(KeyPoint[] a) { public CvVectorKeyPoint(KeyPoint...a) {
super(_ch); super(_ch);
if(a==null) if(a==null || a.length==0)
return; return;
int cnt = a.length; int cnt = a.length;
create(cnt); create(cnt);
......
...@@ -15,9 +15,9 @@ public class CvVectorPoint extends CvVectorInt { ...@@ -15,9 +15,9 @@ public class CvVectorPoint extends CvVectorInt {
super(_ch, m); super(_ch, m);
} }
public CvVectorPoint(Point[] a) { public CvVectorPoint(Point...a) {
super(_ch); super(_ch);
if(a==null) if(a==null || a.length==0)
return; return;
int cnt = a.length; int cnt = a.length;
create(cnt); create(cnt);
......
...@@ -15,9 +15,9 @@ public class CvVectorPoint2f extends CvVectorFloat { ...@@ -15,9 +15,9 @@ public class CvVectorPoint2f extends CvVectorFloat {
super(_ch, m); super(_ch, m);
} }
public CvVectorPoint2f(Point[] a) { public CvVectorPoint2f(Point...a) {
super(_ch); super(_ch);
if(a==null) if(a==null || a.length==0)
return; return;
int cnt = a.length; int cnt = a.length;
create(cnt); create(cnt);
......
...@@ -15,9 +15,9 @@ public class CvVectorPoint3 extends CvVectorInt { ...@@ -15,9 +15,9 @@ public class CvVectorPoint3 extends CvVectorInt {
super(_ch, m); super(_ch, m);
} }
public CvVectorPoint3(Point3[] a) { public CvVectorPoint3(Point3...a) {
super(_ch); super(_ch);
if(a==null) if(a==null || a.length==0)
return; return;
int cnt = a.length; int cnt = a.length;
create(cnt); create(cnt);
......
...@@ -15,9 +15,9 @@ public class CvVectorPoint3f extends CvVectorFloat { ...@@ -15,9 +15,9 @@ public class CvVectorPoint3f extends CvVectorFloat {
super(_ch, m); super(_ch, m);
} }
public CvVectorPoint3f(Point3[] a) { public CvVectorPoint3f(Point3...a) {
super(_ch); super(_ch);
if(a==null) if(a==null || a.length==0)
return; return;
int cnt = a.length; int cnt = a.length;
create(cnt); create(cnt);
......
...@@ -16,9 +16,9 @@ public class CvVectorRect extends CvVectorInt { ...@@ -16,9 +16,9 @@ public class CvVectorRect extends CvVectorInt {
super(_ch, m); super(_ch, m);
} }
public CvVectorRect(Rect[] a) { public CvVectorRect(Rect...a) {
super(_ch); super(_ch);
if(a==null) if(a==null || a.length==0)
return; return;
int cnt = a.length; int cnt = a.length;
create(cnt); create(cnt);
......
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