Skip to content

Commit

Permalink
[camera] use createPinhole and createEquidistant whenever possible
Browse files Browse the repository at this point in the history
  • Loading branch information
mugulmd committed Aug 24, 2023
1 parent 0b808e4 commit c59dc94
Show file tree
Hide file tree
Showing 9 changed files with 132 additions and 79 deletions.
104 changes: 59 additions & 45 deletions src/aliceVision/calibration/distortioncalibration_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ using namespace aliceVision;
// Checks that these points are close to the original points
//-----------------
BOOST_AUTO_TEST_CASE(distortionCalibration_calibrate_classicld)
{
const camera::Pinhole3DEClassicLD cam(1000, 1000, 1000, 1000, 0, 0,
-0.34768564335290314, 1.5809150001711287,
-0.17204522667665839, -0.15541950225726325,
1.1240093674337683);
{
std::shared_ptr<camera::Pinhole> cam =
camera::createPinhole(camera::EINTRINSICS::PINHOLE_CAMERA_3DECLASSICLD,
1000, 1000, 1000, 1000, 0, 0,
{-0.34768564335290314, 1.5809150001711287,
-0.17204522667665839, -0.15541950225726325,
1.1240093674337683});

// Create points
std::vector<calibration::PointPair> pts;
Expand All @@ -45,9 +47,9 @@ BOOST_AUTO_TEST_CASE(distortionCalibration_calibrate_classicld)
for (int j = 0; j < 1000; j+=10)
{
const Vec2 pt(j, i);
const Vec2 cpt = cam.ima2cam(pt);
const Vec2 upt = cam.addDistortion(cpt);
const Vec2 distortedPoint = cam.cam2ima(upt);
const Vec2 cpt = cam->ima2cam(pt);
const Vec2 upt = cam->addDistortion(cpt);
const Vec2 distortedPoint = cam->cam2ima(upt);

calibration::PointPair pp;
pp.distortedPoint = distortedPoint;
Expand All @@ -60,10 +62,11 @@ BOOST_AUTO_TEST_CASE(distortionCalibration_calibrate_classicld)
// Calibrate
calibration::Statistics st;
std::shared_ptr<camera::Pinhole> estimatedCam =
std::make_shared<camera::Pinhole3DEClassicLD>(1000, 1000, 1000, 1000, 0, 0,
0, boost::math::constants::pi<double>() * .5,
0, 0,
0);
camera::createPinhole(camera::EINTRINSICS::PINHOLE_CAMERA_3DECLASSICLD,
1000, 1000, 1000, 1000, 0, 0,
{0, boost::math::constants::pi<double>() * .5,
0, 0,
0});

std::vector<bool> lockedDistortions = {false, false, false, false, false};
BOOST_CHECK(calibration::estimate(estimatedCam, st, pts, true, false, lockedDistortions));
Expand All @@ -90,10 +93,12 @@ BOOST_AUTO_TEST_CASE(distortionCalibration_calibrate_classicld)
//-----------------
BOOST_AUTO_TEST_CASE(distortionCalibration_calibrate_radial4)
{
const camera::Pinhole3DERadial4 cam(1000, 1000, 1000, 1000, 0, 0,
-0.4839495643487452, 1.0301284234642258,
0.014928332802185664, -0.0007797104872758904,
-0.038994206396183909, 8.0474385001183646e-05);
std::shared_ptr<camera::Pinhole> cam =
camera::createPinhole(camera::EINTRINSICS::PINHOLE_CAMERA_3DERADIAL4,
1000, 1000, 1000, 1000, 0, 0,
{-0.4839495643487452, 1.0301284234642258,
0.014928332802185664, -0.0007797104872758904,
-0.038994206396183909, 8.0474385001183646e-05});

// Create points
std::vector<calibration::PointPair> pts;
Expand All @@ -102,9 +107,9 @@ BOOST_AUTO_TEST_CASE(distortionCalibration_calibrate_radial4)
for (int j = 0; j < 1000; j+=10)
{
const Vec2 pt(j, i);
const Vec2 cpt = cam.ima2cam(pt);
const Vec2 upt = cam.addDistortion(cpt);
const Vec2 distortedPoint = cam.cam2ima(upt);
const Vec2 cpt = cam->ima2cam(pt);
const Vec2 upt = cam->addDistortion(cpt);
const Vec2 distortedPoint = cam->cam2ima(upt);

calibration::PointPair pp;
pp.distortedPoint = distortedPoint;
Expand All @@ -117,7 +122,9 @@ BOOST_AUTO_TEST_CASE(distortionCalibration_calibrate_radial4)
// Calibrate
calibration::Statistics st;
std::shared_ptr<camera::Pinhole> estimatedCam =
std::make_shared<camera::Pinhole3DERadial4>(1000, 1000, 1000, 1000, 0, 0, 0, 0, 0, 0, 0);
camera::createPinhole(camera::EINTRINSICS::PINHOLE_CAMERA_3DERADIAL4,
1000, 1000, 1000, 1000, 0, 0,
{0, 0, 0, 0, 0, 0});

std::vector<bool> lockedDistortions = {false, false, false, false, false, false};
BOOST_CHECK(calibration::estimate(estimatedCam, st, pts, true, false, lockedDistortions));
Expand Down Expand Up @@ -146,10 +153,12 @@ BOOST_AUTO_TEST_CASE(distortionCalibration_calibrate_radial4)
//-----------------
BOOST_AUTO_TEST_CASE(distortionCalibration_calibrate_lines_classicld)
{
const camera::Pinhole3DEClassicLD cam(1000, 1000, 1000, 1000, 0, 0,
-0.34768564335290314, 1.5809150001711287,
-0.17204522667665839, -0.15541950225726325,
1.1240093674337683);
std::shared_ptr<camera::Pinhole> cam =
camera::createPinhole(camera::EINTRINSICS::PINHOLE_CAMERA_3DECLASSICLD,
1000, 1000, 1000, 1000, 0, 0,
{-0.34768564335290314, 1.5809150001711287,
-0.17204522667665839, -0.15541950225726325,
1.1240093674337683});

// Create points
std::vector<calibration::PointPair> pts;
Expand All @@ -164,9 +173,9 @@ BOOST_AUTO_TEST_CASE(distortionCalibration_calibrate_lines_classicld)
for (int j = 0; j < 1000; j+=10)
{
const Vec2 pt(j, i);
const Vec2 cpt = cam.ima2cam(pt);
const Vec2 upt = cam.removeDistortion(cpt);
const Vec2 distortedPoint = cam.cam2ima(upt);
const Vec2 cpt = cam->ima2cam(pt);
const Vec2 upt = cam->removeDistortion(cpt);
const Vec2 distortedPoint = cam->cam2ima(upt);

calibration::PointPair pp;
pp.distortedPoint = distortedPoint;
Expand All @@ -189,9 +198,9 @@ BOOST_AUTO_TEST_CASE(distortionCalibration_calibrate_lines_classicld)
for (int i = 0; i < 1000; i+=10)
{
const Vec2 pt(j, i);
const Vec2 cpt = cam.ima2cam(pt);
const Vec2 upt = cam.removeDistortion(cpt);
const Vec2 distortedPoint = cam.cam2ima(upt);
const Vec2 cpt = cam->ima2cam(pt);
const Vec2 upt = cam->removeDistortion(cpt);
const Vec2 distortedPoint = cam->cam2ima(upt);

line.points.push_back(distortedPoint);
}
Expand All @@ -203,10 +212,11 @@ BOOST_AUTO_TEST_CASE(distortionCalibration_calibrate_lines_classicld)
// Calibrate
calibration::Statistics st;
std::shared_ptr<camera::Pinhole> estimatedCam =
std::make_shared<camera::Pinhole3DEClassicLD>(1000, 1000, 1000, 1000, 0, 0,
0, boost::math::constants::pi<double>() * .5,
0, 0,
0);
camera::createPinhole(camera::EINTRINSICS::PINHOLE_CAMERA_3DECLASSICLD,
1000, 1000, 1000, 1000, 0, 0,
{0, boost::math::constants::pi<double>() * .5,
0, 0,
0});

{
std::vector<bool> lockedDistortions = {true, true, true, true, true};
Expand Down Expand Up @@ -244,10 +254,12 @@ BOOST_AUTO_TEST_CASE(distortionCalibration_calibrate_lines_classicld)
//-----------------
BOOST_AUTO_TEST_CASE(distortionCalibration_calibrate_lines_radial4)
{
const camera::Pinhole3DERadial4 cam(1000, 1000, 1000, 1000, 0, 0,
-0.4839495643487452, 1.0301284234642258,
0.014928332802185664, -0.0007797104872758904,
-0.038994206396183909, 8.0474385001183646e-05);
std::shared_ptr<camera::Pinhole> cam =
camera::createPinhole(camera::EINTRINSICS::PINHOLE_CAMERA_3DERADIAL4,
1000, 1000, 1000, 1000, 0, 0,
{-0.4839495643487452, 1.0301284234642258,
0.014928332802185664, -0.0007797104872758904,
-0.038994206396183909, 8.0474385001183646e-05});

// Create points
std::vector<calibration::PointPair> pts;
Expand All @@ -262,9 +274,9 @@ BOOST_AUTO_TEST_CASE(distortionCalibration_calibrate_lines_radial4)
for (int j = 0; j < 1000; j+=10)
{
const Vec2 pt(j, i);
const Vec2 cpt = cam.ima2cam(pt);
const Vec2 upt = cam.removeDistortion(cpt);
const Vec2 distortedPoint = cam.cam2ima(upt);
const Vec2 cpt = cam->ima2cam(pt);
const Vec2 upt = cam->removeDistortion(cpt);
const Vec2 distortedPoint = cam->cam2ima(upt);

calibration::PointPair pp;
pp.distortedPoint = distortedPoint;
Expand All @@ -287,9 +299,9 @@ BOOST_AUTO_TEST_CASE(distortionCalibration_calibrate_lines_radial4)
for (int i = 0; i < 1000; i+=10)
{
const Vec2 pt(j, i);
const Vec2 cpt = cam.ima2cam(pt);
const Vec2 upt = cam.removeDistortion(cpt);
const Vec2 distortedPoint = cam.cam2ima(upt);
const Vec2 cpt = cam->ima2cam(pt);
const Vec2 upt = cam->removeDistortion(cpt);
const Vec2 distortedPoint = cam->cam2ima(upt);

line.points.push_back(distortedPoint);
}
Expand All @@ -301,7 +313,9 @@ BOOST_AUTO_TEST_CASE(distortionCalibration_calibrate_lines_radial4)
// Calibrate
calibration::Statistics st;
std::shared_ptr<camera::Pinhole> estimatedCam =
std::make_shared<camera::Pinhole3DERadial4>(1000, 1000, 1000, 1000, 0, 0, 0, 0, 0, 0, 0, 0);
camera::createPinhole(camera::EINTRINSICS::PINHOLE_CAMERA_3DERADIAL4,
1000, 1000, 1000, 1000, 0, 0,
{0, 0, 0, 0, 0, 0});

{
std::vector<bool> lockedDistortions = {true, true, true, true, true, true};
Expand Down
2 changes: 1 addition & 1 deletion src/aliceVision/localization/LocalizationResult.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ void LocalizationResult::save(const std::vector<LocalizationResult>& localizatio

//intrinsic
{
std::shared_ptr<camera::Pinhole> intrinsicPtr = std::make_shared<camera::Pinhole>();
std::shared_ptr<camera::Pinhole> intrinsicPtr = camera::createPinhole(camera::EINTRINSIC::PINHOLE_CAMERA);
*intrinsicPtr = lr._intrinsics;
sfmDataIO::saveIntrinsic("intrinsic", UndefinedIndexT, std::dynamic_pointer_cast<camera::IntrinsicBase>(intrinsicPtr), lrTree);
}
Expand Down
7 changes: 6 additions & 1 deletion src/aliceVision/localization/optimization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,12 @@ bool refineSequence(std::vector<LocalizationResult> & vec_localizationResult,
ALICEVISION_LOG_DEBUG("Optical distortion won't be considered");
// just add a simple pinhole camera with the same K as the input camera
Vec2 pp = currIntrinsics->getPrincipalPoint();
tinyScene.intrinsics[intrinsicID] = std::make_shared<camera::Pinhole>(currIntrinsics->w(), currIntrinsics->h(), currIntrinsics->getFocalLengthPixX(), currIntrinsics->getFocalLengthPixY(), pp(0), pp(1));
tinyScene.intrinsics[intrinsicID] =
camera::createPinhole(
camera::EINTRINSIC::PINHOLE_CAMERA,
currIntrinsics->w(), currIntrinsics->h(),
currIntrinsics->getFocalLengthPixX(), currIntrinsics->getFocalLengthPixY(),
pp(0), pp(1));
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@ BOOST_AUTO_TEST_CASE(SEQUENTIAL_SFM_Partially_Known_Intrinsics)
// The third one will have an invalid intrinsic (unknown focal length)
{
// Create the intrinsic with unknown focal length
sfmData2.intrinsics[1] = std::make_shared<camera::Pinhole>
(config._cx*2, config._cy*2, -1, -1, 0, 0);
sfmData2.intrinsics[1] = camera::createPinhole(
camera::EINTRINSIC::PINHOLE_CAMERA,
config._cx*2, config._cy*2, -1, -1, 0, 0);
// The 3rd view use this invalid intrinsic
sfmData2.views[2]->setIntrinsicId(1);
}
Expand Down
15 changes: 12 additions & 3 deletions src/aliceVision/sfmDataIO/alembicIO_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,18 @@ SfMData createTestScene(IndexT singleViewsCount,
{
if(i == 0)
{
sfm_data.intrinsics[0] = std::make_shared<camera::Pinhole>(1000, 1000, 36.0, 36.0, std::rand()%10000, std::rand()%10000);
sfm_data.intrinsics[0] =
camera::createPinhole(
camera::EINTRINSIC::PINHOLE_CAMERA,
1000, 1000, 36.0, 36.0, std::rand()%10000, std::rand()%10000);
}
}
else
{
sfm_data.intrinsics[i] = std::make_shared<camera::Pinhole>(1000, 1000, 36.0, 36.0, std::rand()%10000, std::rand()%10000);
sfm_data.intrinsics[i] =
camera::createPinhole(
camera::EINTRINSIC::PINHOLE_CAMERA,
1000, 1000, 36.0, 36.0, std::rand()%10000, std::rand()%10000);
}
}

Expand All @@ -85,7 +91,10 @@ SfMData createTestScene(IndexT singleViewsCount,
rig.setSubPose(subPoseId, RigSubPose(geometry::Pose3(r, c), ERigSubPoseStatus::ESTIMATED));
}

sfm_data.intrinsics[nbIntrinsics + subPoseId] = std::make_shared<camera::Pinhole>(1000, 1000, 36.0, 36.0, std::rand()%10000, std::rand()%10000);
sfm_data.intrinsics[nbIntrinsics + subPoseId] =
camera::createPinhole(
camera::EINTRINSIC::PINHOLE_CAMERA,
1000, 1000, 36.0, 36.0, std::rand()%10000, std::rand()%10000);

for(std::size_t pose = 0; pose < nbRigPoses; ++pose)
{
Expand Down
62 changes: 41 additions & 21 deletions src/aliceVision/sfmDataIO/colmap_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,38 +46,58 @@ BOOST_AUTO_TEST_CASE(colmap_convertIntrinsicsToColmapString)
BOOST_CHECK(intrTest.empty());
// add some compatible intrinsics
intrTest.emplace(10,
std::make_shared<camera::Pinhole>(1920, 1080, 1548.76, 1547.32, 992.36, 549.54));
camera::createPinhole(
camera::EINTRINSICS::PINHOLE_CAMERA,
1920, 1080, 1548.76, 1547.32, 992.36, 549.54));
intrTest.emplace(11,
std::make_shared<camera::Pinhole>(1920, 1080, 1548.76, 1547.32, 992.36, 549.54,
std::make_shared<camera::DistortionRadialK1>(-0.02078)));
camera::createPinhole(
camera::EINTRINSICS::PINHOLE_CAMERA_RADIAL1,
1920, 1080, 1548.76, 1547.32, 992.36, 549.54,
{-0.02078}));
intrTest.emplace(12,
std::make_shared<camera::Pinhole>(1920, 1080, 1548.76, 1547.32, 992.36, 549.54,
std::make_shared<camera::DistortionRadialK3>(-0.02078, 0.1705, -0.00714)));
camera::createPinhole(
camera::EINTRINSICS::PINHOLE_CAMERA_RADIAL3,
1920, 1080, 1548.76, 1547.32, 992.36, 549.54,
{-0.02078, 0.1705, -0.00714}));
intrTest.emplace(13,
std::make_shared<camera::Pinhole>(1920, 1080, 1548.76, 1547.32, 992.36, 549.54,
std::make_shared<camera::DistortionBrown>(-0.02078, 0.1705, -0.00714, 0.00134, -0.000542)));
camera::createPinhole(
camera::EINTRINSICS::PINHOLE_CAMERA_BROWN,
1920, 1080, 1548.76, 1547.32, 992.36, 549.54,
{-0.02078, 0.1705, -0.00714, 0.00134, -0.000542}));
intrTest.emplace(14,
std::make_shared<camera::Pinhole>(1920, 1080, 1548.76, 1547.32, 992.36, 549.54,
std::make_shared<camera::DistortionFisheye>(-0.02078, 0.1705, -0.00714, 0.00134)));
camera::createPinhole(
camera::EINTRINSICS::PINHOLE_CAMERA_FISHEYE,
1920, 1080, 1548.76, 1547.32, 992.36, 549.54,
{-0.02078, 0.1705, -0.00714, 0.00134}));
intrTest.emplace(15,
std::make_shared<camera::Pinhole>(1920, 1080, 1548.76, 1547.32, 992.36, 549.54,
std::make_shared<camera::DistortionFisheye1>(-0.000542)));
camera::createPinhole(
camera::EINTRINSICS::PINHOLE_CAMERA_FISHEYE1,
1920, 1080, 1548.76, 1547.32, 992.36, 549.54,
{-0.000542}));
// add some incompatible intrinsics
intrTest.emplace(20,
std::make_shared<camera::Pinhole>(1920, 1080, 0., 0., 0., 0.,
nullptr,
std::make_shared<camera::Undistortion3DEAnamorphic4>(1920, 1080)));
camera::createPinhole(
camera::EINTRINSICS::PINHOLE_CAMERA_3DEANAMORPHIC4,
1920, 1080, 0., 0., 0., 0.));
intrTest.emplace(21,
std::make_shared<camera::Pinhole>(1920, 1080, 1548.76, 1547.32, 992.36, 549.54,
std::make_shared<camera::Distortion3DEClassicLD>(-0.02078, 0.1705, -0.00714, 0.00134, -0.000542)));
camera::createPinhole(
camera::EINTRINSICS::PINHOLE_CAMERA_3DECLASSICLD,
1920, 1080, 1548.76, 1547.32, 992.36, 549.54,
{-0.02078, 0.1705, -0.00714, 0.00134, -0.000542}));
intrTest.emplace(22,
std::make_shared<camera::Pinhole>(1920, 1080, 1548.76, 1547.32, 992.36, 549.54,
std::make_shared<camera::Distortion3DERadial4>(-0.02078, 0.1705, -0.00714, 0.00134, -0.00714, 0.00134)));
camera::createPinhole(
camera::EINTRINSICS::PINHOLE_CAMERA_3DERADIAL4,
1920, 1080, 1548.76, 1547.32, 992.36, 549.54,
{-0.02078, 0.1705, -0.00714, 0.00134, -0.00714, 0.00134}));
intrTest.emplace(23,
std::make_shared<camera::Equidistant>(1920, 1080, 1548.76, 992.36, 549.54, -0.02078));
camera::createEquidistant(
camera::EINTRINSICS::EQUIDISTANT_CAMERA,
1920, 1080, 1548.76, 549.54, -0.02078));
intrTest.emplace(24,
std::make_shared<camera::Equidistant>(1920, 1080, 1548.76, 992.36, 549.54, -0.02078,
std::make_shared<camera::DistortionRadialK3PT>(0.1705, -0.00714, 0.00134)));
camera::createEquidistant(
camera::EINTRINSICS::EQUIDISTANT_CAMERA_RADIAL3,
1920, 1080, 1548.76, 549.54, -0.02078,
{0.1705, -0.00714, 0.00134}));

// reference for each intrinsic ID the relevant expected string
const std::map<IndexT, std::string> stringRef{
Expand Down
2 changes: 1 addition & 1 deletion src/aliceVision/sfmDataIO/gtIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ bool readGt(const std::string& rootPath, sfmData::SfMData& sfmData, bool useUID)
iter != vec_camfilenames.end(); ++iter, ++index)
{
geometry::Pose3 pose;
std::shared_ptr<camera::Pinhole> pinholeIntrinsic = std::make_shared<camera::Pinhole>();
std::shared_ptr<camera::Pinhole> pinholeIntrinsic = camera::createPinhole(camera::EINTRINSIC::PINHOLE_CAMERA);
bool loaded = fcnReadCamPtr((fs::path(sGTPath) / *iter).string(), *pinholeIntrinsic.get(), pose);
if (!loaded)
{
Expand Down
10 changes: 7 additions & 3 deletions src/aliceVision/sfmDataIO/sceneSample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,15 @@ void generateSampleScene(sfmData::SfMData & output)
const double offsetY = 16;
output.getIntrinsics().emplace(
0,
std::make_shared<camera::Pinhole>(w, h, focalLengthPixX, focalLengthPixY, offsetX, offsetY));
camera::createPinhole(
camera::EINTRINSIC::PINHOLE_CAMERA,
w, h, focalLengthPixX, focalLengthPixY, offsetX, offsetY));
output.getIntrinsics().emplace(
1,
std::make_shared<camera::Pinhole>(w, h, focalLengthPixX, focalLengthPixY, offsetX, offsetY,
std::make_shared<camera::DistortionRadialK3>(0.1, 0.05, -0.001)));
camera::createPinhole(
camera::EINTRINSIC::PINHOLE_CAMERA_RADIAL3,
w, h, focalLengthPixX, focalLengthPixY, offsetX, offsetY,
{0.1, 0.05, -0.001}));

// Generate poses on another cube
IndexT idpose = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/software/convert/main_importKnownPoses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ int aliceVision_main(int argc, char **argv)
std::shared_ptr<camera::Pinhole> camera = std::dynamic_pointer_cast<camera::Pinhole>(intrinsic);
if (camera == nullptr)
{
camera = std::make_shared<camera::Pinhole>();
camera = camera::createPinhole(camera::EINTRINSIC::PINHOLE_CAMERA);
camera->copyFrom(*intrinsic);
sfmData.getIntrinsics().at(view.getIntrinsicId()) = camera;
}
Expand All @@ -267,7 +267,7 @@ int aliceVision_main(int argc, char **argv)
std::shared_ptr<camera::Pinhole> camera = std::dynamic_pointer_cast<camera::Pinhole>(intrinsic);
if (camera == nullptr)
{
camera = std::make_shared<camera::Pinhole>();
camera = camera::createPinhole(camera::EINTRINSIC::PINHOLE_CAMERA);
camera->copyFrom(*intrinsic);
sfmData.getIntrinsics().at(view.getIntrinsicId()) = camera;
}
Expand Down

0 comments on commit c59dc94

Please sign in to comment.