-28 opencv computation_error ai_generated true

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

ID: opencv/solvepnp-insufficient-points

Also available as: JSON · Markdown · 中文
87%Fix Rate
89%Confidence
1Evidence
2023-11-18First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
4.5.0 active
4.7.0 active
4.9.0 active

Root Cause

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

中文

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

Official Documentation

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

Workarounds

  1. 95% success Ensure at least 4 unique, non-collinear 3D-2D point correspondences: if (objectPoints.size() < 4) { /* collect more points */ }
    Ensure at least 4 unique, non-collinear 3D-2D point correspondences: if (objectPoints.size() < 4) { /* collect more points */ }
  2. 85% success Use SOLVEPNP_EPNP which can work with 4 or more points; it is more robust to small sets: cv::solvePnP(objectPoints, imagePoints, cameraMatrix, distCoeffs, rvec, tvec, false, cv::SOLVEPNP_EPNP);
    Use SOLVEPNP_EPNP which can work with 4 or more points; it is more robust to small sets: cv::solvePnP(objectPoints, imagePoints, cameraMatrix, distCoeffs, rvec, tvec, false, cv::SOLVEPNP_EPNP);

中文步骤

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

Dead Ends

Common approaches that don't work:

  1. 100% fail

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

  2. 90% fail

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