1
0
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:
Alexander Smorkalov
2023-06-01 09:37:38 +03:00
565 changed files with 84396 additions and 17589 deletions
+5 -5
View File
@@ -8,12 +8,12 @@
namespace opencv_test {
vector<Point2f> getAxis(InputArray _cameraMatrix, InputArray _distCoeffs, InputArray _rvec,
InputArray _tvec, float length, const float offset) {
InputArray _tvec, float length, const Point2f offset) {
vector<Point3f> axis;
axis.push_back(Point3f(offset, offset, 0.f));
axis.push_back(Point3f(length+offset, offset, 0.f));
axis.push_back(Point3f(offset, length+offset, 0.f));
axis.push_back(Point3f(offset, offset, length));
axis.push_back(Point3f(offset.x, offset.y, 0.f));
axis.push_back(Point3f(length+offset.x, offset.y, 0.f));
axis.push_back(Point3f(offset.x, length+offset.y, 0.f));
axis.push_back(Point3f(offset.x, offset.y, length));
vector<Point2f> axis_to_img;
projectPoints(axis, _rvec, _tvec, _cameraMatrix, _distCoeffs, axis_to_img);
return axis_to_img;
+1 -1
View File
@@ -10,7 +10,7 @@ namespace opencv_test {
static inline double deg2rad(double deg) { return deg * CV_PI / 180.; }
vector<Point2f> getAxis(InputArray _cameraMatrix, InputArray _distCoeffs, InputArray _rvec, InputArray _tvec,
float length, const float offset = 0.f);
float length, const Point2f offset = Point2f(0, 0));
vector<Point2f> getMarkerById(int id, const vector<vector<Point2f> >& corners, const vector<int>& ids);
@@ -247,7 +247,7 @@ void CV_ArucoDetectionPerspective::run(int) {
aruco::ArucoDetector detector(aruco::getPredefinedDictionary(aruco::DICT_6X6_250), params);
// detect from different positions
for(double distance = 0.1; distance < 0.7; distance += 0.2) {
for(double distance : {0.1, 0.3, 0.5, 0.7}) {
for(int pitch = 0; pitch < 360; pitch += (distance == 0.1? 60:180)) {
for(int yaw = 70; yaw <= 120; yaw += 40){
int currentId = iter % 250;
@@ -51,7 +51,7 @@ void CV_ArucoBoardPose::run(int) {
aruco::DetectorParameters detectorParameters = detector.getDetectorParameters();
// for different perspectives
for(double distance = 0.2; distance <= 0.4; distance += 0.15) {
for(double distance : {0.2, 0.35}) {
for(int yaw = -55; yaw <= 50; yaw += 25) {
for(int pitch = -55; pitch <= 50; pitch += 25) {
vector<int> tmpIds;
@@ -162,7 +162,7 @@ void CV_ArucoRefine::run(int) {
aruco::DetectorParameters detectorParameters = detector.getDetectorParameters();
// for different perspectives
for(double distance = 0.2; distance <= 0.4; distance += 0.2) {
for(double distance : {0.2, 0.4}) {
for(int yaw = -60; yaw < 60; yaw += 30) {
for(int pitch = -60; pitch <= 60; pitch += 30) {
aruco::GridBoard gridboard(Size(3, 3), 0.02f, 0.005f, detector.getDictionary());
@@ -12,7 +12,7 @@ namespace opencv_test { namespace {
* @brief Get a synthetic image of Chessboard in perspective
*/
static Mat projectChessboard(int squaresX, int squaresY, float squareSize, Size imageSize,
Mat cameraMatrix, Mat rvec, Mat tvec) {
Mat cameraMatrix, Mat rvec, Mat tvec, bool legacyPattern) {
Mat img(imageSize, CV_8UC1, Scalar::all(255));
Mat distCoeffs(5, 1, CV_64FC1, Scalar::all(0));
@@ -20,7 +20,11 @@ static Mat projectChessboard(int squaresX, int squaresY, float squareSize, Size
for(int y = 0; y < squaresY; y++) {
float startY = float(y) * squareSize;
for(int x = 0; x < squaresX; x++) {
if(y % 2 != x % 2) continue;
if(legacyPattern && (squaresY % 2 == 0)) {
if((y + 1) % 2 != x % 2) continue;
} else {
if(y % 2 != x % 2) continue;
}
float startX = float(x) * squareSize;
vector< Point3f > squareCorners;
@@ -66,7 +70,7 @@ static Mat projectCharucoBoard(aruco::CharucoBoard& board, Mat cameraMatrix, dou
// project chessboard
Mat chessboard =
projectChessboard(board.getChessboardSize().width, board.getChessboardSize().height,
board.getSquareLength(), imageSize, cameraMatrix, rvec, tvec);
board.getSquareLength(), imageSize, cameraMatrix, rvec, tvec, board.getLegacyPattern());
for(unsigned int i = 0; i < chessboard.total(); i++) {
if(chessboard.ptr< unsigned char >()[i] == 0) {
@@ -82,16 +86,15 @@ static Mat projectCharucoBoard(aruco::CharucoBoard& board, Mat cameraMatrix, dou
*/
class CV_CharucoDetection : public cvtest::BaseTest {
public:
CV_CharucoDetection();
CV_CharucoDetection(bool _legacyPattern) : legacyPattern(_legacyPattern) {}
protected:
void run(int);
bool legacyPattern;
};
CV_CharucoDetection::CV_CharucoDetection() {}
void CV_CharucoDetection::run(int) {
int iter = 0;
@@ -100,6 +103,7 @@ void CV_CharucoDetection::run(int) {
aruco::DetectorParameters params;
params.minDistanceToBorder = 3;
aruco::CharucoBoard board(Size(4, 4), 0.03f, 0.015f, aruco::getPredefinedDictionary(aruco::DICT_6X6_250));
board.setLegacyPattern(legacyPattern);
aruco::CharucoDetector detector(board, aruco::CharucoParameters(), params);
cameraMatrix.at<double>(0, 0) = cameraMatrix.at<double>(1, 1) = 600;
@@ -109,7 +113,7 @@ void CV_CharucoDetection::run(int) {
Mat distCoeffs(5, 1, CV_64FC1, Scalar::all(0));
// for different perspectives
for(double distance = 0.2; distance <= 0.4; distance += 0.2) {
for(double distance : {0.2, 0.4}) {
for(int yaw = -55; yaw <= 50; yaw += 25) {
for(int pitch = -55; pitch <= 50; pitch += 25) {
@@ -140,11 +144,7 @@ void CV_CharucoDetection::run(int) {
detector.detectBoard(img, charucoCorners, charucoIds, corners, ids);
}
if(ids.size() == 0) {
ts->printf(cvtest::TS::LOG, "Marker detection failed");
ts->set_failed_test_info(cvtest::TS::FAIL_MISMATCH);
return;
}
ASSERT_GT(ids.size(), std::vector< int >::size_type(0)) << "Marker detection failed";
// check results
vector< Point2f > projectedCharucoCorners;
@@ -161,20 +161,11 @@ void CV_CharucoDetection::run(int) {
int currentId = charucoIds[i];
if(currentId >= (int)board.getChessboardCorners().size()) {
ts->printf(cvtest::TS::LOG, "Invalid Charuco corner id");
ts->set_failed_test_info(cvtest::TS::FAIL_MISMATCH);
return;
}
ASSERT_LT(currentId, (int)board.getChessboardCorners().size()) << "Invalid Charuco corner id";
double repError = cv::norm(charucoCorners[i] - projectedCharucoCorners[currentId]); // TODO cvtest
if(repError > 5.) {
ts->printf(cvtest::TS::LOG, "Charuco corner reprojection error too high");
ts->set_failed_test_info(cvtest::TS::FAIL_MISMATCH);
return;
}
ASSERT_LE(repError, 5.) << "Charuco corner reprojection error too high";
}
}
}
@@ -188,32 +179,33 @@ void CV_CharucoDetection::run(int) {
*/
class CV_CharucoPoseEstimation : public cvtest::BaseTest {
public:
CV_CharucoPoseEstimation();
CV_CharucoPoseEstimation(bool _legacyPattern) : legacyPattern(_legacyPattern) {}
protected:
void run(int);
bool legacyPattern;
};
CV_CharucoPoseEstimation::CV_CharucoPoseEstimation() {}
void CV_CharucoPoseEstimation::run(int) {
int iter = 0;
Mat cameraMatrix = Mat::eye(3, 3, CV_64FC1);
Size imgSize(500, 500);
Size imgSize(750, 750);
aruco::DetectorParameters params;
params.minDistanceToBorder = 3;
aruco::CharucoBoard board(Size(4, 4), 0.03f, 0.015f, aruco::getPredefinedDictionary(aruco::DICT_6X6_250));
board.setLegacyPattern(legacyPattern);
aruco::CharucoDetector detector(board, aruco::CharucoParameters(), params);
cameraMatrix.at<double>(0, 0) = cameraMatrix.at< double >(1, 1) = 650;
cameraMatrix.at<double>(0, 0) = cameraMatrix.at< double >(1, 1) = 1000;
cameraMatrix.at<double>(0, 2) = imgSize.width / 2;
cameraMatrix.at<double>(1, 2) = imgSize.height / 2;
Mat distCoeffs(5, 1, CV_64FC1, Scalar::all(0));
// for different perspectives
for(double distance = 0.2; distance <= 0.3; distance += 0.1) {
for(double distance : {0.2, 0.25}) {
for(int yaw = -55; yaw <= 50; yaw += 25) {
for(int pitch = -55; pitch <= 50; pitch += 25) {
@@ -252,12 +244,21 @@ void CV_CharucoPoseEstimation::run(int) {
// check axes
const float offset = (board.getSquareLength() - board.getMarkerLength()) / 2.f;
const float aruco_offset = (board.getSquareLength() - board.getMarkerLength()) / 2.f;
Point2f offset;
vector<Point2f> topLeft, bottomLeft;
if(legacyPattern) { // white box in upper left corner for even row count chessboard patterns
offset = Point2f(aruco_offset + board.getSquareLength(), aruco_offset);
topLeft = getMarkerById(board.getIds()[1], corners, ids);
bottomLeft = getMarkerById(board.getIds()[2], corners, ids);
} else { // always a black box in the upper left corner
offset = Point2f(aruco_offset, aruco_offset);
topLeft = getMarkerById(board.getIds()[0], corners, ids);
bottomLeft = getMarkerById(board.getIds()[2], corners, ids);
}
vector<Point2f> axes = getAxis(cameraMatrix, distCoeffs, rvec, tvec, board.getSquareLength(), offset);
vector<Point2f> topLeft = getMarkerById(board.getIds()[0], corners, ids);
ASSERT_NEAR(topLeft[0].x, axes[1].x, 3.f);
ASSERT_NEAR(topLeft[0].y, axes[1].y, 3.f);
vector<Point2f> bottomLeft = getMarkerById(board.getIds()[2], corners, ids);
ASSERT_NEAR(bottomLeft[0].x, axes[2].x, 3.f);
ASSERT_NEAR(bottomLeft[0].y, axes[2].y, 3.f);
@@ -271,20 +272,11 @@ void CV_CharucoPoseEstimation::run(int) {
int currentId = charucoIds[i];
if(currentId >= (int)board.getChessboardCorners().size()) {
ts->printf(cvtest::TS::LOG, "Invalid Charuco corner id");
ts->set_failed_test_info(cvtest::TS::FAIL_MISMATCH);
return;
}
ASSERT_LT(currentId, (int)board.getChessboardCorners().size()) << "Invalid Charuco corner id";
double repError = cv::norm(charucoCorners[i] - projectedCharucoCorners[currentId]); // TODO cvtest
if(repError > 5.) {
ts->printf(cvtest::TS::LOG, "Charuco corner reprojection error too high");
ts->set_failed_test_info(cvtest::TS::FAIL_MISMATCH);
return;
}
ASSERT_LE(repError, 5.) << "Charuco corner reprojection error too high";
}
}
}
@@ -332,7 +324,7 @@ void CV_CharucoDiamondDetection::run(int) {
detector.setCharucoParameters(charucoParameters);
// for different perspectives
for(double distance = 0.2; distance <= 0.3; distance += 0.1) {
for(double distance : {0.2, 0.22}) {
for(int yaw = -50; yaw <= 50; yaw += 25) {
for(int pitch = -50; pitch <= 50; pitch += 25) {
@@ -490,12 +482,26 @@ void CV_CharucoBoardCreation::run(int)
TEST(CV_CharucoDetection, accuracy) {
CV_CharucoDetection test;
const bool legacyPattern = false;
CV_CharucoDetection test(legacyPattern);
test.safe_run();
}
TEST(CV_CharucoDetection, accuracy_legacyPattern) {
const bool legacyPattern = true;
CV_CharucoDetection test(legacyPattern);
test.safe_run();
}
TEST(CV_CharucoPoseEstimation, accuracy) {
CV_CharucoPoseEstimation test;
const bool legacyPattern = false;
CV_CharucoPoseEstimation test(legacyPattern);
test.safe_run();
}
TEST(CV_CharucoPoseEstimation, accuracy_legacyPattern) {
const bool legacyPattern = true;
CV_CharucoPoseEstimation test(legacyPattern);
test.safe_run();
}
@@ -656,4 +662,31 @@ TEST(Charuco, issue_14014)
EXPECT_EQ(Size(4, 1), rejectedPoints[0].size()); // check dimension of rejected corners after successfully refine
}
TEST(Charuco, testmatchImagePoints)
{
aruco::CharucoBoard board(Size(2, 3), 1.f, 0.5f, aruco::getPredefinedDictionary(aruco::DICT_4X4_50));
auto chessboardPoints = board.getChessboardCorners();
vector<int> detectedIds;
vector<Point2f> detectedCharucoCorners;
for (const Point3f& point : chessboardPoints) {
detectedIds.push_back((int)detectedCharucoCorners.size());
detectedCharucoCorners.push_back({2.f*point.x, 2.f*point.y});
}
vector<Point3f> objPoints;
vector<Point2f> imagePoints;
board.matchImagePoints(detectedCharucoCorners, detectedIds, objPoints, imagePoints);
ASSERT_EQ(detectedCharucoCorners.size(), objPoints.size());
ASSERT_EQ(detectedCharucoCorners.size(), imagePoints.size());
for (size_t i = 0ull; i < detectedCharucoCorners.size(); i++) {
EXPECT_EQ(detectedCharucoCorners[i], imagePoints[i]);
EXPECT_EQ(chessboardPoints[i].x, objPoints[i].x);
EXPECT_EQ(chessboardPoints[i].y, objPoints[i].y);
}
}
}} // namespace
+5 -8
View File
@@ -65,20 +65,16 @@ TEST(Objdetect_face_detection, regression)
{
// Pre-set params
float scoreThreshold = 0.7f;
float matchThreshold = 0.9f;
float l2disThreshold = 5.0f;
float matchThreshold = 0.7f;
float l2disThreshold = 15.0f;
int numLM = 5;
int numCoords = 4 + 2 * numLM;
// Load ground truth labels
std::map<std::string, Mat> gt = blobFromTXT(findDataFile("dnn_face/detection/cascades_labels.txt"), numCoords);
// for (auto item: gt)
// {
// std::cout << item.first << " " << item.second.size() << std::endl;
// }
// Initialize detector
std::string model = findDataFile("dnn/onnx/models/yunet-202202.onnx", false);
std::string model = findDataFile("dnn/onnx/models/yunet-202303.onnx", false);
Ptr<FaceDetectorYN> faceDetector = FaceDetectorYN::create(model, "", Size(300, 300));
faceDetector->setScoreThreshold(0.7f);
@@ -137,6 +133,7 @@ TEST(Objdetect_face_detection, regression)
lmMatched[lmIdx] = true;
}
}
break;
}
EXPECT_TRUE(boxMatched) << "In image " << item.first << ", cannot match resBox " << resBox << " with any ground truth.";
if (boxMatched)
@@ -178,7 +175,7 @@ TEST(Objdetect_face_recognition, regression)
}
// Initialize detector
std::string detect_model = findDataFile("dnn/onnx/models/yunet-202202.onnx", false);
std::string detect_model = findDataFile("dnn/onnx/models/yunet-202303.onnx", false);
Ptr<FaceDetectorYN> faceDetector = FaceDetectorYN::create(detect_model, "", Size(150, 150), score_thresh, nms_thresh);
std::string recog_model = findDataFile("dnn/onnx/models/face_recognizer_fast.onnx", false);
+32
View File
@@ -708,6 +708,38 @@ TEST(Objdetect_QRCode_detect, detect_regression_21287)
#endif
}
TEST(Objdetect_QRCode_detect_flipped, regression_23249)
{
const std::vector<std::pair<std::string, std::string>> flipped_images =
// image name , expected result
{{"flipped_1.png", "The key is /qrcod_OMevpf"},
{"flipped_2.png", "A26"}};
const std::string root = "qrcode/flipped/";
for(const auto &flipped_image : flipped_images){
const std::string &image_name = flipped_image.first;
const std::string &expect_msg = flipped_image.second;
std::string image_path = findDataFile(root + image_name);
Mat src = imread(image_path);
ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
QRCodeDetector qrcode;
std::vector<Point> corners;
Mat straight_barcode;
cv::String decoded_info;
EXPECT_TRUE(qrcode.detect(src, corners));
EXPECT_TRUE(!corners.empty());
std::string decoded_msg;
#ifdef HAVE_QUIRC
EXPECT_NO_THROW(decoded_msg = qrcode.decode(src, corners, straight_barcode));
ASSERT_FALSE(straight_barcode.empty()) << "Can't decode qrimage.";
EXPECT_EQ(expect_msg, decoded_msg);
#endif
}
}
// @author Kumataro, https://github.com/Kumataro
TEST(Objdetect_QRCode_decode, decode_regression_21929)
{
@@ -450,6 +450,32 @@ TEST(Objdetect_QRCode_Encode_Decode_Structured_Append, DISABLED_regression)
#endif // UPDATE_QRCODE_TEST_DATA
CV_ENUM(EncodeModes, QRCodeEncoder::EncodeMode::MODE_NUMERIC,
QRCodeEncoder::EncodeMode::MODE_ALPHANUMERIC,
QRCodeEncoder::EncodeMode::MODE_BYTE)
typedef ::testing::TestWithParam<EncodeModes> Objdetect_QRCode_Encode_Decode_Structured_Append_Parameterized;
TEST_P(Objdetect_QRCode_Encode_Decode_Structured_Append_Parameterized, regression_22205)
{
const std::string input_data = "the quick brown fox jumps over the lazy dog";
std::vector<cv::Mat> result_qrcodes;
cv::QRCodeEncoder::Params params;
int encode_mode = GetParam();
params.mode = static_cast<cv::QRCodeEncoder::EncodeMode>(encode_mode);
for(size_t struct_num = 2; struct_num < 5; ++struct_num)
{
params.structure_number = static_cast<int>(struct_num);
cv::Ptr<cv::QRCodeEncoder> encoder = cv::QRCodeEncoder::create(params);
encoder->encodeStructuredAppend(input_data, result_qrcodes);
EXPECT_EQ(result_qrcodes.size(), struct_num) << "The number of QR Codes requested is not equal"<<
"to the one returned";
}
}
INSTANTIATE_TEST_CASE_P(/**/, Objdetect_QRCode_Encode_Decode_Structured_Append_Parameterized, EncodeModes::all());
TEST(Objdetect_QRCode_Encode_Decode, regression_issue22029)
{
const cv::String msg = "OpenCV";