From 6fbcb283b94043cbb91dfaee3cdda9464cb055d1 Mon Sep 17 00:00:00 2001 From: Dmitry Kurtaev Date: Tue, 18 Dec 2018 17:39:31 +0300 Subject: [PATCH] Try to fix "enum struct" wrapping for Java --- .../misc/java/test/Features2dTest.java | 28 +++++++++++++++++++ modules/java/generator/gen_java.py | 7 +++-- modules/python/src2/hdr_parser.py | 2 ++ .../SURFFLANNMatchingDemo.java | 2 +- .../SURFFLANNMatchingHomographyDemo.java | 2 +- 5 files changed, 37 insertions(+), 4 deletions(-) diff --git a/modules/features2d/misc/java/test/Features2dTest.java b/modules/features2d/misc/java/test/Features2dTest.java index e27bec6960..db9739bd44 100644 --- a/modules/features2d/misc/java/test/Features2dTest.java +++ b/modules/features2d/misc/java/test/Features2dTest.java @@ -7,11 +7,13 @@ import java.util.List; import org.opencv.calib3d.Calib3d; import org.opencv.core.CvType; import org.opencv.core.Mat; +import org.opencv.core.MatOfInt; import org.opencv.core.MatOfDMatch; import org.opencv.core.MatOfKeyPoint; import org.opencv.core.MatOfPoint2f; import org.opencv.core.Point; import org.opencv.core.Range; +import org.opencv.core.Scalar; import org.opencv.core.DMatch; import org.opencv.features2d.DescriptorMatcher; import org.opencv.features2d.Features2d; @@ -141,4 +143,30 @@ public class Features2dTest extends OpenCVTestCase { Imgcodecs.imwrite(outputPath, outimg); // OpenCVTestRunner.Log("Output image is saved to: " + outputPath); } + + public void testDrawKeypoints() + { + Mat outImg = Mat.ones(11, 11, CvType.CV_8U); + + MatOfKeyPoint kps = new MatOfKeyPoint(new KeyPoint(5, 5, 1)); // x, y, size + Features2d.drawKeypoints(new Mat(), kps, outImg, new Scalar(255), + Features2d.DrawMatchesFlags_DRAW_OVER_OUTIMG); + + Mat ref = new MatOfInt(new int[] { + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 15, 54, 15, 1, 1, 1, 1, + 1, 1, 1, 76, 217, 217, 221, 81, 1, 1, 1, + 1, 1, 100, 224, 111, 57, 115, 225, 101, 1, 1, + 1, 44, 215, 100, 1, 1, 1, 101, 214, 44, 1, + 1, 54, 212, 57, 1, 1, 1, 55, 212, 55, 1, + 1, 40, 215, 104, 1, 1, 1, 105, 215, 40, 1, + 1, 1, 102, 221, 111, 55, 115, 222, 103, 1, 1, + 1, 1, 1, 76, 218, 217, 220, 81, 1, 1, 1, + 1, 1, 1, 1, 15, 55, 15, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 + }).reshape(1, 11); + ref.convertTo(ref, CvType.CV_8U); + + assertMatEqual(ref, outImg); + } } diff --git a/modules/java/generator/gen_java.py b/modules/java/generator/gen_java.py index 74c082470d..b1ea133edf 100755 --- a/modules/java/generator/gen_java.py +++ b/modules/java/generator/gen_java.py @@ -427,9 +427,12 @@ class JavaWrapperGenerator(object): constinfo = ConstInfo(decl, namespaces=self.namespaces, enumType=enumType) if constinfo.isIgnored(): logging.info('ignored: %s', constinfo) - elif not self.isWrapped(constinfo.classname): - logging.info('class not found: %s', constinfo) else: + if not self.isWrapped(constinfo.classname): + logging.info('class not found: %s', constinfo) + constinfo.name = constinfo.classname + '_' + constinfo.name + constinfo.classname = '' + ci = self.getClass(constinfo.classname) duplicate = ci.getConst(constinfo.name) if duplicate: diff --git a/modules/python/src2/hdr_parser.py b/modules/python/src2/hdr_parser.py index 41100ba727..3f8eee4a40 100755 --- a/modules/python/src2/hdr_parser.py +++ b/modules/python/src2/hdr_parser.py @@ -634,6 +634,8 @@ class CppHeaderParser(object): block_type, block_name = b[self.BLOCK_TYPE], b[self.BLOCK_NAME] if block_type in ["file", "enum"]: continue + if block_type in ["enum struct", "enum class"] and block_name == name: + continue if block_type not in ["struct", "class", "namespace", "enum struct", "enum class"]: print("Error at %d: there are non-valid entries in the current block stack %s" % (self.lineno, self.block_stack)) sys.exit(-1) diff --git a/samples/java/tutorial_code/features2D/feature_flann_matcher/SURFFLANNMatchingDemo.java b/samples/java/tutorial_code/features2D/feature_flann_matcher/SURFFLANNMatchingDemo.java index 365c0c7ee2..bd24e9a8e2 100644 --- a/samples/java/tutorial_code/features2D/feature_flann_matcher/SURFFLANNMatchingDemo.java +++ b/samples/java/tutorial_code/features2D/feature_flann_matcher/SURFFLANNMatchingDemo.java @@ -58,7 +58,7 @@ class SURFFLANNMatching { //-- Draw matches Mat imgMatches = new Mat(); Features2d.drawMatches(img1, keypoints1, img2, keypoints2, goodMatches, imgMatches, Scalar.all(-1), - Scalar.all(-1), new MatOfByte(), Features2d.NOT_DRAW_SINGLE_POINTS); + Scalar.all(-1), new MatOfByte(), Features2d.DrawMatchesFlags_NOT_DRAW_SINGLE_POINTS); //-- Show detected matches HighGui.imshow("Good Matches", imgMatches); diff --git a/samples/java/tutorial_code/features2D/feature_homography/SURFFLANNMatchingHomographyDemo.java b/samples/java/tutorial_code/features2D/feature_homography/SURFFLANNMatchingHomographyDemo.java index 44367dd966..1ee33b44f5 100644 --- a/samples/java/tutorial_code/features2D/feature_homography/SURFFLANNMatchingHomographyDemo.java +++ b/samples/java/tutorial_code/features2D/feature_homography/SURFFLANNMatchingHomographyDemo.java @@ -64,7 +64,7 @@ class SURFFLANNMatchingHomography { //-- Draw matches Mat imgMatches = new Mat(); Features2d.drawMatches(imgObject, keypointsObject, imgScene, keypointsScene, goodMatches, imgMatches, Scalar.all(-1), - Scalar.all(-1), new MatOfByte(), Features2d.NOT_DRAW_SINGLE_POINTS); + Scalar.all(-1), new MatOfByte(), Features2d.DrawMatchesFlags_NOT_DRAW_SINGLE_POINTS); //-- Localize the object List obj = new ArrayList<>();