Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

solvePnP-RANSAC crashes.

I am using solvePnpRansac with a vector of Point3f and a vector of Point2f, based on the code from this tutorial:

the function:

        void PnPProblem::estimatePoseRANSAC( const std::vector<cv::Point3f> &list_points3d, 
                                     const std::vector<cv::Point2f> &list_points2d,    
                                     int flags, cv::Mat &inliers, int iterationsCount,
                                     float reprojectionError, double confidence )   

  cv::Mat distCoeffs = cv::Mat::zeros(4, 1, CV_64FC1); // vector of distortion coefficients 
  cv::Mat rvec =  cv::Mat::zeros(3, 1, CV_64FC1);          // output rotation vector   
  cv::Mat tvec = cv::Mat::zeros(3, 1, CV_64FC1);    // output translation vector

  bool useExtrinsicGuess = true;   // if true the function uses the provided rvec and tvec values as
            // initial approximations of the rotation and translation vectors

  cv::solvePnPRansac( list_points3d, list_points2d, _A_matrix, distCoeffs, rvec, tvec,
                useExtrinsicGuess, iterationsCount, reprojectionError, confidence,
                inliers, flags );


It will run fine, for a few seconds, then it will crash with the debug Assertion failed - vector subscript out of range error.

The 3d points and 2d points stay at around 300 each, the other numbers don't change. Why would this be happening?

In realated weirdness, some PnP methods will run, and some won't. Iterative crashes right away, EPNP runs, then gives the assertion error, and P3P is the same.