diff --git a/modules/java/android_test/src/org/opencv/test/features2d/MSERTest.java b/modules/java/android_test/src/org/opencv/test/features2d/MSERTest.java deleted file mode 100644 index c85ac155f4..0000000000 --- a/modules/java/android_test/src/org/opencv/test/features2d/MSERTest.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.opencv.test.features2d; - -import org.opencv.features2d.MSER; -import org.opencv.test.OpenCVTestCase; - -public class MSERTest extends OpenCVTestCase { - - private MSER mser; - - @Override - protected void setUp() throws Exception { - super.setUp(); - - mser = null; - } - - public void test_1() { - super.test_1("FEATURES2D.MSER"); - } - - public void testMSER() { - mser = new MSER(); - assertTrue(null != mser); - } - - public void testMSERIntIntIntDoubleDoubleIntDoubleDoubleInt() { - mser = new MSER(5, 60, 14400, .25f, .2f, 200, 1.01, .003, 5); - assertTrue(null != mser); - } - -} diff --git a/modules/java/android_test/src/org/opencv/test/features2d/STARFeatureDetectorTest.java b/modules/java/android_test/src/org/opencv/test/features2d/STARFeatureDetectorTest.java new file mode 100644 index 0000000000..32ce5483dd --- /dev/null +++ b/modules/java/android_test/src/org/opencv/test/features2d/STARFeatureDetectorTest.java @@ -0,0 +1,130 @@ +package org.opencv.test.features2d; + +import org.opencv.core.Core; +import org.opencv.core.CvType; +import org.opencv.core.Mat; +import org.opencv.core.Point; +import org.opencv.core.Scalar; +import org.opencv.features2d.FeatureDetector; +import org.opencv.features2d.KeyPoint; +import org.opencv.test.OpenCVTestCase; +import org.opencv.test.OpenCVTestRunner; + +import java.util.ArrayList; +import java.util.List; + +public class STARFeatureDetectorTest extends OpenCVTestCase { + + FeatureDetector detector; + KeyPoint[] truth; + int matSize; + + protected void setUp() throws Exception { + detector = FeatureDetector.create(FeatureDetector.STAR); + + matSize = 200; + + truth = new KeyPoint[] { + new KeyPoint(95, 80, 22, -1, 31.595734f, 0, -1), + new KeyPoint(105, 80, 22, -1, 31.595734f, 0, -1), + new KeyPoint(80, 95, 22, -1, 31.595734f, 0, -1), + new KeyPoint(120, 95, 22, -1, 31.595734f, 0, -1), + new KeyPoint(100, 100, 8, -1, -219.90825f, 0, -1), + new KeyPoint(80, 105, 22, -1, 31.595734f, 0, -1), + new KeyPoint(120, 105, 22, -1, 31.595734f, 0, -1), + new KeyPoint(95, 120, 22, -1, 31.595734f, 0, -1), + new KeyPoint(105, 120, 22, -1, 31.595734f, 0, -1) }; + + super.setUp(); + } + + private Mat getTestImg() { + Scalar color = new Scalar(0); + int center = matSize / 2; + int radius = 6; + int offset = 40; + + Mat img = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(255)); + Core.circle(img, new Point(center - offset, center), radius, color, -1); + Core.circle(img, new Point(center + offset, center), radius, color, -1); + Core.circle(img, new Point(center, center - offset), radius, color, -1); + Core.circle(img, new Point(center, center + offset), radius, color, -1); + Core.circle(img, new Point(center, center), radius, color, -1); + return img; + } + + private Mat getMaskImg() { + Mat mask = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(255)); + Mat right = mask.submat(0, matSize, matSize / 2, matSize); + right.setTo(new Scalar(0)); + return mask; + } + + public void testCreate() { + assertNotNull(detector); + } + + public void testDetectMatListOfKeyPointMat() { + Mat img = getTestImg(); + Mat mask = getMaskImg(); + List keypoints = new ArrayList(); + + detector.detect(img, keypoints, mask); + + KeyPoint[] _truth = new KeyPoint[] { truth[0], truth[2], truth[5], truth[7] }; + + assertEquals(_truth.length, keypoints.size()); + for (int i = 0; i < _truth.length; i++) + assertKeyPointEqual(_truth[i], keypoints.get(i), EPS); + } + + public void testDetectMatListOfKeyPoint() { + Mat img = getTestImg(); + List keypoints = new ArrayList(); + + detector.detect(img, keypoints); + + assertEquals(truth.length, keypoints.size()); + for (int i = 0; i < truth.length; i++) + assertKeyPointEqual(truth[i], keypoints.get(i), EPS); + } + + public void testEmpty() { + assertFalse(detector.empty()); + } + + public void testRead() { + Mat img = getTestImg(); + + List keypoints1 = new ArrayList(); + detector.detect(img, keypoints1); + + String filename = OpenCVTestRunner.getTempFileName("yml"); + writeFile(filename, "%YAML:1.0\nmaxSize: 45\nresponseThreshold: 150\nlineThresholdProjected: 10\nlineThresholdBinarized: 8\nsuppressNonmaxSize: 5\n"); + detector.read(filename); + + List keypoints2 = new ArrayList(); + detector.detect(img, keypoints2); + + assertTrue(keypoints2.size() <= keypoints1.size()); + } + + public void testWrite() { + String filename = OpenCVTestRunner.getTempFileName("xml"); + + detector.write(filename); + + String truth = "\n\n45\n30\n10\n8\n5\n\n"; + assertEquals(truth, readFile(filename)); + } + + public void testWriteYml() { + String filename = OpenCVTestRunner.getTempFileName("yml"); + + detector.write(filename); + + String truth = "%YAML:1.0\nmaxSize: 45\nresponseThreshold: 30\nlineThresholdProjected: 10\nlineThresholdBinarized: 8\nsuppressNonmaxSize: 5\n"; + assertEquals(truth, readFile(filename)); + } + +} diff --git a/modules/java/android_test/src/org/opencv/test/features2d/SURFFeatureDetectorTest.java b/modules/java/android_test/src/org/opencv/test/features2d/SURFFeatureDetectorTest.java new file mode 100644 index 0000000000..ff243b914d --- /dev/null +++ b/modules/java/android_test/src/org/opencv/test/features2d/SURFFeatureDetectorTest.java @@ -0,0 +1,142 @@ +package org.opencv.test.features2d; + +import org.opencv.core.Core; +import org.opencv.core.CvType; +import org.opencv.core.Mat; +import org.opencv.core.Point; +import org.opencv.core.Scalar; +import org.opencv.features2d.FeatureDetector; +import org.opencv.features2d.KeyPoint; +import org.opencv.test.OpenCVTestCase; +import org.opencv.test.OpenCVTestRunner; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +public class SURFFeatureDetectorTest extends OpenCVTestCase { + + FeatureDetector detector; + KeyPoint[] truth; + int matSize; + + @Override + protected void setUp() throws Exception { + detector = FeatureDetector.create(FeatureDetector.SURF); + + matSize = 100; + + truth = new KeyPoint[] { new KeyPoint(55.775577545166016f, 44.224422454833984f, 16, 9.754629f, 8617.863f, 1, -1), + new KeyPoint(44.224422454833984f, 44.224422454833984f, 16, 99.75463f, 8617.863f, 1, -1), + new KeyPoint(44.224422454833984f, 55.775577545166016f, 16, 189.7546f, 8617.863f, 1, -1), + new KeyPoint(55.775577545166016f, 55.775577545166016f, 16, 279.75464f, 8617.863f, 1, -1) }; + + super.setUp(); + } + + private Mat getTestImg() { + Mat cross = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(255)); + Core.line(cross, new Point(20, matSize / 2), new Point(matSize - 21, matSize / 2), new Scalar(100), 2); + Core.line(cross, new Point(matSize / 2, 20), new Point(matSize / 2, matSize - 21), new Scalar(100), 2); + + return cross; + } + + private void order(List points) { + Collections.sort(points, new Comparator() { + public int compare(KeyPoint p1, KeyPoint p2) { + if (p1.angle < p2.angle) + return -1; + if (p1.angle > p2.angle) + return 1; + return 0; + } + }); + } + + private Mat getMaskImg() { + Mat mask = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(255)); + Mat right = mask.submat(0, matSize, matSize / 2, matSize); + right.setTo(new Scalar(0)); + return mask; + } + + public void testCreate() { + assertNotNull(detector); + } + + public void testDetectMatListOfKeyPointMat() { + String filename = OpenCVTestRunner.getTempFileName("yml"); + writeFile(filename, "%YAML:1.0\nhessianThreshold: 8000.\noctaves: 3\noctaveLayers: 4\nupright: 0\n"); + detector.read(filename); + + Mat img = getTestImg(); + Mat mask = getMaskImg(); + List keypoints = new ArrayList(); + + detector.detect(img, keypoints, mask); + + KeyPoint[] _truth = new KeyPoint[] { truth[1], truth[2] }; + + assertEquals(_truth.length, keypoints.size()); + order(keypoints); + for (int i = 0; i < _truth.length; i++) + assertKeyPointEqual(_truth[i], keypoints.get(i), EPS); + } + + public void testDetectMatListOfKeyPoint() { + String filename = OpenCVTestRunner.getTempFileName("yml"); + writeFile(filename, "%YAML:1.0\nhessianThreshold: 8000.\noctaves: 3\noctaveLayers: 4\nupright: 0\n"); + detector.read(filename); + + List keypoints = new ArrayList(); + Mat cross = getTestImg(); + + detector.detect(cross, keypoints); + + assertEquals(truth.length, keypoints.size()); + order(keypoints); + for (int i = 0; i < truth.length; i++) + assertKeyPointEqual(truth[i], keypoints.get(i), EPS); + } + + public void testEmpty() { + assertFalse(detector.empty()); + } + + public void testRead() { + Mat cross = getTestImg(); + + List keypoints1 = new ArrayList(); + detector.detect(cross, keypoints1); + + String filename = OpenCVTestRunner.getTempFileName("yml"); + writeFile(filename, "%YAML:1.0\nhessianThreshold: 8000.\noctaves: 3\noctaveLayers: 4\nupright: 0\n"); + detector.read(filename); + + List keypoints2 = new ArrayList(); + detector.detect(cross, keypoints2); + + assertTrue(keypoints2.size() <= keypoints1.size()); + } + + public void testWrite() { + String filename = OpenCVTestRunner.getTempFileName("xml"); + + detector.write(filename); + + String truth = "\n\n400.\n3\n4\n0\n\n"; + assertEquals(truth, readFile(filename)); + } + + public void testWriteYml() { + String filename = OpenCVTestRunner.getTempFileName("yml"); + + detector.write(filename); + + String truth = "%YAML:1.0\nhessianThreshold: 400.\noctaves: 3\noctaveLayers: 4\nupright: 0\n"; + assertEquals(truth, readFile(filename)); + } + +} diff --git a/modules/java/android_test/src/org/opencv/test/features2d/StarDetectorTest.java b/modules/java/android_test/src/org/opencv/test/features2d/StarDetectorTest.java deleted file mode 100644 index d371030d6d..0000000000 --- a/modules/java/android_test/src/org/opencv/test/features2d/StarDetectorTest.java +++ /dev/null @@ -1,58 +0,0 @@ -package org.opencv.test.features2d; - -import java.util.LinkedList; -import java.util.List; - -import org.opencv.core.Core; -import org.opencv.core.CvType; -import org.opencv.core.Mat; -import org.opencv.core.Point; -import org.opencv.core.Scalar; -import org.opencv.features2d.KeyPoint; -import org.opencv.features2d.StarDetector; -import org.opencv.test.OpenCVTestCase; - -public class StarDetectorTest extends OpenCVTestCase { - - public void test_1() { - super.test_1("FEATURES2D.StarDetector"); - } - - private Mat getStarImg() { - Scalar color = new Scalar(0); - int center = 100; - int radius = 5; - int offset = 40; - - Mat img = new Mat(200, 200, CvType.CV_8U, new Scalar(255)); - Core.circle(img, new Point(center - offset, center), radius, color, -1); - Core.circle(img, new Point(center + offset, center), radius, color, -1); - Core.circle(img, new Point(center, center - offset), radius, color, -1); - Core.circle(img, new Point(center, center + offset), radius, color, -1); - Core.circle(img, new Point(center, center), radius, color, -1); - return img; - } - - public void testDetect() { - Mat img = getStarImg(); - List keypoints = new LinkedList(); - StarDetector star = new StarDetector(); - - star.detect(img, keypoints); - - KeyPoint truth = new KeyPoint(100, 100, 8, -1, -223.40334f, 0, -1); - assertEquals(1, keypoints.size()); - assertKeyPointEqual(truth, keypoints.get(0), EPS); - } - - public void testStarDetector() { - StarDetector star = new StarDetector(); - assertNotNull(star); - } - - public void testStarDetectorIntIntIntIntInt() { - StarDetector star = new StarDetector(45, 30, 10, 8, 5); - assertNotNull(star); - } - -} diff --git a/modules/java/gen_java.py b/modules/java/gen_java.py index 722f1ae353..7bbb041528 100644 --- a/modules/java/gen_java.py +++ b/modules/java/gen_java.py @@ -14,6 +14,7 @@ class_ignore_list = ( #features2d "KeyPoint", "MSER", + "StarDetector", ) const_ignore_list = (