From 28732d4300607e59824f6ed517a047484b4ebc16 Mon Sep 17 00:00:00 2001 From: Andrey Kamaev Date: Thu, 4 Aug 2011 06:21:17 +0000 Subject: [PATCH] Java API: added tests for SiftDescriptorExtractor and OrbDescriptorExtractor --- .../features2d/BRIEFDescriptorExtractorTest.java | 3 +- .../features2d/ORBDescriptorExtractorTest.java | 109 +++++++++++++++++++++ .../features2d/SIFTDescriptorExtractorTest.java | 106 ++++++++++++++++++++ 3 files changed, 216 insertions(+), 2 deletions(-) create mode 100644 modules/java/android_test/src/org/opencv/test/features2d/ORBDescriptorExtractorTest.java create mode 100644 modules/java/android_test/src/org/opencv/test/features2d/SIFTDescriptorExtractorTest.java diff --git a/modules/java/android_test/src/org/opencv/test/features2d/BRIEFDescriptorExtractorTest.java b/modules/java/android_test/src/org/opencv/test/features2d/BRIEFDescriptorExtractorTest.java index 0c7514d..1244a06 100644 --- a/modules/java/android_test/src/org/opencv/test/features2d/BRIEFDescriptorExtractorTest.java +++ b/modules/java/android_test/src/org/opencv/test/features2d/BRIEFDescriptorExtractorTest.java @@ -41,7 +41,6 @@ public class BRIEFDescriptorExtractorTest extends OpenCVTestCase { Mat descriptors = new Mat(); extractor.compute(img, keypoints, descriptors); - OpenCVTestRunner.Log(descriptors); Mat truth = new Mat(1, 32, CvType.CV_8UC1) { { @@ -50,7 +49,7 @@ public class BRIEFDescriptorExtractorTest extends OpenCVTestCase { } }; - assertMatEqual(truth, descriptors, EPS); + assertMatEqual(truth, descriptors); } public void testCreate() { diff --git a/modules/java/android_test/src/org/opencv/test/features2d/ORBDescriptorExtractorTest.java b/modules/java/android_test/src/org/opencv/test/features2d/ORBDescriptorExtractorTest.java new file mode 100644 index 0000000..53e367d --- /dev/null +++ b/modules/java/android_test/src/org/opencv/test/features2d/ORBDescriptorExtractorTest.java @@ -0,0 +1,109 @@ +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.DescriptorExtractor; +import org.opencv.features2d.KeyPoint; +import org.opencv.test.OpenCVTestCase; +import org.opencv.test.OpenCVTestRunner; + +import java.util.Arrays; +import java.util.List; + +public class ORBDescriptorExtractorTest extends OpenCVTestCase { + + DescriptorExtractor extractor; + int matSize; + + 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; + } + + @Override + protected void setUp() throws Exception { + extractor = DescriptorExtractor.create(DescriptorExtractor.ORB); + matSize = 100; + + super.setUp(); + } + + public void testCompute() { + KeyPoint point = new KeyPoint(55.775577545166016f, 44.224422454833984f, 16, 9.754629f, 8617.863f, 1, -1); + List keypoints = Arrays.asList(point); + Mat img = getTestImg(); + Mat descriptors = new Mat(); + + extractor.compute(img, keypoints, descriptors); + + Mat truth = new Mat(1, 32, CvType.CV_8UC1) { + { + put(0, 0, 20, 51, 88, 22, 14, 181, 78, 111, 36, 144, 62, 0, 188, 196, 4, 8, 133, 80, 96, 18, 64, 29, 0, + 254, 230, 247, 12, 2, 78, 129, 70, 145); + } + }; + assertMatEqual(truth, descriptors); + } + + public void testCreate() { + assertNotNull(extractor); + } + + public void testDescriptorSize() { + assertEquals(32, extractor.descriptorSize()); + } + + public void testDescriptorType() { + assertEquals(CvType.CV_8U, extractor.descriptorType()); + } + + public void testEmpty() { + assertFalse(extractor.empty()); + } + + public void testRead() { + KeyPoint point = new KeyPoint(55.775577545166016f, 44.224422454833984f, 16, 9.754629f, 8617.863f, 1, -1); + List keypoints = Arrays.asList(point); + Mat img = getTestImg(); + Mat descriptors = new Mat(); + + String filename = OpenCVTestRunner.getTempFileName("yml"); + writeFile(filename, "%YAML:1.0\nscaleFactor: 1.1\nnLevels: 3\nfirstLevel: 0\nedgeThreshold: 31\npatchSize: 31\n"); + extractor.read(filename); + + extractor.compute(img, keypoints, descriptors); + + Mat truth = new Mat(1, 32, CvType.CV_8UC1) { + { + put(0, 0, 20, 55, 88, 20, 14, 49, 70, 111, 148, 144, 30, 16, 252, 133, 0, 8, 5, 85, 32, 0, 74, 25, 0, + 252, 119, 191, 4, 2, 66, 1, 66, 145); + } + }; + assertMatEqual(truth, descriptors); + } + + public void testWrite() { + String filename = OpenCVTestRunner.getTempFileName("xml"); + + extractor.write(filename); + + String truth = "\n\n1.2000000476837158e+00\n3\n0\n31\n31\n\n"; + assertEquals(truth, readFile(filename)); + } + + public void testWriteYml() { + String filename = OpenCVTestRunner.getTempFileName("yml"); + + extractor.write(filename); + + String truth = "%YAML:1.0\nscaleFactor: 1.2000000476837158e+00\nnLevels: 3\nfirstLevel: 0\nedgeThreshold: 31\npatchSize: 31\n"; + assertEquals(truth, readFile(filename)); + } + +} diff --git a/modules/java/android_test/src/org/opencv/test/features2d/SIFTDescriptorExtractorTest.java b/modules/java/android_test/src/org/opencv/test/features2d/SIFTDescriptorExtractorTest.java new file mode 100644 index 0000000..c1329ab --- /dev/null +++ b/modules/java/android_test/src/org/opencv/test/features2d/SIFTDescriptorExtractorTest.java @@ -0,0 +1,106 @@ +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.DescriptorExtractor; +import org.opencv.features2d.KeyPoint; +import org.opencv.test.OpenCVTestCase; +import org.opencv.test.OpenCVTestRunner; + +import java.util.Arrays; +import java.util.List; + +public class SIFTDescriptorExtractorTest extends OpenCVTestCase { + + DescriptorExtractor extractor; + KeyPoint keypoint; + Mat truth; + int matSize; + + 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; + } + + @Override + protected void setUp() throws Exception { + extractor = DescriptorExtractor.create(DescriptorExtractor.SIFT); + keypoint = new KeyPoint(55.775577545166016f, 44.224422454833984f, 16, 9.754629f, 8617.863f, 1, -1); + matSize = 100; + truth = new Mat(1, 128, CvType.CV_32FC1) { + { + put(0,0, 123, 0, 0, 1, 123, 0, 0, 1, 123, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 123, 0, 0, 2, 123, 0, 0, 2, 123, 0, 0, 0, 0, 0, 0, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 123, 30, + 7, 31, 123, 0, 0, 0, 123, 52, 88, 0, 0, 0, 0, 0, 0, 2, 123, 0, 0, 0, 0, 0, 0, 1, 110, 0, 0, 0, 0, 0, 18, 37, 18, 34, 16, + 21, 12, 23, 12, 50, 123, 0, 0, 0, 90, 26, 0, 3, 123, 0, 0, 1, 122, 0, 0, 2, 123, 0, 0, 1, 93, 0); + } + }; + + super.setUp(); + } + + public void testCompute() { + List keypoints = Arrays.asList(keypoint); + Mat img = getTestImg(); + Mat descriptors = new Mat(); + + extractor.compute(img, keypoints, descriptors); + + assertMatEqual(truth, descriptors, EPS); + } + + public void testCreate() { + assertNotNull(extractor); + } + + public void testDescriptorSize() { + assertEquals(128, extractor.descriptorSize()); + } + + public void testDescriptorType() { + assertEquals(CvType.CV_32F, extractor.descriptorType()); + } + + public void testEmpty() { + assertFalse(extractor.empty()); + } + + public void testRead() { + List keypoints = Arrays.asList(keypoint); + Mat img = getTestImg(); + Mat descriptors = new Mat(); + + String filename = OpenCVTestRunner.getTempFileName("yml"); + writeFile(filename, "%YAML:1.0\nmagnification: 3.\nisNormalize: 1\nrecalculateAngles: 1\nnOctaves: 6\nnOctaveLayers: 4\nfirstOctave: -1\nangleMode: 0\n"); + + extractor.read(filename); + + extractor.compute(img, keypoints, descriptors); + assertMatNotEqual(truth, descriptors, EPS); + } + + public void testWrite() { + String filename = OpenCVTestRunner.getTempFileName("xml"); + + extractor.write(filename); + + String truth = "\n\n3.\n1\n1\n4\n3\n-1\n0\n\n"; + assertEquals(truth, readFile(filename)); + } + + public void testWriteYml() { + String filename = OpenCVTestRunner.getTempFileName("yml"); + + extractor.write(filename); + + String truth = "%YAML:1.0\nmagnification: 3.\nisNormalize: 1\nrecalculateAngles: 1\nnOctaves: 4\nnOctaveLayers: 3\nfirstOctave: -1\nangleMode: 0\n"; + assertEquals(truth, readFile(filename)); + } + +} -- 2.7.4