@@ -61,7 +61,7 @@ class fisheyeTest : public ::testing::Test {
61
61
62
62
protected:
63
63
std::string combine (const std::string& _item1, const std::string& _item2);
64
- cv::Mat mergeRectification ( const cv::Mat& l , const cv::Mat& r );
64
+ static void merge4 ( const cv::Mat& tl, const cv::Mat& tr , const cv::Mat& bl, const cv::Mat& br, cv::Mat& merged );
65
65
};
66
66
67
67
// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -386,12 +386,7 @@ TEST_F(fisheyeTest, EstimateUncertainties)
386
386
CV_Assert (errors.alpha == 0 );
387
387
}
388
388
389
- #ifdef HAVE_TEGRA_OPTIMIZATION
390
- // not passing accuracy constrains
391
- TEST_F (fisheyeTest, DISABLED_rectify)
392
- #else
393
- TEST_F (fisheyeTest, rectify)
394
- #endif
389
+ TEST_F (fisheyeTest, stereoRectify)
395
390
{
396
391
const std::string folder =combine (datasets_repository_path, " calib-3_stereo_from_JY" );
397
392
@@ -407,20 +402,65 @@ TEST_F(fisheyeTest, rectify)
407
402
cv::fisheye::stereoRectify (K1, D1, K2, D2, calibration_size, theR, theT, R1, R2, P1, P2, Q,
408
403
cv::CALIB_ZERO_DISPARITY, requested_size, balance, fov_scale);
409
404
405
+ // Collected with these CMake flags: -DWITH_IPP=OFF -DCV_ENABLE_INTRINSICS=OFF -DCV_DISABLE_OPTIMIZATION=ON -DCMAKE_BUILD_TYPE=Debug
406
+ cv::Matx33d R1_ref (
407
+ 0.9992853269091279 , 0.03779164101000276 , -0.0007920188690205426 ,
408
+ -0.03778569762983931 , 0.9992646472015868 , 0.006511981857667881 ,
409
+ 0.001037534936357442 , -0.006477400933964018 , 0.9999784831677112
410
+ );
411
+ cv::Matx33d R2_ref (
412
+ 0.9994868963898833 , -0.03197579751378937 , -0.001868774538573449 ,
413
+ 0.03196298186616116 , 0.9994677442608699 , -0.0065265589947392 ,
414
+ 0.002076471801477729 , 0.006463478587068991 , 0.9999769555891836
415
+ );
416
+ cv::Matx34d P1_ref (
417
+ 420.8551870450913 , 0 , 586.501617798451 , 0 ,
418
+ 0 , 420.8551870450913 , 374.7667511986098 , 0 ,
419
+ 0 , 0 , 1 , 0
420
+ );
421
+ cv::Matx34d P2_ref (
422
+ 420.8551870450913 , 0 , 586.501617798451 , -41.77758076597302 ,
423
+ 0 , 420.8551870450913 , 374.7667511986098 , 0 ,
424
+ 0 , 0 , 1 , 0
425
+ );
426
+ cv::Matx44d Q_ref (
427
+ 1 , 0 , 0 , -586.501617798451 ,
428
+ 0 , 1 , 0 , -374.7667511986098 ,
429
+ 0 , 0 , 0 , 420.8551870450913 ,
430
+ 0 , 0 , 10.07370889670733 , -0
431
+ );
432
+
433
+ const double eps = 1e-10 ;
434
+ EXPECT_MAT_NEAR (R1_ref, R1, eps);
435
+ EXPECT_MAT_NEAR (R2_ref, R2, eps);
436
+ EXPECT_MAT_NEAR (P1_ref, P1, eps);
437
+ EXPECT_MAT_NEAR (P2_ref, P2, eps);
438
+ EXPECT_MAT_NEAR (Q_ref, Q, eps);
439
+
440
+ if (::testing::Test::HasFailure ())
441
+ {
442
+ std::cout << " Actual values are:" << std::endl
443
+ << " R1 =" << std::endl << R1 << std::endl
444
+ << " R2 =" << std::endl << R2 << std::endl
445
+ << " P1 =" << std::endl << P1 << std::endl
446
+ << " P2 =" << std::endl << P2 << std::endl
447
+ << " Q =" << std::endl << Q << std::endl;
448
+ }
449
+
450
+ #if 1 // Debug code
410
451
cv::Mat lmapx, lmapy, rmapx, rmapy;
411
452
// rewrite for fisheye
412
453
cv::fisheye::initUndistortRectifyMap (K1, D1, R1, P1, requested_size, CV_32F, lmapx, lmapy);
413
454
cv::fisheye::initUndistortRectifyMap (K2, D2, R2, P2, requested_size, CV_32F, rmapx, rmapy);
414
455
415
456
cv::Mat l, r, lundist, rundist;
416
- cv::VideoCapture lcap (combine (folder, " left/stereo_pair_%03d.jpg" )),
417
- rcap (combine (folder, " right/stereo_pair_%03d.jpg" ));
418
-
419
- for (int i = 0 ;; ++i)
457
+ for (int i = 0 ; i < 34 ; ++i)
420
458
{
421
- lcap >> l; rcap >> r;
422
- if (l.empty () || r.empty ())
423
- break ;
459
+ SCOPED_TRACE (cv::format (" image %d" , i));
460
+ l = imread (combine (folder, cv::format (" left/stereo_pair_%03d.jpg" , i)), cv::IMREAD_COLOR);
461
+ r = imread (combine (folder, cv::format (" right/stereo_pair_%03d.jpg" , i)), cv::IMREAD_COLOR);
462
+ ASSERT_FALSE (l.empty ());
463
+ ASSERT_FALSE (r.empty ());
424
464
425
465
int ndisp = 128 ;
426
466
cv::rectangle (l, cv::Rect (255 , 0 , 829 , l.rows -1 ), cv::Scalar (0 , 0 , 255 ));
@@ -429,15 +469,18 @@ TEST_F(fisheyeTest, rectify)
429
469
cv::remap (l, lundist, lmapx, lmapy, cv::INTER_LINEAR);
430
470
cv::remap (r, rundist, rmapx, rmapy, cv::INTER_LINEAR);
431
471
432
- cv::Mat rectification = mergeRectification (lundist, rundist);
472
+ for (int ii = 0 ; ii < lundist.rows ; ii += 20 )
473
+ {
474
+ cv::line (lundist, cv::Point (0 , ii), cv::Point (lundist.cols , ii), cv::Scalar (0 , 255 , 0 ));
475
+ cv::line (rundist, cv::Point (0 , ii), cv::Point (lundist.cols , ii), cv::Scalar (0 , 255 , 0 ));
476
+ }
433
477
434
- cv::Mat correct = cv::imread (combine (datasets_repository_path, cv::format (" rectification_AB_%03d.png" , i)));
478
+ cv::Mat rectification;
479
+ merge4 (l, r, lundist, rundist, rectification);
435
480
436
- if (correct.empty ())
437
- cv::imwrite (combine (datasets_repository_path, cv::format (" rectification_AB_%03d.png" , i)), rectification);
438
- else
439
- EXPECT_MAT_NEAR (correct, rectification, 1e-10 );
481
+ cv::imwrite (cv::format (" fisheye_rectification_AB_%03d.png" , i), rectification);
440
482
}
483
+ #endif
441
484
}
442
485
443
486
TEST_F (fisheyeTest, stereoCalibrate)
@@ -644,17 +687,17 @@ std::string fisheyeTest::combine(const std::string& _item1, const std::string& _
644
687
return item1 + (last != ' /' ? " /" : " " ) + item2;
645
688
}
646
689
647
- cv::Mat fisheyeTest::mergeRectification ( const cv::Mat& l , const cv::Mat& r )
690
+ void fisheyeTest::merge4 ( const cv::Mat& tl, const cv::Mat& tr, const cv::Mat& bl , const cv::Mat& br, cv::Mat& merged )
648
691
{
649
- CV_Assert (l. type () == r .type () && l. size () == r. size () );
650
- cv::Mat merged (l. rows , l. cols * 2 , l. type () );
651
- cv::Mat lpart = merged. colRange ( 0 , l. cols );
652
- cv::Mat rpart = merged. colRange (l. cols , merged .cols );
653
- l. copyTo (lpart );
654
- r. copyTo (rpart);
655
-
656
- for ( int i = 0 ; i < l. rows ; i+= 20 )
657
- cv::line (merged, cv::Point ( 0 , i), cv::Point (merged. cols , i), cv::Scalar ( 0 , 255 , 0 ));
658
-
659
- return merged;
692
+ int type = tl .type ();
693
+ cv::Size sz = tl. size ( );
694
+ ASSERT_EQ (type, tr. type ()); ASSERT_EQ (type, bl. type ()); ASSERT_EQ (type, br. type () );
695
+ ASSERT_EQ (sz. width , tr. cols ); ASSERT_EQ (sz. width , bl. cols ); ASSERT_EQ (sz. width , br .cols );
696
+ ASSERT_EQ (sz. height , tr. rows ); ASSERT_EQ (sz. height , bl. rows ); ASSERT_EQ (sz. height , br. rows );
697
+
698
+ merged. create ( cv::Size (sz. width * 2 , sz. height * 2 ), type);
699
+ tl. copyTo ( merged ( cv::Rect ( 0 , 0 , sz. width , sz. height )));
700
+ tr. copyTo (merged ( cv::Rect (sz. width , 0 , sz. width , sz. height ) ));
701
+ bl. copyTo ( merged ( cv::Rect ( 0 , sz. height , sz. width , sz. height )));
702
+ br. copyTo ( merged ( cv::Rect (sz. width , sz. height , sz. width , sz. height ))) ;
660
703
}
0 commit comments