From bd565df379fdc0bee4f10a65b4a1c15cb47bc709 Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Tue, 31 Oct 2023 11:23:47 +0300 Subject: [PATCH] Added Java bindings for BOWImgDescriptorExtractor constructor. --- .../features2d/include/opencv2/features2d.hpp | 4 +- .../test/BOWImgDescriptorExtractorTest.java | 48 +++++++++++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 modules/features2d/misc/java/test/BOWImgDescriptorExtractorTest.java diff --git a/modules/features2d/include/opencv2/features2d.hpp b/modules/features2d/include/opencv2/features2d.hpp index a7d348d833..e0d0187bdc 100644 --- a/modules/features2d/include/opencv2/features2d.hpp +++ b/modules/features2d/include/opencv2/features2d.hpp @@ -1544,8 +1544,8 @@ public: @param dmatcher Descriptor matcher that is used to find the nearest word of the trained vocabulary for each keypoint descriptor of the image. */ - CV_WRAP BOWImgDescriptorExtractor( const Ptr& dextractor, - const Ptr& dmatcher ); + CV_WRAP BOWImgDescriptorExtractor( const Ptr& dextractor, + const Ptr& dmatcher ); /** @overload */ BOWImgDescriptorExtractor( const Ptr& dmatcher ); virtual ~BOWImgDescriptorExtractor(); diff --git a/modules/features2d/misc/java/test/BOWImgDescriptorExtractorTest.java b/modules/features2d/misc/java/test/BOWImgDescriptorExtractorTest.java new file mode 100644 index 0000000000..a8ff001e85 --- /dev/null +++ b/modules/features2d/misc/java/test/BOWImgDescriptorExtractorTest.java @@ -0,0 +1,48 @@ +package org.opencv.test.features2d; + +import org.opencv.core.Core; +import org.opencv.core.CvType; +import org.opencv.core.Mat; +import org.opencv.core.MatOfKeyPoint; +import org.opencv.core.Point; +import org.opencv.core.Scalar; +import org.opencv.core.KeyPoint; +import org.opencv.features2d.ORB; +import org.opencv.features2d.DescriptorMatcher; +import org.opencv.features2d.BOWImgDescriptorExtractor; +import org.opencv.test.OpenCVTestCase; +import org.opencv.test.OpenCVTestRunner; +import org.opencv.imgproc.Imgproc; + +public class BOWImgDescriptorExtractorTest extends OpenCVTestCase { + + ORB extractor; + DescriptorMatcher matcher; + int matSize; + + public static void assertDescriptorsClose(Mat expected, Mat actual, int allowedDistance) { + double distance = Core.norm(expected, actual, Core.NORM_HAMMING); + assertTrue("expected:<" + allowedDistance + "> but was:<" + distance + ">", distance <= allowedDistance); + } + + private Mat getTestImg() { + Mat cross = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(255)); + Imgproc.line(cross, new Point(20, matSize / 2), new Point(matSize - 21, matSize / 2), new Scalar(100), 2); + Imgproc.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 { + super.setUp(); + extractor = ORB.create(); + matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE); + matSize = 100; + } + + public void testCreate() { + BOWImgDescriptorExtractor bow = new BOWImgDescriptorExtractor(extractor, matcher); + } + +}