Skip to content
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

SolvePnP with useExtrinsicGuess is broken when using IEnumberable overload #1556

Closed
Jcparkyn opened this issue Apr 7, 2023 · 0 comments · Fixed by #1585
Closed

SolvePnP with useExtrinsicGuess is broken when using IEnumberable overload #1556

Jcparkyn opened this issue Apr 7, 2023 · 0 comments · Fixed by #1585

Comments

@Jcparkyn
Copy link
Contributor

Jcparkyn commented Apr 7, 2023

Summary of your issue

When using Cv2.SolvePnP with the overload that takes IEnumerable parameters, the rvec and tvec values passed to the function are overwritten before calling the native OpenCV method. This is normally fine, but when using useExtrinsicGuess, this results in garbage output.

The InputArray overload doesn't have this issue.

The problem is here, where rvec and tvec are created from scratch, instead of using the passed-in values.

Environment

  • Windows 10
  • OpenCvSharp4.Windows, Version="4.7.0.20230115"
  • F# 7

What did you do when you faced the problem?

Replaced code with InputArray overload, which works as expected.

Example code (F#):

// Dummy values because coming up with a real scenario is hard.
let mutable rvec = null
let mutable tvec = null
while true do
    Cv2.SolvePnP(
        [Point3f(0f, 0f, 0f); Point3f(0f, 0f, 1f); Point3f(0f, 1f, 0f); Point3f(0f, 1f, 1f)],
        [Point2f(0f, 0f); Point2f(0f, 1f); Point2f(1f, 0f); Point2f(1f, 1f)],
        cameraMatrix = array2D [
            [ 1394.6027293299926; 0.; 995.588675691456];
            [0.; 1394.6027293299926; 599.3212928484164];
            [0.; 0.; 1. ]],
        distCoeffs = [ 0.11; -0.219; 0.0012; 0.00856; 0.1127 ],
        rvec = &rvec,
        tvec = &tvec,
        useExtrinsicGuess = (not <| isNull rvec),
        flags = SolvePnPFlags.Iterative
    )

Output:

rvec and tvec have reasonable values, or at least close to what they are with useExtrinsicGuess=false.

What did you intend to be?

rvec and tvec are not even close to correct.

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 a pull request may close this issue.

1 participant