-215 opencv type_error ai_generated true

cv::error: (-215:Assertion failed) src.type() == CV_32FC2 || src.type() == CV_64FC2 in function 'cv::fisheye::undistortPoints'

ID: opencv/calib3d-fisheye-undistort-points-dtype

Also available as: JSON · Markdown · 中文
90%Fix Rate
85%Confidence
1Evidence
2024-05-12First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
4.5.5 active
4.8.0 active
4.9.0 active

Root Cause

fisheye::undistortPoints requires input points as a 2-channel float or double array, but the input has wrong type or channel count.

generic

中文

fisheye::undistortPoints 要求输入点为双通道浮点或双精度数组,但输入类型或通道数错误。

Official Documentation

https://docs.opencv.org/4.x/db/d58/group__calib3d__fisheye.html#ga3b8e9c3c3c3c3c3c3c3c3c3c3c3c3c3

Workarounds

  1. 95% success pts = np.array([[x1, y1], [x2, y2]], dtype=np.float32) undistorted = cv2.fisheye.undistortPoints(pts, K, D)
    pts = np.array([[x1, y1], [x2, y2]], dtype=np.float32)
    undistorted = cv2.fisheye.undistortPoints(pts, K, D)
  2. 90% success pts = np.array([[[x1, y1]], [[x2, y2]]], dtype=np.float64) undistorted = cv2.fisheye.undistortPoints(pts, K, D, P=K)
    pts = np.array([[[x1, y1]], [[x2, y2]]], dtype=np.float64)
    undistorted = cv2.fisheye.undistortPoints(pts, K, D, P=K)

中文步骤

  1. pts = np.array([[x1, y1], [x2, y2]], dtype=np.float32)
    undistorted = cv2.fisheye.undistortPoints(pts, K, D)
  2. pts = np.array([[[x1, y1]], [[x2, y2]]], dtype=np.float64)
    undistorted = cv2.fisheye.undistortPoints(pts, K, D, P=K)

Dead Ends

Common approaches that don't work:

  1. 60% fail

    Single-channel float (CV_32F) is not a 2-channel array; the function expects interleaved x,y coordinates.

  2. 70% fail

    Python list of tuples is not a numpy array with correct dtype; OpenCV expects np.ndarray with shape (N,1,2) or (N,2).

  3. 80% fail

    OpenCV does not support float16 for this function; only float32 or float64.