problem in my solvePnPRANSAC code

asked 2012-09-05 21:30:26 -0600

this post is marked as community wiki

This post is a wiki. Anyone with karma >50 is welcome to improve it.

Hi Everyone,

I am having some problem with solvePnPRANSAC. I have 3D data obtained from bundler from images. I am matching 2D points (Query images) with the 3D points. Once I get the corresponding 2D to 3D points, I pick top 50 matches and estimating the pose using opencv function.

Sometimes my 2D match wrongly i.e. against a different 3D model. In such case, ideally I should not get any inlier. But I am getting inliers. In case of correct matches, the inliers come very less as well.

I dont know what I am doing wrong. The code snap is as follows:-

Mat op = Mat(modelPoints); //3d image points Mat ip =Mat(imagePoints); //2d image points

//defining the camera matrix double _cm[9] = {FOCAL_LENGTH, 0, 1, 0, FOCAL_LENGTH, 1, 0, 0, 1 }; camMatrix = Mat(3,3,CV_64FC1,_cm);

rvec = Mat(rv); tvec = Mat(tv);

double _dc[] = {0,0,0,0};
solvePnPRansac(op, ip, camMatrix, Mat(1,4,CV_64FC1,_dc), rvec, tvec);

Please guide me what I am doing wrong; The focal length is kept 2960 in my experiments.

edit retag flag offensive close merge delete

Comments

I suppose something is wrong with your camera matrix. The principal point is (1, 1), based on your code. The principal point is the optical center of the image. Ideally you need to calibrate your camera, i.e. using cv::calibrateCamera (see the docs). Keep in mind that the precision of pose estimation is heavily dependent on the calibration quality (correctness of camera matrix and distortion coefficients values).

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