-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add fixed extrinsics in rig config #1144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1633,23 +1633,38 @@ int RunPointTriangulator(int argc, char** argv) { | |
// { | ||
// "camera_id": 1, | ||
// "image_prefix": "left1_image" | ||
// "rel_tvec": [0, 0, 0], | ||
// "rel_qvec": [1, 0, 0, 0] | ||
// }, | ||
// { | ||
// "camera_id": 2, | ||
// "image_prefix": "left2_image" | ||
// "rel_tvec": [0, 0, 0], | ||
// "rel_qvec": [0, 1, 0, 0] | ||
// }, | ||
// { | ||
// "camera_id": 3, | ||
// "image_prefix": "right1_image" | ||
// "rel_tvec": [0, 0, 0], | ||
// "rel_qvec": [0, 0, 1, 0] | ||
// }, | ||
// { | ||
// "camera_id": 4, | ||
// "image_prefix": "right2_image" | ||
// "rel_tvec": [0, 0, 0], | ||
// "rel_qvec": [0, 0, 0, 1] | ||
// } | ||
// ] | ||
// } | ||
// ] | ||
// | ||
// The "camera_id" and "image_prefix" fields are required, whereas the | ||
// "rel_tvec" and "rel_qvec" fields optionally specify the relative | ||
// extrinsics of the camera rig in the form of a translation vector and a | ||
// rotation quaternion. The relative extrinsics rel_qvec and rel_tvec transform | ||
// coordinates from rig to camera coordinate space. If the relative extrinsics | ||
// are not provided then they are automatically inferred from the reconstruction. | ||
// | ||
// This file specifies the configuration for a single camera rig and that you | ||
// could potentially define multiple camera rigs. The rig is composed of 4 | ||
// cameras: all images of the first camera must have "left1_image" as a name | ||
|
@@ -1683,11 +1698,9 @@ int RunPointTriangulator(int argc, char** argv) { | |
// frame002.png | ||
// ... | ||
// | ||
// TODO: Provide an option to manually / explicitly set the relative extrinsics | ||
// of the camera rig. At the moment, the relative extrinsics are automatically | ||
// inferred from the reconstruction. | ||
std::vector<CameraRig> ReadCameraRigConfig( | ||
const std::string& rig_config_path, const Reconstruction& reconstruction) { | ||
std::vector<CameraRig> ReadCameraRigConfig(const std::string& rig_config_path, | ||
const Reconstruction& reconstruction, | ||
bool estimate_rig_relative_poses) { | ||
boost::property_tree::ptree pt; | ||
boost::property_tree::read_json(rig_config_path.c_str(), pt); | ||
|
||
|
@@ -1699,8 +1712,28 @@ std::vector<CameraRig> ReadCameraRigConfig( | |
for (const auto& camera : rig_config.second.get_child("cameras")) { | ||
const int camera_id = camera.second.get<int>("camera_id"); | ||
image_prefixes.push_back(camera.second.get<std::string>("image_prefix")); | ||
camera_rig.AddCamera(camera_id, ComposeIdentityQuaternion(), | ||
Eigen::Vector3d(0, 0, 0)); | ||
Eigen::Vector3d rel_tvec; | ||
Eigen::Vector4d rel_qvec; | ||
int index = 0; | ||
auto rel_tvec_node = camera.second.get_child_optional("rel_tvec"); | ||
if (rel_tvec_node) { | ||
for (const auto& node : rel_tvec_node.get()) { | ||
rel_tvec[index] = node.second.get_value<double>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You missed the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch on that one; I'll post a fix. |
||
} | ||
} else { | ||
estimate_rig_relative_poses = true; | ||
} | ||
index = 0; | ||
auto rel_qvec_node = camera.second.get_child_optional("rel_qvec"); | ||
if (rel_qvec_node) { | ||
for (const auto& node : rel_qvec_node.get()) { | ||
rel_qvec[index] = node.second.get_value<double>(); | ||
} | ||
} else { | ||
estimate_rig_relative_poses = true; | ||
} | ||
|
||
camera_rig.AddCamera(camera_id, rel_qvec, rel_tvec); | ||
} | ||
|
||
camera_rig.SetRefCameraId(rig_config.second.get<int>("ref_camera_id")); | ||
|
@@ -1732,7 +1765,15 @@ std::vector<CameraRig> ReadCameraRigConfig( | |
} | ||
|
||
camera_rig.Check(reconstruction); | ||
camera_rig.ComputeRelativePoses(reconstruction); | ||
if (estimate_rig_relative_poses) { | ||
PrintHeading2("Estimating relative rig poses"); | ||
if (!camera_rig.ComputeRelativePoses(reconstruction)) { | ||
std::cout << "WARN: Failed to estimate rig poses from reconstruction; " | ||
"cannot use rig BA" | ||
<< std::endl; | ||
return std::vector<CameraRig>(); | ||
} | ||
} | ||
|
||
camera_rigs.push_back(camera_rig); | ||
} | ||
|
@@ -1744,13 +1785,16 @@ int RunRigBundleAdjuster(int argc, char** argv) { | |
std::string input_path; | ||
std::string output_path; | ||
std::string rig_config_path; | ||
bool estimate_rig_relative_poses = true; | ||
|
||
RigBundleAdjuster::Options rig_ba_options; | ||
|
||
OptionManager options; | ||
options.AddRequiredOption("input_path", &input_path); | ||
options.AddRequiredOption("output_path", &output_path); | ||
options.AddRequiredOption("rig_config_path", &rig_config_path); | ||
options.AddDefaultOption("estimate_rig_relative_poses", | ||
&estimate_rig_relative_poses); | ||
options.AddDefaultOption("RigBundleAdjustment.refine_relative_poses", | ||
&rig_ba_options.refine_relative_poses); | ||
options.AddBundleAdjustmentOptions(); | ||
|
@@ -1761,7 +1805,8 @@ int RunRigBundleAdjuster(int argc, char** argv) { | |
|
||
PrintHeading1("Camera rig configuration"); | ||
|
||
auto camera_rigs = ReadCameraRigConfig(rig_config_path, reconstruction); | ||
auto camera_rigs = ReadCameraRigConfig(rig_config_path, reconstruction, | ||
estimate_rig_relative_poses); | ||
|
||
BundleAdjustmentConfig config; | ||
for (size_t i = 0; i < camera_rigs.size(); ++i) { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.