Skip to content

Commit

Permalink
Improvements to NVM, Cam, Recon3D, and Bundler exporters (colmap#1187)
Browse files Browse the repository at this point in the history
* Fixes to NVM/Cam/Recon3D/Bundler exporters

* Adhere to code style guide for conditional braces
  • Loading branch information
drkoller authored and lucasthahn committed Aug 17, 2022
1 parent 37ad6e6 commit b7f72fc
Showing 1 changed file with 39 additions and 20 deletions.
59 changes: 39 additions & 20 deletions src/base/reconstruction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -831,12 +831,15 @@ bool Reconstruction::ExportNVM(const std::string& path,
const class Camera& camera = Camera(image.CameraId());

double k;
if (skip_distortion) {
if (skip_distortion ||
camera.ModelId() == SimplePinholeCameraModel::model_id ||
camera.ModelId() == PinholeCameraModel::model_id) {
k = 0.0;
} else if (camera.ModelId() == SimpleRadialCameraModel::model_id) {
k = -1 * camera.Params(SimpleRadialCameraModel::extra_params_idxs[0]);
} else {
std::cout << "WARNING: NVM only supports `SIMPLE_RADIAL` camera model."
std::cout << "WARNING: NVM only supports `SIMPLE_RADIAL` "
"and pinhole camera models."
<< std::endl;
return false;
}
Expand Down Expand Up @@ -914,31 +917,47 @@ bool Reconstruction::ExportCam(const std::string& path,
file.precision(17);

double k1, k2;
if (skip_distortion) {
if (skip_distortion ||
camera.ModelId() == SimplePinholeCameraModel::model_id ||
camera.ModelId() == PinholeCameraModel::model_id) {
k1 = 0.0;
k2 = 0.0;
} else if (camera.ModelId() == SimpleRadialCameraModel::model_id) {
k1 = -1 * camera.Params(SimpleRadialCameraModel::extra_params_idxs[0]);
k2 = 0.0;
} else if (camera.ModelId() != RadialCameraModel::model_id) {
} else if (camera.ModelId() == RadialCameraModel::model_id) {
k1 = -1 * camera.Params(RadialCameraModel::extra_params_idxs[0]);
k2 = -1 * camera.Params(RadialCameraModel::extra_params_idxs[1]);
} else {
std::cout << "WARNING: CAM only supports `SIMPLE_RADIAL` and `RADIAL` "
"camera model."
std::cout << "WARNING: CAM only supports `SIMPLE_RADIAL`, `RADIAL`, "
"and pinhole camera models."
<< std::endl;
return false;
}

double fx, fy;
if (camera.FocalLengthIdxs().size() == 2) {
fx = camera.FocalLengthX();
fy = camera.FocalLengthY();
} else {
fx = fy = camera.MeanFocalLength();
}

double focal_length;
if (camera.Width() * fy < camera.Height() * fx) {
focal_length = fy / camera.Height();
} else {
focal_length = fx / camera.Width();
}

const Eigen::Matrix3d rot_mat = image.RotationMatrix();
const double max_image_size = std::max(camera.Width(), camera.Height());
file << image.Tvec(0) << " " << image.Tvec(1) << " " << image.Tvec(2) << " "
<< rot_mat(0, 0) << " " << rot_mat(0, 1) << " " << rot_mat(0, 2) << " "
<< rot_mat(1, 0) << " " << rot_mat(1, 1) << " " << rot_mat(1, 2) << " "
<< rot_mat(2, 0) << " " << rot_mat(2, 1) << " " << rot_mat(2, 2)
<< std::endl;
file << camera.MeanFocalLength() / max_image_size << " " << k1 << " " << k2
<< " 1.0 " << camera.PrincipalPointX() / camera.Width() << " "
file << focal_length << " " << k1 << " " << k2 << " " << fy / fx << " "
<< camera.PrincipalPointX() / camera.Width() << " "
<< camera.PrincipalPointY() / camera.Height() << std::endl;
}

Expand Down Expand Up @@ -978,18 +997,20 @@ bool Reconstruction::ExportRecon3D(const std::string& path,
const class Camera& camera = Camera(image.CameraId());

double k1, k2;
if (skip_distortion) {
if (skip_distortion ||
camera.ModelId() == SimplePinholeCameraModel::model_id ||
camera.ModelId() == PinholeCameraModel::model_id) {
k1 = 0.0;
k2 = 0.0;
} else if (camera.ModelId() == SimpleRadialCameraModel::model_id) {
k1 = -1 * camera.Params(SimpleRadialCameraModel::extra_params_idxs[0]);
k2 = 0.0;
} else if (camera.ModelId() != RadialCameraModel::model_id) {
} else if (camera.ModelId() == RadialCameraModel::model_id) {
k1 = -1 * camera.Params(RadialCameraModel::extra_params_idxs[0]);
k2 = -1 * camera.Params(RadialCameraModel::extra_params_idxs[1]);
} else {
std::cout << "WARNING: Recon3D only supports `SIMPLE_RADIAL` and "
"`RADIAL` camera model."
std::cout << "WARNING: Recon3D only supports `SIMPLE_RADIAL`, "
"`RADIAL`, and pinhole camera models."
<< std::endl;
return false;
}
Expand Down Expand Up @@ -1080,11 +1101,9 @@ bool Reconstruction::ExportBundler(const std::string& path,
const class Camera& camera = Camera(image.CameraId());

double k1, k2;
if (skip_distortion) {
k1 = 0.0;
k2 = 0.0;
} else if (camera.ModelId() == SimplePinholeCameraModel::model_id ||
camera.ModelId() == PinholeCameraModel::model_id) {
if (skip_distortion ||
camera.ModelId() == SimplePinholeCameraModel::model_id ||
camera.ModelId() == PinholeCameraModel::model_id) {
k1 = 0.0;
k2 = 0.0;
} else if (camera.ModelId() == SimpleRadialCameraModel::model_id) {
Expand All @@ -1094,8 +1113,8 @@ bool Reconstruction::ExportBundler(const std::string& path,
k1 = camera.Params(RadialCameraModel::extra_params_idxs[0]);
k2 = camera.Params(RadialCameraModel::extra_params_idxs[1]);
} else {
std::cout << "WARNING: Bundler only supports `SIMPLE_RADIAL` and "
"`RADIAL` camera models."
std::cout << "WARNING: Bundler only supports `SIMPLE_RADIAL`, "
"`RADIAL`, and pinhole camera models."
<< std::endl;
return false;
}
Expand Down

0 comments on commit b7f72fc

Please sign in to comment.