From 2154fb5a15314db2a84efc532ac5ceb83a1d9d1a Mon Sep 17 00:00:00 2001 From: Ivan Korolev Date: Sat, 7 Apr 2012 06:00:18 +0000 Subject: [PATCH] Java API: Fixed some bugs in the ImgprocTest.java --- .../org/opencv/test/imgproc/ImgprocTest.java | 66 ++++++++----------- 1 file changed, 28 insertions(+), 38 deletions(-) diff --git a/modules/java/android_test/src/org/opencv/test/imgproc/ImgprocTest.java b/modules/java/android_test/src/org/opencv/test/imgproc/ImgprocTest.java index f53756e0dd..72a006183c 100644 --- a/modules/java/android_test/src/org/opencv/test/imgproc/ImgprocTest.java +++ b/modules/java/android_test/src/org/opencv/test/imgproc/ImgprocTest.java @@ -244,7 +244,7 @@ public class ImgprocTest extends OpenCVTestCase { List images = Arrays.asList(grayChess); MatOfInt channels = new MatOfInt(1, 0); MatOfInt histSize = new MatOfInt(1, 10); - MatOfFloat ranges = new MatOfFloat(1, 0f, 256f); + MatOfFloat ranges = new MatOfFloat(1, 0f, 256f); Mat hist = new Mat(); Imgproc.calcHist(images, channels, new Mat(), hist, histSize, ranges); @@ -261,7 +261,7 @@ public class ImgprocTest extends OpenCVTestCase { List images = Arrays.asList(gray128); MatOfInt channels = new MatOfInt(1, 0); MatOfInt histSize = new MatOfInt(1, 10); - MatOfFloat ranges = new MatOfFloat(1, 0f, 256f); + MatOfFloat ranges = new MatOfFloat(1, 0f, 256f); Mat hist = new Mat(); Imgproc.calcHist(images, channels, new Mat(), hist, histSize, ranges); @@ -278,7 +278,7 @@ public class ImgprocTest extends OpenCVTestCase { List images = Arrays.asList(gray255, gray128); MatOfInt channels = new MatOfInt(1, 0, 1); MatOfInt histSize = new MatOfInt(1, 10, 10); - MatOfFloat ranges = new MatOfFloat(1, 0f, 256f, 0f, 256f); + MatOfFloat ranges = new MatOfFloat(1, 0f, 256f, 0f, 256f); Mat hist = new Mat(); Imgproc.calcHist(images, channels, new Mat(), hist, histSize, ranges); @@ -293,9 +293,9 @@ public class ImgprocTest extends OpenCVTestCase { public void testCalcHistListOfMatListOfIntegerMatMatListOfIntegerListOfFloatBoolean() { List images = Arrays.asList(gray255, gray128); - List channels = Arrays.asList(0, 1); - List histSize = Arrays.asList(10, 10); - List ranges = Arrays.asList(0f, 256f, 0f, 256f); + MatOfInt channels = new MatOfInt(1, 0, 1); + MatOfInt histSize = new MatOfInt(1, 10, 10); + MatOfFloat ranges = new MatOfFloat(1, 0f, 256f, 0f, 256f); Mat hist = new Mat(); Imgproc.calcHist(images, channels, new Mat(), hist, histSize, ranges, true); @@ -541,15 +541,14 @@ public class ImgprocTest extends OpenCVTestCase { Rect r = new Rect(new Point(0, 0), truthPosition); Core.rectangle(img, r.tl(), r.br(), new Scalar(0), Core.FILLED); - List corners = new ArrayList(); - corners.add(new Point(truthPosition.x + 1, truthPosition.y + 1)); + MatOfPoint2f corners = new MatOfPoint2f(new Point(truthPosition.x + 1, truthPosition.y + 1)); Size winSize = new Size(2, 2); Size zeroZone = new Size(-1, -1); TermCriteria criteria = new TermCriteria(TermCriteria.EPS, 0, 0.01); Imgproc.cornerSubPix(img, corners, winSize, zeroZone, criteria); - - assertPointEquals(truthPosition, corners.get(0), weakEPS); + + assertPointEquals(truthPosition, corners.toList().get(0), weakEPS); } public void testCvtColorMatMatInt() { @@ -601,7 +600,7 @@ public class ImgprocTest extends OpenCVTestCase { public void testDrawContoursMatListOfMatIntScalar() { Core.rectangle(gray0, new Point(1, 2), new Point(7, 8), new Scalar(100)); - List contours = new ArrayList(); + List contours = new ArrayList(); Imgproc.findContours(gray0, contours, new Mat(), Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE); Imgproc.drawContours(gray0, contours, -1, new Scalar(0)); @@ -611,7 +610,7 @@ public class ImgprocTest extends OpenCVTestCase { public void testDrawContoursMatListOfMatIntScalarInt() { Core.rectangle(gray0, new Point(1, 2), new Point(7, 8), new Scalar(100)); - List contours = new ArrayList(); + List contours = new ArrayList(); Imgproc.findContours(gray0, contours, new Mat(), Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE); Imgproc.drawContours(gray0, contours, -1, new Scalar(0), Core.FILLED); @@ -706,7 +705,7 @@ public class ImgprocTest extends OpenCVTestCase { public void testFindContoursMatListOfMatMatIntInt() { Mat img = new Mat(50, 50, CvType.CV_8UC1, new Scalar(0)); - List contours = new ArrayList(5); + List contours = new ArrayList(5); Mat hierarchy = new Mat(); Imgproc.findContours(img, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE); @@ -728,8 +727,8 @@ public class ImgprocTest extends OpenCVTestCase { public void testFindContoursMatListOfMatMatIntIntPoint() { Mat img = new Mat(50, 50, CvType.CV_8UC1, new Scalar(0)); Mat img2 = img.submat(5, 50, 3, 50); - List contours = new ArrayList(); - List contours2 = new ArrayList(); + List contours = new ArrayList(); + List contours2 = new ArrayList(); Mat hierarchy = new Mat(); Core.rectangle(img, new Point(10, 20), new Point(20, 30), new Scalar(100), 3, Core.LINE_AA, 0); @@ -749,7 +748,7 @@ public class ImgprocTest extends OpenCVTestCase { } public void testFitEllipse() { - List points = Arrays.asList(new Point(0, 0), new Point(-1, 1), new Point(1, 1), new Point(1, -1), new Point(-1, -1)); + MatOfPoint2f points = new MatOfPoint2f(new Point(0, 0), new Point(-1, 1), new Point(1, 1), new Point(1, -1), new Point(-1, -1)); RotatedRect rrect = new RotatedRect(); rrect = Imgproc.fitEllipse(points); @@ -834,8 +833,8 @@ public class ImgprocTest extends OpenCVTestCase { } public void testGetAffineTransform() { - List src = Arrays.asList(new Point(2, 3), new Point(3, 1), new Point(1, 4)); - List dst = Arrays.asList(new Point(3, 3), new Point(7, 4), new Point(5, 6)); + MatOfPoint2f src = new MatOfPoint2f(new Point(2, 3), new Point(3, 1), new Point(1, 4)); + MatOfPoint2f dst = new MatOfPoint2f(new Point(3, 3), new Point(7, 4), new Point(5, 6)); Mat transform = Imgproc.getAffineTransform(src, dst); @@ -978,7 +977,7 @@ public class ImgprocTest extends OpenCVTestCase { public void testGoodFeaturesToTrackMatListOfPointIntDoubleDouble() { Mat src = gray0; Core.rectangle(src, new Point(2, 2), new Point(8, 8), new Scalar(100), -1); - List lp = new ArrayList(); + MatOfPoint lp = new MatOfPoint(); Imgproc.goodFeaturesToTrack(src, lp, 100, 0.01, 3); @@ -988,7 +987,7 @@ public class ImgprocTest extends OpenCVTestCase { public void testGoodFeaturesToTrackMatListOfPointIntDoubleDoubleMatIntBooleanDouble() { Mat src = gray0; Core.rectangle(src, new Point(2, 2), new Point(8, 8), new Scalar(100), -1); - List lp = new ArrayList(); + MatOfPoint lp = new MatOfPoint(); Imgproc.goodFeaturesToTrack(src, lp, 100, 0.01, 3, gray1, 4, true, 0); @@ -1278,11 +1277,11 @@ public class ImgprocTest extends OpenCVTestCase { } public void testIsContourConvex() { - List contour1 = Arrays.asList(new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(5, 4)); + MatOfPoint2f contour1 = new MatOfPoint2f(new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(5, 4)); assertFalse(Imgproc.isContourConvex(contour1)); - List contour2 = Arrays.asList(new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(5, 6)); + MatOfPoint2f contour2 = new MatOfPoint2f(new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(5, 6)); assertTrue(Imgproc.isContourConvex(contour2)); } @@ -1354,7 +1353,7 @@ public class ImgprocTest extends OpenCVTestCase { } public void testMinAreaRect() { - List points = Arrays.asList(new Point(1, 1), new Point(5, 1), new Point(4, 3), new Point(6, 2)); + MatOfPoint2f points = new MatOfPoint2f(new Point(1, 1), new Point(5, 1), new Point(4, 3), new Point(6, 2)); RotatedRect rrect = Imgproc.minAreaRect(points); @@ -1364,12 +1363,7 @@ public class ImgprocTest extends OpenCVTestCase { } public void testMinEnclosingCircle() { - List points = new ArrayList(); - points.add(new Point(0, 0)); - points.add(new Point(-1, 0)); - points.add(new Point(0, -1)); - points.add(new Point(1, 0)); - points.add(new Point(0, 1)); + MatOfPoint2f points = new MatOfPoint2f(new Point(0, 0), new Point(-1, 0), new Point(0, -1), new Point(1, 0), new Point(0, 1)); Point actualCenter = new Point(); float[] radius = new float[1]; @@ -1429,8 +1423,7 @@ public class ImgprocTest extends OpenCVTestCase { } public void testPointPolygonTest() { - List contour = Arrays.asList(new Point(0, 0), new Point(1, 3), new Point(3, 4), new Point(4, 3), new Point(2, 1)); - + MatOfPoint2f contour = new MatOfPoint2f(new Point(0, 0), new Point(1, 3), new Point(3, 4), new Point(4, 3), new Point(2, 1)); double sign1 = Imgproc.pointPolygonTest(contour, new Point(2, 2), false); assertEquals(1.0, sign1); @@ -1762,18 +1755,15 @@ public class ImgprocTest extends OpenCVTestCase { //undistortPoints(List src, List dst, Mat cameraMatrix, Mat distCoeffs) public void testUndistortPointsListOfPointListOfPointMatMat() { - List src = new ArrayList(3); - src.add( new Point(1, 2) ); - src.add( new Point(3, 4) ); - src.add( new Point(-1, -1) ); - List dst = new ArrayList(); + MatOfPoint2f src = new MatOfPoint2f(new Point(1, 2), new Point(3, 4), new Point(-1, -1)); + MatOfPoint2f dst = new MatOfPoint2f(); Mat cameraMatrix = Mat.eye(3, 3, CvType.CV_64FC1); Mat distCoeffs = new Mat(8, 1, CvType.CV_64FC1, new Scalar(0)); Imgproc.undistortPoints(src, dst, cameraMatrix, distCoeffs); assertEquals(src.size(), dst.size()); - for(int i=0; i