Skip to content

Commit 00cc4aa

Browse files
committed
calib3d: fix fisheye stereoRectify test
- don't write into testdata directory - check matrices instead of result images
1 parent 7c0193b commit 00cc4aa

File tree

1 file changed

+76
-32
lines changed

1 file changed

+76
-32
lines changed

modules/calib3d/test/test_fisheye.cpp

Lines changed: 76 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class fisheyeTest : public ::testing::Test {
6060

6161
protected:
6262
std::string combine(const std::string& _item1, const std::string& _item2);
63-
cv::Mat mergeRectification(const cv::Mat& l, const cv::Mat& r);
63+
static void merge4(const cv::Mat& tl, const cv::Mat& tr, const cv::Mat& bl, const cv::Mat& br, cv::Mat& merged);
6464
};
6565

6666
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -385,11 +385,7 @@ TEST_F(fisheyeTest, EstimateUncertainties)
385385
CV_Assert(errors.alpha == 0);
386386
}
387387

388-
#ifdef HAVE_TEGRA_OPTIMIZATION
389-
TEST_F(fisheyeTest, DISABLED_rectify)
390-
#else
391-
TEST_F(fisheyeTest, rectify)
392-
#endif
388+
TEST_F(fisheyeTest, stereoRectify)
393389
{
394390
const std::string folder =combine(datasets_repository_path, "calib-3_stereo_from_JY");
395391

@@ -405,20 +401,65 @@ TEST_F(fisheyeTest, rectify)
405401
cv::fisheye::stereoRectify(K1, D1, K2, D2, calibration_size, theR, theT, R1, R2, P1, P2, Q,
406402
cv::CALIB_ZERO_DISPARITY, requested_size, balance, fov_scale);
407403

404+
// Collected with these CMake flags: -DWITH_IPP=OFF -DCMAKE_BUILD_TYPE=Debug
405+
cv::Matx33d R1_ref(
406+
0.9992853269091279, 0.03779164101000276, -0.0007920188690205426,
407+
-0.03778569762983931, 0.9992646472015868, 0.006511981857667881,
408+
0.001037534936357442, -0.006477400933964018, 0.9999784831677112
409+
);
410+
cv::Matx33d R2_ref(
411+
0.9994868963898833, -0.03197579751378937, -0.001868774538573449,
412+
0.03196298186616116, 0.9994677442608699, -0.0065265589947392,
413+
0.002076471801477729, 0.006463478587068991, 0.9999769555891836
414+
);
415+
cv::Matx34d P1_ref(
416+
420.8551870450913, 0, 586.501617798451, 0,
417+
0, 420.8551870450913, 374.7667511986098, 0,
418+
0, 0, 1, 0
419+
);
420+
cv::Matx34d P2_ref(
421+
420.8551870450913, 0, 586.501617798451, -41.77758076597302,
422+
0, 420.8551870450913, 374.7667511986098, 0,
423+
0, 0, 1, 0
424+
);
425+
cv::Matx44d Q_ref(
426+
1, 0, 0, -586.501617798451,
427+
0, 1, 0, -374.7667511986098,
428+
0, 0, 0, 420.8551870450913,
429+
0, 0, 10.07370889670733, -0
430+
);
431+
432+
const double eps = 1e-10;
433+
EXPECT_MAT_NEAR(R1_ref, R1, eps);
434+
EXPECT_MAT_NEAR(R2_ref, R2, eps);
435+
EXPECT_MAT_NEAR(P1_ref, P1, eps);
436+
EXPECT_MAT_NEAR(P2_ref, P2, eps);
437+
EXPECT_MAT_NEAR(Q_ref, Q, eps);
438+
439+
if (::testing::Test::HasFailure())
440+
{
441+
std::cout << "Actual values are:" << std::endl
442+
<< "R1 =" << std::endl << R1 << std::endl
443+
<< "R2 =" << std::endl << R2 << std::endl
444+
<< "P1 =" << std::endl << P1 << std::endl
445+
<< "P2 =" << std::endl << P2 << std::endl
446+
<< "Q =" << std::endl << Q << std::endl;
447+
}
448+
449+
#if 1 // Debug code
408450
cv::Mat lmapx, lmapy, rmapx, rmapy;
409451
//rewrite for fisheye
410452
cv::fisheye::initUndistortRectifyMap(K1, D1, R1, P1, requested_size, CV_32F, lmapx, lmapy);
411453
cv::fisheye::initUndistortRectifyMap(K2, D2, R2, P2, requested_size, CV_32F, rmapx, rmapy);
412454

413455
cv::Mat l, r, lundist, rundist;
414-
cv::VideoCapture lcap(combine(folder, "left/stereo_pair_%03d.jpg")),
415-
rcap(combine(folder, "right/stereo_pair_%03d.jpg"));
416-
417-
for(int i = 0;; ++i)
456+
for (int i = 0; i < 34; ++i)
418457
{
419-
lcap >> l; rcap >> r;
420-
if (l.empty() || r.empty())
421-
break;
458+
SCOPED_TRACE(cv::format("image %d", i));
459+
l = imread(combine(folder, cv::format("left/stereo_pair_%03d.jpg", i)), cv::IMREAD_COLOR);
460+
r = imread(combine(folder, cv::format("right/stereo_pair_%03d.jpg", i)), cv::IMREAD_COLOR);
461+
ASSERT_FALSE(l.empty());
462+
ASSERT_FALSE(r.empty());
422463

423464
int ndisp = 128;
424465
cv::rectangle(l, cv::Rect(255, 0, 829, l.rows-1), CV_RGB(255, 0, 0));
@@ -427,15 +468,18 @@ TEST_F(fisheyeTest, rectify)
427468
cv::remap(l, lundist, lmapx, lmapy, cv::INTER_LINEAR);
428469
cv::remap(r, rundist, rmapx, rmapy, cv::INTER_LINEAR);
429470

430-
cv::Mat rectification = mergeRectification(lundist, rundist);
471+
for (int ii = 0; ii < lundist.rows; ii += 20)
472+
{
473+
cv::line(lundist, cv::Point(0, ii), cv::Point(lundist.cols, ii), cv::Scalar(0, 255, 0));
474+
cv::line(rundist, cv::Point(0, ii), cv::Point(lundist.cols, ii), cv::Scalar(0, 255, 0));
475+
}
431476

432-
cv::Mat correct = cv::imread(combine(datasets_repository_path, cv::format("rectification_AB_%03d.png", i)));
477+
cv::Mat rectification;
478+
merge4(l, r, lundist, rundist, rectification);
433479

434-
if (correct.empty())
435-
cv::imwrite(combine(datasets_repository_path, cv::format("rectification_AB_%03d.png", i)), rectification);
436-
else
437-
EXPECT_MAT_NEAR(correct, rectification, 1e-10);
438-
}
480+
cv::imwrite(cv::format("fisheye_rectification_AB_%03d.png", i), rectification);
481+
}
482+
#endif
439483
}
440484

441485
TEST_F(fisheyeTest, stereoCalibrate)
@@ -601,17 +645,17 @@ std::string fisheyeTest::combine(const std::string& _item1, const std::string& _
601645
return item1 + (last != '/' ? "/" : "") + item2;
602646
}
603647

604-
cv::Mat fisheyeTest::mergeRectification(const cv::Mat& l, const cv::Mat& r)
648+
void fisheyeTest::merge4(const cv::Mat& tl, const cv::Mat& tr, const cv::Mat& bl, const cv::Mat& br, cv::Mat& merged)
605649
{
606-
CV_Assert(l.type() == r.type() && l.size() == r.size());
607-
cv::Mat merged(l.rows, l.cols * 2, l.type());
608-
cv::Mat lpart = merged.colRange(0, l.cols);
609-
cv::Mat rpart = merged.colRange(l.cols, merged.cols);
610-
l.copyTo(lpart);
611-
r.copyTo(rpart);
612-
613-
for(int i = 0; i < l.rows; i+=20)
614-
cv::line(merged, cv::Point(0, i), cv::Point(merged.cols, i), CV_RGB(0, 255, 0));
615-
616-
return merged;
650+
int type = tl.type();
651+
cv::Size sz = tl.size();
652+
ASSERT_EQ(type, tr.type()); ASSERT_EQ(type, bl.type()); ASSERT_EQ(type, br.type());
653+
ASSERT_EQ(sz.width, tr.cols); ASSERT_EQ(sz.width, bl.cols); ASSERT_EQ(sz.width, br.cols);
654+
ASSERT_EQ(sz.height, tr.rows); ASSERT_EQ(sz.height, bl.rows); ASSERT_EQ(sz.height, br.rows);
655+
656+
merged.create(cv::Size(sz.width * 2, sz.height * 2), type);
657+
tl.copyTo(merged(cv::Rect(0, 0, sz.width, sz.height)));
658+
tr.copyTo(merged(cv::Rect(sz.width, 0, sz.width, sz.height)));
659+
bl.copyTo(merged(cv::Rect(0, sz.height, sz.width, sz.height)));
660+
bl.copyTo(merged(cv::Rect(sz.width, sz.height, sz.width, sz.height)));
617661
}

0 commit comments

Comments
 (0)