From 6b888ada8a5c3ced86c569c9c0050fd38557b593 Mon Sep 17 00:00:00 2001 From: Andrey Pavlenko Date: Thu, 28 Jul 2011 15:48:08 +0000 Subject: [PATCH] Java API tests are added: fillConvexPoly, mixChannels, drawContours --- .../src/org/opencv/test/core/coreTest.java | 83 +++++++++++++++++-- .../org/opencv/test/imgproc/imgprocTest.java | 10 ++- 2 files changed, 87 insertions(+), 6 deletions(-) diff --git a/modules/java/android_test/src/org/opencv/test/core/coreTest.java b/modules/java/android_test/src/org/opencv/test/core/coreTest.java index e8a9c160e..e5d4d43fc 100644 --- a/modules/java/android_test/src/org/opencv/test/core/coreTest.java +++ b/modules/java/android_test/src/org/opencv/test/core/coreTest.java @@ -1,14 +1,16 @@ package org.opencv.test.core; import java.util.ArrayList; +import java.util.List; +import org.opencv.Converters; +import org.opencv.core.Core; import org.opencv.core.CvException; import org.opencv.core.CvType; import org.opencv.core.Mat; import org.opencv.core.Point; import org.opencv.core.Rect; import org.opencv.core.Scalar; -import org.opencv.core.Core; import org.opencv.test.OpenCVTestCase; public class coreTest extends OpenCVTestCase { @@ -478,15 +480,57 @@ public class coreTest extends OpenCVTestCase { } public void testFillConvexPolyMatMatScalar() { - fail("Not yet implemented"); + List lp = new ArrayList(4); + lp.add( new Point(1, 1) ); + lp.add( new Point(5, 0) ); + lp.add( new Point(6, 8) ); + lp.add( new Point(0, 9) ); + Mat points = Converters.vector_Point_to_Mat(lp); + assertTrue(0 == Core.countNonZero(gray0)); + + Core.fillConvexPoly(gray0, points, new Scalar(150)); + assertTrue(0 < Core.countNonZero(gray0)); + + Core.fillConvexPoly(gray0, points, new Scalar(0)); + assertTrue(0 == Core.countNonZero(gray0)); } public void testFillConvexPolyMatMatScalarInt() { - fail("Not yet implemented"); + List lp = new ArrayList(4); + lp.add( new Point(1, 1) ); + lp.add( new Point(5, 0) ); + lp.add( new Point(6, 8) ); + lp.add( new Point(0, 9) ); + Mat points = Converters.vector_Point_to_Mat(lp); + assertTrue(0 == Core.countNonZero(gray0)); + + Core.fillConvexPoly(gray0, points, new Scalar(150), 4); + assertTrue(0 < Core.countNonZero(gray0)); + + Core.fillConvexPoly(gray0, points, new Scalar(0), 4); + assertTrue(0 == Core.countNonZero(gray0)); } public void testFillConvexPolyMatMatScalarIntInt() { - fail("Not yet implemented"); + List lp = new ArrayList(4); + lp.add( new Point(1, 1) ); + lp.add( new Point(5, 1) ); + lp.add( new Point(5, 8) ); + lp.add( new Point(1, 8) ); + Mat points = Converters.vector_Point_to_Mat(lp); + List lp2 = new ArrayList(4); + lp2.add( new Point(2, 2) ); + lp2.add( new Point(10, 2) ); + lp2.add( new Point(10, 17) ); //TODO: don't know why '16' fails the test + lp2.add( new Point(2, 17) ); //TODO: don't know why '16' fails the test + Mat points2 = Converters.vector_Point_to_Mat(lp2); + assertTrue(0 == Core.countNonZero(gray0)); + + Core.fillConvexPoly(gray0, points, new Scalar(150), 4, 0); + assertTrue(0 < Core.countNonZero(gray0)); + + Core.fillConvexPoly(gray0, points2, new Scalar(0), 4, 1); + assertTrue(0 == Core.countNonZero(gray0)); } public void testFillPolyMatListOfMatScalar() { @@ -921,7 +965,36 @@ public class coreTest extends OpenCVTestCase { } public void testMixChannels() { - fail("Not yet implemented"); + rgba0.setTo(new Scalar(10, 20, 30, 40)); + + List result = new ArrayList(); + Core.split(rgba0, result); + assertEquals(10, (int) result.get(0).get(0, 0)[0]); + assertEquals(20, (int) result.get(1).get(0, 0)[0]); + assertEquals(30, (int) result.get(2).get(0, 0)[0]); + assertEquals(40, (int) result.get(3).get(0, 0)[0]); + + List src = new ArrayList(1); + src.add(rgba0); + + List dst = new ArrayList(4); + dst.add(gray3); + dst.add(gray2); + dst.add(gray1); + dst.add(gray0); + + List fromTo = new ArrayList(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); + + assertMatEqual(result.get(0), gray0); + assertMatEqual(result.get(1), gray1); + assertMatEqual(result.get(2), gray2); + assertMatEqual(result.get(3), gray3); } public void testMulSpectrumsMatMatMatInt() { 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 5468f0e6d..4182d1e4c 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 @@ -588,7 +588,15 @@ public class imgprocTest extends OpenCVTestCase { } public void testDrawContoursMatListOfMatIntScalar() { - fail("Not yet implemented"); + List contours = new ArrayList(5); + Mat hierarchy = dst; + Core.rectangle(gray0, new Point(1, 2), new Point(7, 8), new Scalar(100)); + Imgproc.findContours(gray0, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE); + assertTrue(1 == contours.size()); + + assertFalse(0 == Core.countNonZero(gray0)); + Imgproc.drawContours(gray0, contours, -1, new Scalar(0)); + assertTrue(0 == Core.countNonZero(gray0)); } public void testDrawContoursMatListOfMatIntScalarInt() {