Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc87d30f

Browse files
author
thezane
committed
Add new unit tests
1 parente2cf41a commitc87d30f

File tree

2 files changed

+236
-4
lines changed

2 files changed

+236
-4
lines changed

‎modules/calib3d/test/test_cameracalibration.cpp‎

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,177 @@ void CV_CameraCalibrationTest_CPP::project( const std::vector<Point3d>& objectPo
816816
}*/
817817
}
818818

819+
// --------------------------------- CV_CameraCalibrationFixedExtrinsicsTest_CPP --------------------------------------------
820+
821+
classCV_CameraCalibrationFixedExtrinsicsTest_CPP :publicCV_CameraCalibrationTest
822+
{
823+
public:
824+
CV_CameraCalibrationFixedExtrinsicsTest_CPP(constbool _useRodrigues=false );
825+
protected:
826+
virtualvoidcalibrate(const FixtureParams &fp, CalibratedParams &cp );
827+
828+
virtualintcheckCalibration(const FixtureParams &fp, CalibratedParams &cp );
829+
830+
/* Whether rotation matrices should be passed in as Rodrigues vectors*/
831+
constbool useRodrigues;
832+
};
833+
834+
CV_CameraCalibrationFixedExtrinsicsTest_CPP::CV_CameraCalibrationFixedExtrinsicsTest_CPP(constbool _useRodrigues )
835+
: useRodrigues( _useRodrigues )
836+
{
837+
}
838+
839+
voidCV_CameraCalibrationFixedExtrinsicsTest_CPP::calibrate(const FixtureParams &fp, CalibratedParams &cp )
840+
{
841+
vector<vector<Point3f> >objectPoints( fp.numImages );
842+
vector<vector<Point2f> >imagePoints( fp.numImages );
843+
std::vector<Mat> rvecs, tvecs;
844+
Mat newObjMat;
845+
Mat stdDevsMatInt, stdDevsMatExt;
846+
Mat stdDevsMatObj;
847+
848+
for(int i =0; i < fp.numImages; i++ )
849+
{
850+
Mat( fp.imagePoints[i]).convertTo(imagePoints[i], CV_32F );
851+
Mat( fp.objectPoints[i]).convertTo(objectPoints[i], CV_32F );
852+
}
853+
854+
CV_Assert( (size_t)fp.numImages == fp.goodRotMatrs.size() );
855+
CV_Assert( (size_t)fp.numImages == fp.goodTransVects.size() );
856+
857+
for (int i =0; i < fp.numImages; i++ )
858+
{
859+
Mat rMat =Mat( fp.goodRotMatrs[i] );
860+
861+
if ( useRodrigues )
862+
{
863+
rvecs.emplace_back();
864+
cvtest::Rodrigues( rMat.t(), rvecs.back() );
865+
}
866+
else
867+
{
868+
rvecs.emplace_back( rMat.t() );
869+
}
870+
871+
tvecs.emplace_back(Mat( fp.goodTransVects[i] ) );
872+
}
873+
874+
calibrateCameraRO( objectPoints,
875+
imagePoints,
876+
fp.imageSize,
877+
fp.iFixedPoint,
878+
cp.cameraMatrix,
879+
cp.distortion,
880+
rvecs,
881+
tvecs,
882+
newObjMat,
883+
stdDevsMatInt,
884+
stdDevsMatExt,
885+
stdDevsMatObj,
886+
cp.perViewErrors,
887+
fp.flags | CALIB_FIX_EXTRINSIC );
888+
889+
for (int i =0; i < fp.numImages; i++ )
890+
{
891+
if ( useRodrigues )
892+
{
893+
Mat rMat;
894+
cvtest::Rodrigues( rvecs[i], rMat );
895+
cv::transpose( rMat, rMat );
896+
cp.rotMatrs.emplace_back();
897+
rMat.convertTo( cp.rotMatrs[i], CV_64F );
898+
}
899+
else
900+
{
901+
RotMat rMat =Mat( rvecs[i].t() );
902+
cp.rotMatrs.emplace_back( rMat );
903+
}
904+
905+
cp.transVects.emplace_back( tvecs[i] );
906+
}
907+
}
908+
909+
intCV_CameraCalibrationFixedExtrinsicsTest_CPP::checkCalibration(const FixtureParams &fp, CalibratedParams &cp)
910+
{
911+
int code = cvtest::TS::OK;
912+
913+
/* ========= Compare parameters =========*/
914+
CV_Assert(cp.cameraMatrix.type() == CV_64F && cp.cameraMatrix.size() ==Size(3,3));
915+
CV_Assert(cp.distortion.type() == CV_64F);
916+
917+
Size dsz = cp.distortion.size();
918+
CV_Assert(dsz ==Size(4,1) || dsz ==Size(1,4) || dsz ==Size(5,1) || dsz ==Size(1,5));
919+
920+
/* ----- Compare focal lengths -----*/
921+
code =compare(&cp.cameraMatrix.at<double>(0,0), &fp.goodFcx,1,0.1,"fx");
922+
if( code <0 )
923+
return code;
924+
925+
code =compare(&cp.cameraMatrix.at<double>(1,1), &fp.goodFcy,1,0.1,"fy");
926+
if( code <0 )
927+
return code;
928+
929+
/* ----- Compare principal points -----*/
930+
code =compare(&cp.cameraMatrix.at<double>(0,2), &fp.goodCx,1,0.1,"cx");
931+
if( code <0 )
932+
return code;
933+
934+
code =compare(&cp.cameraMatrix.at<double>(1,2), &fp.goodCy,1,0.1,"cy");
935+
if( code <0 )
936+
return code;
937+
938+
/* ----- Compare distortion -----*/
939+
code =compare(&cp.distortion.at<double>(0), &fp.goodDistortion.at<double>(0),4,0.1,"[k1,k2,p1,p2]");
940+
if( code <0 )
941+
return code;
942+
943+
/* ----- Check extrinsics are the same -----*/
944+
CV_Assert(cp.rotMatrs.size() == (size_t)fp.numImages);
945+
CV_Assert(cp.transVects.size() == (size_t)fp.numImages);
946+
947+
for(int i =0; i < fp.numImages; i++ )
948+
{
949+
RotMat goodRotMat;
950+
951+
if ( useRodrigues )
952+
{
953+
Mat rMat =Mat( fp.goodRotMatrs[i] );
954+
Mat rvec;
955+
cvtest::Rodrigues( rMat.t(), rvec );
956+
cvtest::Rodrigues( rvec, rMat );
957+
cv::transpose( rMat, rMat );
958+
rMat.convertTo( goodRotMat, CV_64F );
959+
}
960+
else
961+
{
962+
goodRotMat = fp.goodRotMatrs[i];
963+
}
964+
965+
if( cp.rotMatrs[i] != goodRotMat )
966+
{
967+
printf("rot mats for frame #%d are different\n", i);
968+
std::cout <<"curr:\n" << cp.rotMatrs[i] << std::endl;
969+
std::cout <<"good:\n" << goodRotMat << std::endl;
970+
971+
code = TS::FAIL_BAD_ACCURACY;
972+
break;
973+
}
974+
975+
if( cp.transVects[i] != fp.goodTransVects[i] )
976+
{
977+
printf("rot mats for frame #%d are different\n", i);
978+
std::cout <<"curr:\n" << cp.transVects[i] << std::endl;
979+
std::cout <<"good:\n" << fp.goodTransVects[i] << std::endl;
980+
981+
code = TS::FAIL_BAD_ACCURACY;
982+
break;
983+
}
984+
}
985+
if( code <0 )
986+
return code;
987+
988+
return code;
989+
}
819990

820991
//----------------------------------------- CV_CalibrationMatrixValuesTest --------------------------------
821992

@@ -1697,6 +1868,9 @@ void CV_StereoCalibrationTest_CPP::correct( const Mat& F,
16971868
///////////////////////////////////////////////////////////////////////////////////////////////////
16981869

16991870
TEST(Calib3d_CalibrateCamera_CPP, regression) { CV_CameraCalibrationTest_CPP test; test.safe_run(); }
1871+
TEST(Calib3d_CalibrateCamera_CPP, fixedExtrinsics) { CV_CameraCalibrationFixedExtrinsicsTest_CPP test; test.safe_run(); }
1872+
TEST(Calib3d_CalibrateCamera_CPP, fixedExtrinsicsRodrigues) {
1873+
CV_CameraCalibrationFixedExtrinsicsTest_CPP test{true/* useRodrigues*/ }; test.safe_run(); }
17001874
TEST(Calib3d_CalibrationMatrixValues_CPP, accuracy) { CV_CalibrationMatrixValuesTest_CPP test; test.safe_run(); }
17011875
TEST(Calib3d_ProjectPoints_CPP, regression) { CV_ProjectPointsTest_CPP test; test.safe_run(); }
17021876

‎modules/calib3d/test/test_cameracalibration_badarg.cpp‎

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ void CV_CameraCalibrationBadArgTest::run( int /* start_from */ )
126126
Mat rvecs_cpp;
127127
Mat tvecs_cpp;
128128
Mat newObjPts_cpp;
129+
std::vector<Mat> badRvecs;
130+
std::vector<Mat> badTvecs;
129131

130132
std::vector<Point3f> objPts_cpp;
131133
for(int y =0; y < corSize.height; ++y)
@@ -140,8 +142,13 @@ void CV_CameraCalibrationBadArgTest::run( int /* start_from */ )
140142
}
141143
caller.cameraMatrix.create(3,3, CV_32F);
142144
caller.distCoeffs.create(5,1, CV_32F);
143-
caller.rvecs.clear();
144-
caller.tvecs.clear();
145+
caller.rvecs.resize(M);
146+
caller.tvecs.resize(M);
147+
for (int i =0; i < M; ++i)
148+
{
149+
caller.rvecs[i] =Mat::eye(3,3, CV_64F);
150+
caller.tvecs[i] =Mat::zeros(3,1, CV_64F);
151+
}
145152
caller.newObjPts.clear();
146153

147154
/* /*//*/*/
@@ -185,13 +192,64 @@ void CV_CameraCalibrationBadArgTest::run( int /* start_from */ )
185192
Mat badCM =Mat::zeros(4,4, CV_64F);
186193
caller.cameraMatrix_arg = badCM;
187194
caller.flags = CALIB_USE_INTRINSIC_GUESS;
188-
errors +=run_test_case(CV_StsBadArg,"Bad camearaMatrix header", caller );
195+
errors +=run_test_case(Error::StsBadArg,"Bad camearaMatrix header", caller );
189196

190197
caller.initArgs();
191198
Mat badDC =Mat::zeros(10,10, CV_64F);
192199
caller.distCoeffs_arg = badDC;
193200
caller.flags = CALIB_USE_INTRINSIC_GUESS;
194-
errors +=run_test_case( CV_StsBadArg,"Bad camearaMatrix header", caller );
201+
errors +=run_test_case( Error::StsBadArg,"Bad camearaMatrix header", caller );
202+
203+
caller.initArgs();
204+
caller.rvecs_arg =noArray();
205+
caller.flags = CALIB_FIX_EXTRINSIC;
206+
errors +=run_test_case( Error::StsBadArg,"None passed in rvecs", caller );
207+
208+
caller.initArgs();
209+
badRvecs = {Mat::eye(3,3, CV_64F)};
210+
caller.rvecs_arg = badRvecs;
211+
caller.flags = CALIB_FIX_EXTRINSIC;
212+
errors +=run_test_case( Error::StsBadArg,"Bad rvecs size", caller );
213+
214+
caller.initArgs();
215+
badRvecs = caller.rvecs;
216+
badRvecs[0] =Mat::eye(4,4, CV_64F);
217+
caller.rvecs_arg = badRvecs;
218+
caller.flags = CALIB_FIX_EXTRINSIC;
219+
errors +=run_test_case( Error::StsBadSize,"Bad rvecs[0]", caller );
220+
221+
caller.initArgs();
222+
badRvecs = caller.rvecs;
223+
badRvecs[1] =Mat::eye(4,4, CV_64F);
224+
caller.rvecs_arg = badRvecs;
225+
caller.flags = CALIB_FIX_EXTRINSIC;
226+
errors +=run_test_case( Error::StsBadSize,"Bad rvecs[1]", caller );
227+
228+
caller.initArgs();
229+
caller.tvecs_arg =noArray();
230+
caller.flags = CALIB_FIX_EXTRINSIC;
231+
errors +=run_test_case( Error::StsBadArg,"None passed in tvecs", caller );
232+
233+
caller.initArgs();
234+
badTvecs = {Mat::eye(3,1, CV_64F)};
235+
caller.tvecs_arg = badTvecs;
236+
caller.flags = CALIB_FIX_EXTRINSIC;
237+
errors +=run_test_case( Error::StsBadArg,"Bad tvecs size", caller );
238+
239+
caller.initArgs();
240+
badTvecs = caller.tvecs;
241+
badTvecs[0] =Mat::eye(4,1, CV_64F);
242+
caller.tvecs_arg = badTvecs;
243+
caller.flags = CALIB_FIX_EXTRINSIC;
244+
errors +=run_test_case( Error::StsBadSize,"Bad tvecs[0]", caller );
245+
246+
caller.initArgs();
247+
badTvecs = caller.tvecs;
248+
badTvecs[1] =Mat::eye(4,1, CV_64F);
249+
caller.tvecs_arg = badTvecs;
250+
caller.flags = CALIB_FIX_EXTRINSIC;
251+
errors +=run_test_case( Error::StsBadSize,"Bad tvecs[1]", caller );
252+
195253

196254
if (errors)
197255
ts->set_failed_test_info(cvtest::TS::FAIL_MISMATCH);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp