Skip to content

Conversation

kocurvik
Copy link
Contributor

@kocurvik kocurvik commented Nov 23, 2024

Added homography decomposition into pose using SVD.

Original code by @yaqding I just changed the call signature and added bindings.

If approved I will add info to README and bump version.

The code was originally written by @yaqding

Co-authored-by: <yaqding@users.noreply.github.com>
Eigen::Matrix3d V2 = svd.matrixV();

if (abs(S2(0) - S2(2)) < 1.0e-6) {
poses->emplace_back(H2, Eigen::Vector3d(0.0, 0.0, 0.0));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should maybe also add a zero vector to normals here.

Also this check could be made invariant w.r.t. the scale of HH.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So maybe scale this w.r.t. the determinant?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could divide by S2(0) as well.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's best to have poses.size() == normals.size() even in these corner cases. So normals->emplace_back(0,0,0) is reasonable here as well I think.

@@ -19,6 +20,10 @@ focals_from_fundamental_iterative(const Eigen::Matrix3d &F, const Camera &camera
const int &max_iters = 50,
const Eigen::Vector4d &weights = Eigen::Vector4d(5.0e-4, 1.0, 5.0e-4, 1.0));

// Estimate the camera motion from homography.
// If you use H obtained using correspondences in image coordinates from two cameras you need to input K2^-1 * H * K1.
void motion_from_homography(Eigen::Matrix3d HH, std::vector<CameraPose> *poses, std::vector<Eigen::Vector3d> *normals);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HH could be const ref unless we need to copy.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is done so we can enforce the determinant to be positive inside the function.

}
Eigen::Vector3d t2 = (H2 - R2) * n2;

poses->emplace_back(R1, t1);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess there are four possible solutions here
(R1, t1, n1)
(R1, -t1, -n1)
(R2, t2, n2)
(R2, -t2, -n2)
So here we choose the solution pairs with n(2) > 0, but is it possible to decide that these are the correct ones without any correspondences?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be better to return all four otherwise.

@kocurvik
Copy link
Contributor Author

I forgot to comment. The requested changes have been committed. Let me know if this is ok so I can also add changes to README.

@vlarsson
Copy link
Collaborator

Looks good to me, thanks! Please fix the normals thing in the comment, and then update the README and we can merge.

* add H decomp description to README
@kocurvik
Copy link
Contributor Author

I added the normals output and description in README.

Should I also bump the version? I noticed there have been some other somewhat significant commits without version change since 2.0.4.

Copy link
Collaborator

@vlarsson vlarsson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@vlarsson vlarsson merged commit 172ffda into PoseLib:master Dec 19, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants