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

solve_pnp_generic assertion error #579

Open
Craftzman7 opened this issue May 30, 2024 · 0 comments
Open

solve_pnp_generic assertion error #579

Craftzman7 opened this issue May 30, 2024 · 0 comments

Comments

@Craftzman7
Copy link

  1. Tested on Windows & Linux & MacOS
  2. OpenCV installed via package
  3. OpenCV version: 4.5.4
  4. Rustc version: rustc 1.78.0 (9b00956e5 2024-04-29)

I'm attempting to execute the calib3d::solve_pnp_generic method but it always fails with an assertion error. So far my only lead is that it doesn't like the Vector<Vector<f64>> that I pass in the first two options.
Error:

 ./modules/core/src/matrix_wrap.cpp:72: error: (-215:Assertion failed) 0 <= i && i < (int)vv.size() in function 'getMat_'
 (code: StsAssert, -215)

Code:

let camera_matrix: Vec<f64> = vec![1.5423439978686960e+04, 0.0, 2.5748006057298221e+02, 0.0, 4.4603671037286931e+03, 2.7826697712257112e+02, 0.0, 0.0, 1.0];
let dist_coeffs: Vec<f64> = vec![-6.6209197452352086e+01, 7.2707747669563760e+03, 4.2347679589010436e+00, 7.3656411868892713e-01, -2.3636395586370299e+03];

let fidiucial_size: f64 = 0.1651;
let object_points = vec![
    vec![-fidiucial_size / 2.0, fidiucial_size / 2.0, 0.0],
    vec![fidiucial_size / 2.0, fidiucial_size / 2.0, 0.0],
    vec![fidiucial_size / 2.0, -fidiucial_size / 2.0, 0.0],
    vec![-fidiucial_size / 2.0, -fidiucial_size / 2.0, 0.0],
];

let image_points = tags[0].corners().iter().map(|x| Vector::from_iter(x.iter().map(|y| *y as f64))).collect::<Vector<Vector<f64>>>();

let object_points = object_points.iter().map(|x| Vector::from_iter(x.iter().map(|y| *y as f64))).collect::<Vector<Vector<f64>>>();

let camera_matrix = opencv::core::Mat::from_slice(&camera_matrix).unwrap();

let dist_coeffs = opencv::core::Mat::from_slice(&dist_coeffs).unwrap();

let calc = opencv::calib3d::solve_pnp_generic(
    &object_points,
    &image_points,
    &camera_matrix,
    &dist_coeffs,
    &mut opencv::core::no_array(),
    &mut opencv::core::no_array(),
    false,
    opencv::calib3d::SolvePnPMethod::SOLVEPNP_IPPE_SQUARE,
    &mut opencv::core::no_array(),
    &mut opencv::core::no_array(),
    &mut opencv::core::no_array(),
)?;

Any idea why this is happening?

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

No branches or pull requests

1 participant