opencv_contrib icon indicating copy to clipboard operation
opencv_contrib copied to clipboard

ccalib/omnidir: bad results with projectPoints / undistortPoints for non-contiguous inputs

Open gautiervarjo opened this issue 1 year ago • 0 comments

System information (version)
  • OpenCV => 4.5, 4.8, 4.9 (versions I tried)
  • Operating System / Platform => Linux x86_64
  • Compiler => unknown (installed opencv-contrib-python from PyPI)
Detailed description

When using the functions cv2.omnidir.projectPoints and cv2.omnidir.undistortPoints via the python API, the results might be garbage depending on how the input points were sliced and reshaped.

If the input numpy array is copied, the issue disappears.

Steps to reproduce
import cv2
import numpy as np

# Dummy camera parameters.
K = np.array([[500.0, 0.0, 500.0], [0.0, 500.0, 500.0], [0.0, 0.0, 1.0]])
D = (0.0, 0.0, 0.0, 0.0)
Xi = np.array(0.0)
R = np.eye(3)

# Generate a bunch of 2D points, with an extra 3rd channel which we'll slice away.
rng = np.random.default_rng(seed=1234)
points = rng.uniform(0, 1000, size=(6, 3))

np.testing.assert_allclose(
    cv2.omnidir.undistortPoints(points[:, :2].reshape(-1, 1, 2), K, D, Xi, R),
    cv2.omnidir.undistortPoints(points[:, :2].reshape(-1, 1, 2).copy(), K, D, Xi, R),
    atol=1e-6,
    rtol=1e-6,
)
Issue submission checklist
  • [x] I report the issue, it's not a question
  • [x] I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
  • [x] I updated to the latest OpenCV version and the issue is still there
  • [x] There is reproducer code and related data files: videos, images, onnx, etc

gautiervarjo avatar Jan 19 '24 16:01 gautiervarjo