mirror of
https://github.com/opencv/opencv_contrib.git
synced 2025-10-15 03:38:39 +08:00
fix python/Java tests, add new Java test
This commit is contained in:
@@ -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.
|
* This function return the image of a ChArUco marker, ready to be printed.
|
||||||
*/
|
*/
|
||||||
CV_EXPORTS_W void drawCharucoDiamond(const Ptr<Dictionary> &dictionary, Vec4i ids, int squareLength,
|
CV_EXPORTS_W void drawCharucoDiamond(const Ptr<Dictionary> &dictionary, Vec4i ids, int squareLength,
|
||||||
int markerLength, OutputArray img, int marginSize = 0,
|
int markerLength, OutputArray img, int marginSize = 0,
|
||||||
int borderBits = 1);
|
int borderBits = 1);
|
||||||
|
|
||||||
//! @}
|
//! @}
|
||||||
}
|
}
|
||||||
|
@@ -6,6 +6,7 @@ import java.util.List;
|
|||||||
import org.opencv.test.OpenCVTestCase;
|
import org.opencv.test.OpenCVTestCase;
|
||||||
import org.opencv.core.Scalar;
|
import org.opencv.core.Scalar;
|
||||||
import org.opencv.core.Mat;
|
import org.opencv.core.Mat;
|
||||||
|
import org.opencv.core.Size;
|
||||||
import org.opencv.core.CvType;
|
import org.opencv.core.CvType;
|
||||||
import org.opencv.aruco.*;
|
import org.opencv.aruco.*;
|
||||||
import org.opencv.objdetect.*;
|
import org.opencv.objdetect.*;
|
||||||
@@ -13,9 +14,30 @@ import org.opencv.objdetect.*;
|
|||||||
|
|
||||||
public class ArucoTest extends OpenCVTestCase {
|
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);
|
||||||
|
|
||||||
|
List<Mat>objPoints = new ArrayList<Mat>();
|
||||||
|
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() {
|
public void testArucoIssue3133() {
|
||||||
byte[][] marker = {{0,1,1},{1,1,1},{0,1,1}};
|
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);
|
dictionary.set_maxCorrectionBits(0);
|
||||||
Mat markerBits = new Mat(3, 3, CvType.CV_8UC1);
|
Mat markerBits = new Mat(3, 3, CvType.CV_8UC1);
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
@@ -32,7 +54,7 @@ public class ArucoTest extends OpenCVTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testArucoDetector() {
|
public void testArucoDetector() {
|
||||||
Dictionary dictionary = getPredefinedDictionary(0);
|
Dictionary dictionary = Objdetect.getPredefinedDictionary(0);
|
||||||
DetectorParameters detectorParameters = new DetectorParameters();
|
DetectorParameters detectorParameters = new DetectorParameters();
|
||||||
ArucoDetector detector = new ArucoDetector(dictionary, detectorParameters);
|
ArucoDetector detector = new ArucoDetector(dictionary, detectorParameters);
|
||||||
|
|
||||||
|
@@ -39,7 +39,7 @@ def SaveArucoDictBytesList(filePath = "arucoDictBytesList.npz"):
|
|||||||
|
|
||||||
arucoDictBytesList = {}
|
arucoDictBytesList = {}
|
||||||
for name, flag in dictInfo:
|
for name, flag in dictInfo:
|
||||||
arucoDict = aruco.Dictionary_get(flag)
|
arucoDict = aruco.getPredefinedDictionary(flag)
|
||||||
arucoDictBytesList[name] = arucoDict.bytesList
|
arucoDictBytesList[name] = arucoDict.bytesList
|
||||||
|
|
||||||
np.savez_compressed(filePath, **arucoDictBytesList)
|
np.savez_compressed(filePath, **arucoDictBytesList)
|
||||||
|
@@ -16,7 +16,7 @@ class aruco_test(NewOpenCVTests):
|
|||||||
ids = np.arange(17)
|
ids = np.arange(17)
|
||||||
rev_ids = ids[::-1]
|
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)
|
board = cv.aruco.CharucoBoard_create(7, 5, 1, 0.5, aruco_dict)
|
||||||
|
|
||||||
np.testing.assert_array_equal(board.getIds().squeeze(), ids)
|
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)
|
np.testing.assert_array_equal(board.getIds().squeeze(), ids)
|
||||||
|
|
||||||
def test_drawCharucoDiamond(self):
|
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)
|
img = cv.aruco.drawCharucoDiamond(aruco_dict, np.array([0, 1, 2, 3]), 100, 80)
|
||||||
self.assertTrue(img is not None)
|
self.assertTrue(img is not None)
|
||||||
|
|
||||||
@@ -62,7 +62,7 @@ class aruco_test(NewOpenCVTests):
|
|||||||
os.remove(filename)
|
os.remove(filename)
|
||||||
|
|
||||||
def test_identify(self):
|
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_idx = 9
|
||||||
expected_rotation = 2
|
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)
|
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)
|
self.assertEqual(rotation, expected_rotation)
|
||||||
|
|
||||||
def test_getDistanceToId(self):
|
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
|
idx = 7
|
||||||
rotation = 3
|
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)
|
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):
|
def test_aruco_detector(self):
|
||||||
aruco_params = cv.aruco.DetectorParameters()
|
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)
|
aruco_detector = cv.aruco.ArucoDetector(aruco_dict, aruco_params)
|
||||||
id = 2
|
id = 2
|
||||||
marker_size = 100
|
marker_size = 100
|
||||||
@@ -107,7 +107,7 @@ class aruco_test(NewOpenCVTests):
|
|||||||
|
|
||||||
def test_aruco_detector_refine(self):
|
def test_aruco_detector_refine(self):
|
||||||
aruco_params = cv.aruco.DetectorParameters()
|
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)
|
aruco_detector = cv.aruco.ArucoDetector(aruco_dict, aruco_params)
|
||||||
board_size = (3, 4)
|
board_size = (3, 4)
|
||||||
board = cv.aruco.GridBoard_create(board_size[0], board_size[1], 5.0, 1.0, aruco_dict)
|
board = cv.aruco.GridBoard_create(board_size[0], board_size[1], 5.0, 1.0, aruco_dict)
|
||||||
|
@@ -2,7 +2,7 @@ import numpy as np
|
|||||||
import cv2 as cv
|
import cv2 as cv
|
||||||
|
|
||||||
# aruco
|
# 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))
|
cv.imshow("marker", cv.aruco.drawMarker(adict, 0, 400))
|
||||||
|
|
||||||
# random calibration data. your mileage may vary.
|
# random calibration data. your mileage may vary.
|
||||||
|
@@ -2,7 +2,7 @@ import numpy as np
|
|||||||
import cv2 as cv
|
import cv2 as cv
|
||||||
|
|
||||||
# aruco config
|
# 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))
|
cv.imshow("marker", cv.aruco.drawMarker(adict, 0, 400))
|
||||||
marker_len = 5
|
marker_len = 5
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user