1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-31 00:03:03 +04:00

Merge branch 4.x

This commit is contained in:
Alexander Smorkalov
2023-09-11 13:22:22 +03:00
148 changed files with 2384 additions and 1876 deletions
+62
View File
@@ -41,6 +41,7 @@
//M*/
#include "test_precomp.hpp"
#include "opencv2/core/utils/logger.hpp"
namespace opencv_test { namespace {
@@ -2259,4 +2260,65 @@ TEST(Calib3d_SolvePnP, inputShape)
}
}
bool hasNan(const cv::Mat& mat)
{
bool has = false;
if (mat.type() == CV_32F)
{
for(int i = 0; i < static_cast<int>(mat.total()); i++)
has |= cvIsNaN(mat.at<float>(i)) != 0;
}
else if (mat.type() == CV_64F)
{
for(int i = 0; i < static_cast<int>(mat.total()); i++)
has |= cvIsNaN(mat.at<double>(i)) != 0;
}
else
{
has = true;
CV_LOG_ERROR(NULL, "check hasNan called with unsupported type!");
}
return has;
}
TEST(AP3P, ctheta1p_nan_23607)
{
// the task is not well defined and may not converge (empty R, t) or should
// converge to some non-NaN solution
const std::array<cv::Point2d, 3> cameraPts = {
cv::Point2d{0.042784865945577621, 0.59844839572906494},
cv::Point2d{-0.028428621590137482, 0.60354739427566528},
cv::Point2d{0.0046037044376134872, 0.70674681663513184}
};
const std::array<cv::Point3d, 3> modelPts = {
cv::Point3d{-0.043258000165224075, 0.020459245890378952, -0.0069921980611979961},
cv::Point3d{-0.045648999512195587, 0.0029820732306689024, 0.0079000638797879219},
cv::Point3d{-0.043276999145746231, -0.013622495345771313, 0.0080113131552934647}
};
std::vector<Mat> R, t;
solveP3P(modelPts, cameraPts, Mat::eye(3, 3, CV_64F), Mat(), R, t, SOLVEPNP_AP3P);
EXPECT_EQ(R.size(), 2ul);
EXPECT_EQ(t.size(), 2ul);
// Try apply rvec and tvec to get model points from camera points.
Mat pts = Mat(modelPts).reshape(1, 3);
Mat expected = Mat(cameraPts).reshape(1, 3);
for (size_t i = 0; i < R.size(); ++i) {
EXPECT_TRUE(!hasNan(R[i]));
EXPECT_TRUE(!hasNan(t[i]));
Mat transform;
cv::Rodrigues(R[i], transform);
Mat res = pts * transform.t();
for (int j = 0; j < 3; ++j) {
res.row(j) += t[i].reshape(1, 1);
res.row(j) /= res.row(j).at<double>(2);
}
EXPECT_LE(cvtest::norm(res.colRange(0, 2), expected, NORM_INF), 3e-16);
}
}
}} // namespace