From b562b69d0cd69b82864dc760adaa61e895511c1b Mon Sep 17 00:00:00 2001 From: AleksandrPanov Date: Thu, 24 Nov 2022 20:21:45 +0300 Subject: [PATCH] fix python/Java tests, add new Java test --- .../aruco/include/opencv2/aruco/charuco.hpp | 4 +-- modules/aruco/misc/java/test/ArucoTest.java | 26 +++++++++++++++++-- .../misc/pattern_generator/MarkerPrinter.py | 2 +- modules/aruco/misc/python/test/test_aruco.py | 12 ++++----- modules/ovis/samples/aruco_ar_demo.py | 2 +- modules/rapid/samples/track_marker.py | 2 +- 6 files changed, 35 insertions(+), 13 deletions(-) diff --git a/modules/aruco/include/opencv2/aruco/charuco.hpp b/modules/aruco/include/opencv2/aruco/charuco.hpp index 2f1a2334e..122228d4a 100644 --- a/modules/aruco/include/opencv2/aruco/charuco.hpp +++ b/modules/aruco/include/opencv2/aruco/charuco.hpp @@ -134,8 +134,8 @@ CV_EXPORTS_W void drawDetectedDiamonds(InputOutputArray image, InputArrayOfArray * This function return the image of a ChArUco marker, ready to be printed. */ CV_EXPORTS_W void drawCharucoDiamond(const Ptr &dictionary, Vec4i ids, int squareLength, - int markerLength, OutputArray img, int marginSize = 0, - int borderBits = 1); + int markerLength, OutputArray img, int marginSize = 0, + int borderBits = 1); //! @} } diff --git a/modules/aruco/misc/java/test/ArucoTest.java b/modules/aruco/misc/java/test/ArucoTest.java index 716f178d8..ffdb25c5f 100644 --- a/modules/aruco/misc/java/test/ArucoTest.java +++ b/modules/aruco/misc/java/test/ArucoTest.java @@ -6,6 +6,7 @@ import java.util.List; import org.opencv.test.OpenCVTestCase; import org.opencv.core.Scalar; import org.opencv.core.Mat; +import org.opencv.core.Size; import org.opencv.core.CvType; import org.opencv.aruco.*; import org.opencv.objdetect.*; @@ -13,9 +14,30 @@ import org.opencv.objdetect.*; public class ArucoTest extends OpenCVTestCase { + public void testDrawBoards() { + Dictionary dictionary = Objdetect.getPredefinedDictionary(Objdetect.DICT_4X4_50); + + Mat point1 = new Mat(4, 3, CvType.CV_32FC1); + int row = 0, col = 0; + point1.put(row ,col, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0); + + ListobjPoints = new ArrayList(); + objPoints.add(point1); + + Mat ids = new Mat(1, 1, CvType.CV_32SC1); + ids.put(row, col, 0); + + Board board = Board.create(objPoints, dictionary, ids); + + Mat image = new Mat(); + board.draw(new Size(50, 50), image); + + assertTrue(image.total() > 0); + } + public void testArucoIssue3133() { byte[][] marker = {{0,1,1},{1,1,1},{0,1,1}}; - Dictionary dictionary = extendDictionary(1, 3); + Dictionary dictionary = Objdetect.extendDictionary(1, 3); dictionary.set_maxCorrectionBits(0); Mat markerBits = new Mat(3, 3, CvType.CV_8UC1); for (int i = 0; i < 3; i++) { @@ -32,7 +54,7 @@ public class ArucoTest extends OpenCVTestCase { } public void testArucoDetector() { - Dictionary dictionary = getPredefinedDictionary(0); + Dictionary dictionary = Objdetect.getPredefinedDictionary(0); DetectorParameters detectorParameters = new DetectorParameters(); ArucoDetector detector = new ArucoDetector(dictionary, detectorParameters); diff --git a/modules/aruco/misc/pattern_generator/MarkerPrinter.py b/modules/aruco/misc/pattern_generator/MarkerPrinter.py index 301f4f918..4cf9185c3 100644 --- a/modules/aruco/misc/pattern_generator/MarkerPrinter.py +++ b/modules/aruco/misc/pattern_generator/MarkerPrinter.py @@ -39,7 +39,7 @@ def SaveArucoDictBytesList(filePath = "arucoDictBytesList.npz"): arucoDictBytesList = {} for name, flag in dictInfo: - arucoDict = aruco.Dictionary_get(flag) + arucoDict = aruco.getPredefinedDictionary(flag) arucoDictBytesList[name] = arucoDict.bytesList np.savez_compressed(filePath, **arucoDictBytesList) diff --git a/modules/aruco/misc/python/test/test_aruco.py b/modules/aruco/misc/python/test/test_aruco.py index b22b94eca..a37ccd618 100644 --- a/modules/aruco/misc/python/test/test_aruco.py +++ b/modules/aruco/misc/python/test/test_aruco.py @@ -16,7 +16,7 @@ class aruco_test(NewOpenCVTests): ids = np.arange(17) rev_ids = ids[::-1] - aruco_dict = cv.aruco.Dictionary_get(cv.aruco.DICT_5X5_250) + aruco_dict = cv.aruco.getPredefinedDictionary(cv.aruco.DICT_5X5_250) board = cv.aruco.CharucoBoard_create(7, 5, 1, 0.5, aruco_dict) np.testing.assert_array_equal(board.getIds().squeeze(), ids) @@ -28,7 +28,7 @@ class aruco_test(NewOpenCVTests): np.testing.assert_array_equal(board.getIds().squeeze(), ids) def test_drawCharucoDiamond(self): - aruco_dict = cv.aruco.Dictionary_get(cv.aruco.DICT_4X4_50) + aruco_dict = cv.aruco.getPredefinedDictionary(cv.aruco.DICT_4X4_50) img = cv.aruco.drawCharucoDiamond(aruco_dict, np.array([0, 1, 2, 3]), 100, 80) self.assertTrue(img is not None) @@ -62,7 +62,7 @@ class aruco_test(NewOpenCVTests): os.remove(filename) def test_identify(self): - aruco_dict = cv.aruco.Dictionary_get(cv.aruco.DICT_4X4_50) + aruco_dict = cv.aruco.getPredefinedDictionary(cv.aruco.DICT_4X4_50) expected_idx = 9 expected_rotation = 2 bit_marker = np.array([[0, 1, 1, 0], [1, 0, 1, 0], [1, 1, 1, 1], [0, 0, 1, 1]], dtype=np.uint8) @@ -74,7 +74,7 @@ class aruco_test(NewOpenCVTests): self.assertEqual(rotation, expected_rotation) def test_getDistanceToId(self): - aruco_dict = cv.aruco.Dictionary_get(cv.aruco.DICT_4X4_50) + aruco_dict = cv.aruco.getPredefinedDictionary(cv.aruco.DICT_4X4_50) idx = 7 rotation = 3 bit_marker = np.array([[0, 1, 0, 1], [0, 1, 1, 1], [1, 1, 0, 0], [0, 1, 0, 0]], dtype=np.uint8) @@ -84,7 +84,7 @@ class aruco_test(NewOpenCVTests): def test_aruco_detector(self): aruco_params = cv.aruco.DetectorParameters() - aruco_dict = cv.aruco.Dictionary_get(cv.aruco.DICT_4X4_250) + aruco_dict = cv.aruco.getPredefinedDictionary(cv.aruco.DICT_4X4_250) aruco_detector = cv.aruco.ArucoDetector(aruco_dict, aruco_params) id = 2 marker_size = 100 @@ -107,7 +107,7 @@ class aruco_test(NewOpenCVTests): def test_aruco_detector_refine(self): aruco_params = cv.aruco.DetectorParameters() - aruco_dict = cv.aruco.Dictionary_get(cv.aruco.DICT_4X4_250) + aruco_dict = cv.aruco.getPredefinedDictionary(cv.aruco.DICT_4X4_250) aruco_detector = cv.aruco.ArucoDetector(aruco_dict, aruco_params) board_size = (3, 4) board = cv.aruco.GridBoard_create(board_size[0], board_size[1], 5.0, 1.0, aruco_dict) diff --git a/modules/ovis/samples/aruco_ar_demo.py b/modules/ovis/samples/aruco_ar_demo.py index 567912c5b..72aeeaebe 100644 --- a/modules/ovis/samples/aruco_ar_demo.py +++ b/modules/ovis/samples/aruco_ar_demo.py @@ -2,7 +2,7 @@ import numpy as np import cv2 as cv # aruco -adict = cv.aruco.Dictionary_get(cv.aruco.DICT_4X4_50) +adict = cv.aruco.getPredefinedDictionary(cv.aruco.DICT_4X4_50) cv.imshow("marker", cv.aruco.drawMarker(adict, 0, 400)) # random calibration data. your mileage may vary. diff --git a/modules/rapid/samples/track_marker.py b/modules/rapid/samples/track_marker.py index fc17353ff..aa084e5ca 100644 --- a/modules/rapid/samples/track_marker.py +++ b/modules/rapid/samples/track_marker.py @@ -2,7 +2,7 @@ import numpy as np import cv2 as cv # aruco config -adict = cv.aruco.Dictionary_get(cv.aruco.DICT_4X4_50) +adict = cv.aruco.getPredefinedDictionary(cv.aruco.DICT_4X4_50) cv.imshow("marker", cv.aruco.drawMarker(adict, 0, 400)) marker_len = 5