-215 opencv type_error ai_generated true

cv::error: (-215:断言失败) src.type() == CV_32FC2 || src.type() == CV_64FC2 在函数 'cv::fisheye::undistortPoints' 中

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

其他格式: JSON · Markdown 中文 · English
90%修复率
85%置信度
1证据数
2024-05-12首次发现

版本兼容性

版本状态引入弃用备注
4.5.5 active
4.8.0 active
4.9.0 active

根因分析

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

English

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

generic

官方文档

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

解决方案

  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)

无效尝试

常见但无效的做法:

  1. 60% 失败

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

  2. 70% 失败

    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% 失败

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