Ask Your Question

solvePnpRansac GPU assertion failed

asked 2016-02-11 00:45:52 -0500

Alek.B gravatar image

I'm trying to use the gpu version of solvePnPRansac to estimate the pose of the camera, but I get the following error:

OpenCV Error: Assertion failed (object.rows == 1 && object.cols > 0 && object.type() == CV_32FC3) in cv::gpu::solvePnPRansac, file C:\opencv\sources\modules\gpu\src\calib3d.cpp, line 218

If I run my code using the solvePnP or cpu-based solvePnPRansac, everything works fine.

I took a look into the code of calib3d.cpp at line 218 and the problem seems to be related to the first parameter of the function (that should be the list of the reference points).

It seems that the format that I use to send the reference point to the function is wrong, but I didn't figure out which one is correct.

Here is my code:

// Reference Points and Detected Points for Pose Estimation
std::vector<cv::Point3f> refMarkerPoint;
std::vector<cv::Point2f> markerPoints;


cv::Mat rvec = cv::Mat::zeros(1, 3, CV_32F);
cv::Mat tvec = cv::Mat::zeros(1, 3, CV_32F);
cv::Mat rotation = cv::Mat::zeros(1, 3, CV_32F);
cv::Mat tvec2 = cv::Mat::zeros(1, 3, CV_32F);
Vec3d eulerAngles;


if (cx_right != 0 && cx_left != 0 && markerPoints.size() > 0)
    marker_detected = 1;
    //solvePnPRansac(refMarkerPoint, markerPoints, cameraMatrix, distCoeffs, rvec, tvec, false, 20, 4, 20, noArray(), CV_ITERATIVE); // CV_EPNP, CV_P3P
    //solvePnP(Mat(refMarkerPoint), Mat(markerPoints), cameraMatrix, distCoeffs, rvec, tvec);
   gpu::solvePnPRansac(Mat(refMarkerPoint), Mat(markerPoints), cameraMatrix, distCoeffs, rvec, tvec);

    cv::Rodrigues(rvec, rotation);


Do you have any suggestions?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2016-02-11 01:03:10 -0500

berak gravatar image

updated 2016-02-11 05:34:42 -0500

could you try to transpose it, like:

gpu::solvePnPRansac(Mat(refMarkerPoint).t(), Mat(markerPoints).t(), .... ?

(making a Mat from a vector unfortunately makes a single col Mat, not a single row one)

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2016-02-11 00:45:52 -0500

Seen: 478 times

Last updated: Feb 11 '16