opencv assertion_error ai_generated true

cv::error: (-215:断言失败) npoints >= 0 && npoints == std::max(1, (int)objectPoints.size()) 在函数 'cv::fisheye::estimateExtrinsics' 中

cv::error: (-215:Assertion failed) npoints >= 0 && npoints == std::max(1, (int)objectPoints.size()) in function 'cv::fisheye::estimateExtrinsics'

ID: opencv/calib3d-fisheye-estimate-extrinsics-invalid

其他格式: JSON · Markdown 中文 · English
86%修复率
83%置信度
1证据数
2023-11-25首次发现

版本兼容性

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

根因分析

传递给 fisheye::estimateExtrinsics 的图像点数 (npoints) 与物点数不匹配,或者 objectPoints 向量为空。

English

The number of image points (npoints) passed to fisheye::estimateExtrinsics does not match the number of object points, or objectPoints vector is empty.

generic

官方文档

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

解决方案

  1. Ensure imagePoints and objectPoints have the same size: assert(imagePoints.size() == objectPoints.size()); Then call: cv::fisheye::estimateExtrinsics(objectPoints, imagePoints, K, D, rvec, tvec);
  2. If using a chessboard, use cv::findChessboardCorners to get imagePoints and generate objectPoints with cv::fisheye::calcChessboardCorners. Example: std::vector<cv::Point3f> objp; cv::fisheye::calcChessboardCorners(cv::Size(9,6), 1.0f, objp); Then match sizes.
  3. Debug by printing sizes before the call: std::cout << 'obj size: ' << objectPoints.size() << ' img size: ' << imagePoints.size() << std::endl; If they differ, pad or trim the larger vector to match.

无效尝试

常见但无效的做法:

  1. Use cv::fisheye::calibrate instead of estimateExtrinsics 85% 失败

    calibrate is for full calibration, not for single-view extrinsic estimation. It requires multiple views and returns different outputs.

  2. Set npoints to a large constant like 100 95% 失败

    npoints must be exactly the size of the imagePoints vector. A hardcoded value will always mismatch unless coincidentally correct.

  3. Convert objectPoints to a vector of cv::Point3f instead of cv::Point3d 70% 失败

    The assertion checks size, not type. Type mismatch causes a different error, but size mismatch persists.