-28 opencv computation_error ai_generated true

cv::error: (-28:有效点数不足) 在函数 'solvePnP' 中

cv::error: (-28:Insufficient number of valid points) in function 'solvePnP'

ID: opencv/solvepnp-insufficient-points

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

版本兼容性

版本状态引入弃用备注
4.5.0 active
4.7.0 active
4.9.0 active

根因分析

cv::solvePnP 需要至少 4 个非共线的点对应关系(P3P)或 6 个(PnP);输入集太小或包含退化点。

English

cv::solvePnP requires at least 4 non-collinear point correspondences for P3P or 6 for PnP; the input set is too small or contains degenerate points.

generic

官方文档

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

解决方案

  1. 确保至少有 4 个唯一且非共线的 3D-2D 点对应:if (objectPoints.size() < 4) { /* 收集更多点 */ }
  2. 使用 SOLVEPNP_EPNP,它可以处理 4 个或更多点,对少量点更鲁棒:cv::solvePnP(objectPoints, imagePoints, cameraMatrix, distCoeffs, rvec, tvec, false, cv::SOLVEPNP_EPNP);

无效尝试

常见但无效的做法:

  1. 100% 失败

    All PnP methods require a minimum number of correspondences; iterative methods still need at least 4 points to compute a solution.

  2. 90% 失败

    Duplicate or collinear points do not provide new constraints; the solver fails due to degeneracy or numerical instability.