From 387e8c9ef507b0c52fd0f1c50ecfba8fd2b9b8e7 Mon Sep 17 00:00:00 2001 From: Andrey Kamaev Date: Fri, 29 Jul 2011 12:42:23 +0000 Subject: [PATCH] Java API: star detector is covered by tests --- .../test/features2d/StarDetectorTest.java | 73 +++++++++++++------ 1 file changed, 52 insertions(+), 21 deletions(-) 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 index c1a2de9c33..fdd0f335c7 100644 --- a/modules/java/android_test/src/org/opencv/test/features2d/StarDetectorTest.java +++ b/modules/java/android_test/src/org/opencv/test/features2d/StarDetectorTest.java @@ -1,31 +1,62 @@ 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.RotatedRect; +import org.opencv.core.Scalar; +import org.opencv.core.Size; +import org.opencv.features2d.KeyPoint; import org.opencv.features2d.StarDetector; import org.opencv.test.OpenCVTestCase; +import org.opencv.test.OpenCVTestRunner; + +import java.util.LinkedList; +import java.util.List; public class StarDetectorTest extends OpenCVTestCase { - - private StarDetector star; - - @Override - protected void setUp() throws Exception { - super.setUp(); + + 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 = null; + 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); } - - public void test_1() { - super.test_1("FEATURES2D.StarDetector"); - } - - public void testStarDetector() { - star = new StarDetector(); - assertTrue(null != star); - } - - public void testStarDetectorIntIntIntIntInt() { - star = new StarDetector(45, 30, 10, 8, 5); - assertTrue(null != star); - } }