From 0b3dbdd4b3395674fe9d05162ab916b83e683559 Mon Sep 17 00:00:00 2001 From: Alexander Lyulkov Date: Thu, 25 Jul 2024 16:47:41 +0300 Subject: [PATCH] Added Java ORB test --- .../java/test/ORBFeatureDetectorTest.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/modules/features2d/misc/java/test/ORBFeatureDetectorTest.java b/modules/features2d/misc/java/test/ORBFeatureDetectorTest.java index 7399253af6..2cd9977fb2 100644 --- a/modules/features2d/misc/java/test/ORBFeatureDetectorTest.java +++ b/modules/features2d/misc/java/test/ORBFeatureDetectorTest.java @@ -1,5 +1,13 @@ package org.opencv.test.features2d; +import org.junit.Assert; +import org.opencv.core.CvType; +import org.opencv.core.KeyPoint; +import org.opencv.core.Mat; +import org.opencv.core.MatOfKeyPoint; +import org.opencv.core.Scalar; +import org.opencv.features2d.Features2d; +import org.opencv.features2d.ORB; import org.opencv.test.OpenCVTestCase; public class ORBFeatureDetectorTest extends OpenCVTestCase { @@ -36,4 +44,35 @@ public class ORBFeatureDetectorTest extends OpenCVTestCase { fail("Not yet implemented"); } + public void testDetectTwoPoints() { + Mat img = new Mat(256,256, CvType.CV_8UC3, new Scalar(0,0,0)); + img.put(35, 40, 255,255, 255); + img.put(152, 98, 200,0, 0); + + MatOfKeyPoint keypoints = new MatOfKeyPoint(); + ORB orb = ORB.create(); + Mat descriptors = new Mat(); + orb.detectAndCompute(img, new Mat(), keypoints, descriptors); + + KeyPoint[] keypointsArray = keypoints.toArray(); + assertEquals(2, keypointsArray.length); + + long x1 = Math.round(keypointsArray[0].pt.x); + long y1 = Math.round(keypointsArray[0].pt.y); + long x2 = Math.round(keypointsArray[1].pt.x); + long y2 = Math.round(keypointsArray[1].pt.y); + + if (x2 > x1) { + assertEquals(40, x1); + assertEquals(35, y1); + assertEquals(98, x2); + assertEquals(152, y2); + } else { + assertEquals(40, x2); + assertEquals(35, y2); + assertEquals(98, x1); + assertEquals(152, y1); + } + } + }