Fixes and optimizations for the SQPnP solver#21702
Merged
opencv-pushbot merged 6 commits intoopencv:4.xfrom May 13, 2022
Merged
Fixes and optimizations for the SQPnP solver#21702opencv-pushbot merged 6 commits intoopencv:4.xfrom
opencv-pushbot merged 6 commits intoopencv:4.xfrom
Conversation
- optimized the calculation of qa_sum by moving equal elements outside the loop - unrolled copying of the lower triangle of omega - substituted SVD with eigendecomposition in the factorization of omega (2-3 times faster) - fixed the initialization of lambda in FOAM - added a cheirality test that checks a solution on all 3D points rather than on their mean. The old test rejected valid poses in some cases - fixed some typos & errors in comments
Eigen decomposition seems to yield larger errors in certain tests, reverted to SVD
Added nearestRotationMatrixSVD() Previous nearestRotationMatrix() renamed to nearestRotationMatrixFOAM() and reverts to nearestRotationMatrixSVD() for singular matrices
Member
|
/cc @nathanrgodwin as author of initial contribution |
Fixed the order of checks in PoseSolver::solveInternal()
Contributor
|
@victor1234 Please take a look. |
Contributor
|
@mlourakis as I understand main improvements are:
How did you measure calculation time improvements?
In which cases? Is this a bug of implementation? Thanks |
Contributor
Author
|
Hi,
Your summary description is correct.
Computation time was measured in microseconds using
std::chrono::high_resolution_clock::now() and various inputs.
The old initialization of lambda caused the FOAM algorithm to diverge in
a pathological case with a singular input matrix; the latter was
reported as an issue by an SQPnP user
(terzakig/sqpnp#15).
The cheirality fix is also important as the old test sometimes caused
valid solutions to be discarded.
To compute the nullspace of matrix Omega, the SVD is used. Despite its
excellent stability, SVD is slow and does not exploit the symmetry of
our matrix. Therefore, I attempted to replace SVD with eigen
decomposition (EVD) but the results were not as accurate as with SVD. It
seems that this is an issue inherent with the EVD (rather than its
implementation) as I tried to use Eigen's SelfAdjointEigenSolver in the
OpenCV code without success.
Note here that the stand-alone implementation of SQPnP uses Eigen's
rank-revealing QR (see
https://github.com/terzakig/sqpnp/blob/e9ebcf07ac26350777548a3eefdae578f9570200/sqpnp/sqpnp.h#L205-L213)
wich is faster compared to SVD. The user is given the option to choose
between RRQR and SVD. However, as openCV seems to lack a RRQR, I had to
stick to SVD.
Hope this has cleared things up.
Best regards,
ML
On 2022-04-28 15:41, Victor wrote:
@mlourakis [1] as I understand main improvements are:
* fixed some typos & errors in comments
* calculation time optimization
* fixies: initialization of lambda, cheirality test
How did you measure calculation time improvements?
What was practically affected by the fixies? I mean in which cases the old solution did not work?
> Eigen decomposition seems to yield larger errors in certain tests, reverted to SVD
In which cases? Is this a bug of implementation?
Thanks
--
Reply to this email directly, view it on GitHub [2], or unsubscribe [3].
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Contributor
|
Great |
victor1234
approved these changes
Apr 29, 2022
vpisarev
approved these changes
May 13, 2022
Contributor
|
@mlourakis, thank you very much for keeping OpenCV version of your code up-to-date! 👍 |
Merged
a-sajjad72
pushed a commit
to a-sajjad72/opencv
that referenced
this pull request
Mar 30, 2023
Fixes and optimizations for the SQPnP solver * Fixes and optimizations - optimized the calculation of qa_sum by moving equal elements outside the loop - unrolled copying of the lower triangle of omega - substituted SVD with eigendecomposition in the factorization of omega (2-3 times faster) - fixed the initialization of lambda in FOAM - added a cheirality test that checks a solution on all 3D points rather than on their mean. The old test rejected valid poses in some cases - fixed some typos & errors in comments * reverted to SVD Eigen decomposition seems to yield larger errors in certain tests, reverted to SVD * nearestRotationMatrixSVD Added nearestRotationMatrixSVD() Previous nearestRotationMatrix() renamed to nearestRotationMatrixFOAM() and reverts to nearestRotationMatrixSVD() for singular matrices * fixed checks order Fixed the order of checks in PoseSolver::solveInternal()
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR mirrors to OpenCV changes made recently to the official SQPnP implementation
Pull Request Readiness Checklist
Patch to opencv_extra has the same branch name.