solvePnP-RANSAC crashes.

asked 2015-06-18 07:38:01 -0600

stillNovice gravatar image

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

http://docs.opencv.org/master/dc/d2c/...

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.

edit retag flag offensive close merge delete

Comments

Has anyone found a solution to this? I'm having the exact same problem. I'd appreciate any insight!

bjdr gravatar imagebjdr ( 2016-02-10 13:48:48 -0600 )edit

Probably the problem is in types of what you're passing to solvePnP. list_points3d and list_points2d are floats and rvec, tvec, distCoeffs (not sure for _A_matrix) are doubles. And also the possible problem is in your extrinsic guess (the values of rvec and tvec, that are passed as inputs) as long as your useExtrinsicGuess is true.

MFmaniak gravatar imageMFmaniak ( 2017-01-10 00:51:01 -0600 )edit