CARVIEW |
Navigation Menu
-
-
Notifications
You must be signed in to change notification settings - Fork 56.2k
Added SQPnP algorithm to SolvePnP #18371
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
Conversation
d950279
to
b5c26aa
Compare
@nathanrgodwin Thanks for the contribution. |
Changed norm method (significant speed increase), changed nearest rotation computation to FOAM
interesting paper |
@tompollok I have the changes from the new commit "New InvertSymmetric3x3" added locally but I haven't added the loop unrolling from their latest commit yet. It should be trivial to make that change. I haven't had the chance to test these changes yet, but once I do, I'll add them to the PR. |
@vpisarev is there a chance for this pr to still make it for 4.5 release? It does not alter any previous functionality and seems like a very interesting pnp solver. |
I'm interested in testing sqpnp algorithm, so for that I implemented the code sqpnp.h and sqpnp.cpp into aruco library to compare the performance of sqpnp and IPPE which is the algorithm implemented there. Here you can find aruco with sqpnp implemented and also a real video of markers given by aruco I didn't have to do much modifications to get it to work with aruco so it is fairly simple to see what I've modified. I've noticed that the current implementation of sqpnp is unstable, very often giving a completely wrong results. For your information Aruco is using the four planar corners of the marker to estimate the pose. I don't know if this is a limitation of sqpnp but I should investigate that when I finish reading the article of sqpnp. My experience with IPPE is that it is only suffering from pose ambiguity in some situations, otherwise it is always giving the right solution. |
Please note, that it is under GPLv3, so it's derived work can't be used in OpenCV. |
Yes I agree but this is just for a purpose of testing opencv (sqpnp algorithm) in aruco for a real application and not the way around. Thanks for pointing that out! |
@JaouadROS This is somewhat surprising since the SQPnP code passes the same unit tests that the OpenCV IPPE implementation passes as well as a number of synthetic tests developed by the paper's authors (these tests are used in my own repo https://github.com/nathanrgodwin/SQPnP). I'll take a look at your implementation and see if I can recreate the issue. |
@JaouadROS Thank you for bringing this bug to my attention. The error stemmed from the SVD operation. The solver computes U and Vt matrices sufficient to reproduce the original matrix. Because the PSD matrix being decomposed was not full rank, when one of the values of the vectors of the orthogonal basis of the nullspace in Vt reaches 0, the corresponding value in U is no longer contributes to reproducing the original matrix and can't be optimized further. Switching to use Vt instead of U for the eigenvectors resolved the problem. After resolving this error and running approximately 2000 solving iterations on your aruco marker video, SQPnP produced a re-projection error of more than 2 only once. Although it seems in this case, IPPE outperformed SQPnP, possibly because the points here are coplanar. AVG SQPNP RMSE: 0.364983 |
Indices were initialized negative. When nullspace is large, points coplanar, and rotation near 0, indices not changed.
Thank you @nathanrgodwin for the quick reply and debug, now it works as good as IPPE in the case of four planar points with slightly better performance for IPPE. Still though both suffer from ambiguity and it is something that can't be detected through the projection error. Now I've another case in which I don't get the correct results. This time I've 11 points non-coplanar and I compare the pose between two frames with a very small movement of the points (you can see that when you plot the image points) and still the poses are very different.
|
@JaouadROS The results for these point sets do produce bad poses, however, the poses produced are the same as the author's implementation. OpenCV's SOLVEPNP_ITERATIVE also produces a high reprojection error. |
@nathanrgodwin Thank you for your time. I'll double-check those points again and I'll let you know. But for SOLVEPNP_ITERATIVE, it needs a good initial guess (it works with useExtrinsicGuess sets to true) so it won't converge without a |
@JaouadROS Yeah, it is LM internally. For LM, it is possible for it to converge without a good guess, however, since it finds a local minimum, convergence without a good guess does depend on the convexity of the solution space. I mostly provided this as a quick sanity check, if this converged with LM without extrinsic guess, there would clearly be a problem with the SQPnP solution. You could try the other relevant OpenCV PnP solvers as well with your sample points to determine if the point sets can produce a valid solution. |
@nathanrgodwin, thank you for the contribution! π |
Added algorithm from "A Consistently Fast and Globally Optimal Solution to the Perspective-n-Point Problem" by G. Terzakis and M.Lourakis to SolvePnP. Based in part on the implementation from terzakig/sqpnp.
The paper from ECCV2020 argues that the method used produces state-of-the-art results without requiring a co-planar arrangement of points. Integration with the SolvePnP unit test suggests this claim is accurate.
The primary changes introduced by this pull request are:
System:
Windows 10 64-bit
Visual Studio 2019