-215 opencv type_error ai_generated true

cv::error: (-215:Assertion failed) distCoeffs.type() == CV_32FC1 || distCoeffs.type() == CV_64FC1 in function 'undistortPoints'

ID: opencv/undistort-points-empty

Also available as: JSON · Markdown · 中文
88%Fix Rate
87%Confidence
1Evidence
2023-09-10First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
4.5.0 active
4.8.0 active
4.10.0 active

Root Cause

The distortion coefficients matrix passed to cv::undistortPoints must be of type CV_32FC1 or CV_64FC1; other types cause an assertion failure.

generic

中文

传递给 cv::undistortPoints 的畸变系数矩阵必须为 CV_32FC1 或 CV_64FC1 类型;其他类型会导致断言失败。

Official Documentation

https://docs.opencv.org/4.x/d9/d0c/group__calib3d.html#ga55b3f9b9c3f0c9b8e1f0a5b7c3e1f

Workarounds

  1. 95% success Convert distCoeffs to CV_32FC1: distCoeffs.convertTo(distCoeffs, CV_32F);
    Convert distCoeffs to CV_32FC1: distCoeffs.convertTo(distCoeffs, CV_32F);
  2. 90% success If no distortion, pass a zero matrix: cv::Mat::zeros(1, 5, CV_64FC1) or cv::Mat::zeros(1, 8, CV_64FC1).
    If no distortion, pass a zero matrix: cv::Mat::zeros(1, 5, CV_64FC1) or cv::Mat::zeros(1, 8, CV_64FC1).

中文步骤

  1. 将 distCoeffs 转换为 CV_32FC1:distCoeffs.convertTo(distCoeffs, CV_32F);
  2. 如果没有畸变,传递零矩阵:cv::Mat::zeros(1, 5, CV_64FC1) 或 cv::Mat::zeros(1, 8, CV_64FC1)。

Dead Ends

Common approaches that don't work:

  1. 90% fail

    The function expects a single-channel matrix for distortion coefficients; multi-channel types are not accepted and trigger the assertion.

  2. 70% fail

    An empty Mat has type CV_8UC1 by default; the assertion fails because it is neither CV_32FC1 nor CV_64FC1. Use cv::Mat() with proper type or a zero matrix.