mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 23:33:05 +04:00
Merge branch 4.x
This commit is contained in:
@@ -691,6 +691,58 @@ TEST(Charuco, testmatchImagePoints)
|
||||
}
|
||||
}
|
||||
|
||||
typedef testing::TestWithParam<int> CharucoDraw;
|
||||
INSTANTIATE_TEST_CASE_P(/**/, CharucoDraw, testing::Values(CV_8UC2, CV_8SC2, CV_16UC2, CV_16SC2, CV_32SC2, CV_32FC2, CV_64FC2));
|
||||
TEST_P(CharucoDraw, testDrawDetected) {
|
||||
vector<vector<Point>> detected_golds = {{Point(20, 20), Point(80, 20), Point(80, 80), Point2f(20, 80)}};
|
||||
Point center_gold = (detected_golds[0][0] + detected_golds[0][1] + detected_golds[0][2] + detected_golds[0][3]) / 4;
|
||||
int type = GetParam();
|
||||
vector<Mat> detected(detected_golds[0].size(), Mat(4, 1, type));
|
||||
// copy detected_golds to detected with any 2 channels type
|
||||
for (size_t i = 0ull; i < detected_golds[0].size(); i++) {
|
||||
detected[0].row((int)i) = Scalar(detected_golds[0][i].x, detected_golds[0][i].y);
|
||||
}
|
||||
vector<vector<Point>> contours;
|
||||
Point detectedCenter;
|
||||
Moments m;
|
||||
Mat img;
|
||||
|
||||
// check drawDetectedMarkers
|
||||
img = Mat::zeros(100, 100, CV_8UC1);
|
||||
ASSERT_NO_THROW(aruco::drawDetectedMarkers(img, detected, noArray(), Scalar(255, 255, 255)));
|
||||
// check that the marker borders are painted
|
||||
findContours(img, contours, RETR_EXTERNAL, CHAIN_APPROX_SIMPLE);
|
||||
ASSERT_EQ(contours.size(), 1ull);
|
||||
m = moments(contours[0]);
|
||||
detectedCenter = Point(cvRound(m.m10/m.m00), cvRound(m.m01/m.m00));
|
||||
ASSERT_EQ(detectedCenter, center_gold);
|
||||
|
||||
|
||||
// check drawDetectedCornersCharuco
|
||||
img = Mat::zeros(100, 100, CV_8UC1);
|
||||
ASSERT_NO_THROW(aruco::drawDetectedCornersCharuco(img, detected[0], noArray(), Scalar(255, 255, 255)));
|
||||
// check that the 4 charuco corners are painted
|
||||
findContours(img, contours, RETR_EXTERNAL, CHAIN_APPROX_SIMPLE);
|
||||
ASSERT_EQ(contours.size(), 4ull);
|
||||
for (size_t i = 0ull; i < 4ull; i++) {
|
||||
m = moments(contours[i]);
|
||||
detectedCenter = Point(cvRound(m.m10/m.m00), cvRound(m.m01/m.m00));
|
||||
// detectedCenter must be in detected_golds
|
||||
ASSERT_TRUE(find(detected_golds[0].begin(), detected_golds[0].end(), detectedCenter) != detected_golds[0].end());
|
||||
}
|
||||
|
||||
|
||||
// check drawDetectedDiamonds
|
||||
img = Mat::zeros(100, 100, CV_8UC1);
|
||||
ASSERT_NO_THROW(aruco::drawDetectedDiamonds(img, detected, noArray(), Scalar(255, 255, 255)));
|
||||
// check that the diamonds borders are painted
|
||||
findContours(img, contours, RETR_EXTERNAL, CHAIN_APPROX_SIMPLE);
|
||||
ASSERT_EQ(contours.size(), 1ull);
|
||||
m = moments(contours[0]);
|
||||
detectedCenter = Point(cvRound(m.m10/m.m00), cvRound(m.m01/m.m00));
|
||||
ASSERT_EQ(detectedCenter, center_gold);
|
||||
}
|
||||
|
||||
typedef testing::TestWithParam<cv::Size> CharucoBoard;
|
||||
INSTANTIATE_TEST_CASE_P(/**/, CharucoBoard, testing::Values(Size(3, 2), Size(3, 2), Size(6, 2), Size(2, 6),
|
||||
Size(3, 4), Size(4, 3), Size(7, 3), Size(3, 7)));
|
||||
@@ -719,4 +771,60 @@ TEST_P(CharucoBoard, testWrongSizeDetection)
|
||||
ASSERT_TRUE(detectedCharucoIds.empty());
|
||||
}
|
||||
|
||||
// Temporary disabled in https://github.com/opencv/opencv/pull/24338
|
||||
// 5.x version produces conrnes with different shape than 4.x (32F_C2 instead of 2x 32FC1)
|
||||
TEST(Charuco, DISABLED_testSeveralBoardsWithCustomIds)
|
||||
{
|
||||
Size res{500, 500};
|
||||
Mat K = (Mat_<double>(3,3) <<
|
||||
0.5*res.width, 0, 0.5*res.width,
|
||||
0, 0.5*res.height, 0.5*res.height,
|
||||
0, 0, 1);
|
||||
|
||||
Mat expected_corners = (Mat_<float>(9,2) <<
|
||||
200, 200,
|
||||
250, 200,
|
||||
300, 200,
|
||||
200, 250,
|
||||
250, 250,
|
||||
300, 250,
|
||||
200, 300,
|
||||
250, 300,
|
||||
300, 300
|
||||
);
|
||||
|
||||
|
||||
aruco::Dictionary dict = cv::aruco::getPredefinedDictionary(aruco::DICT_4X4_50);
|
||||
vector<int> ids1 = {0, 1, 33, 3, 4, 5, 6, 8}, ids2 = {7, 9, 44, 11, 12, 13, 14, 15};
|
||||
aruco::CharucoBoard board1(Size(4, 4), 1.f, .8f, dict, ids1), board2(Size(4, 4), 1.f, .8f, dict, ids2);
|
||||
|
||||
// generate ChArUco board
|
||||
Mat gray;
|
||||
{
|
||||
Mat gray1, gray2;
|
||||
board1.generateImage(Size(res.width, res.height), gray1, 150);
|
||||
board2.generateImage(Size(res.width, res.height), gray2, 150);
|
||||
hconcat(gray1, gray2, gray);
|
||||
}
|
||||
|
||||
aruco::CharucoParameters charucoParameters;
|
||||
charucoParameters.cameraMatrix = K;
|
||||
aruco::CharucoDetector detector1(board1, charucoParameters), detector2(board2, charucoParameters);
|
||||
|
||||
vector<int> ids;
|
||||
vector<Mat> corners;
|
||||
Mat c_ids1, c_ids2, c_corners1, c_corners2;
|
||||
|
||||
detector1.detectBoard(gray, c_corners1, c_ids1, corners, ids);
|
||||
detector2.detectBoard(gray, c_corners2, c_ids2, corners, ids);
|
||||
|
||||
ASSERT_EQ(ids.size(), size_t(16));
|
||||
ASSERT_EQ(c_corners1.rows, expected_corners.rows);
|
||||
EXPECT_NEAR(0, cvtest::norm(expected_corners, c_corners1.reshape(1), NORM_INF), 3e-1);
|
||||
|
||||
ASSERT_EQ(c_corners2.rows, expected_corners.rows);
|
||||
expected_corners.col(0) += 500;
|
||||
EXPECT_NEAR(0, cvtest::norm(expected_corners, c_corners2.reshape(1), NORM_INF), 3e-1);
|
||||
}
|
||||
|
||||
}} // namespace
|
||||
|
||||
Reference in New Issue
Block a user