solvePnP fluctuating result

asked 2018-03-17 04:50:03 -0500

Luan Tran Minh gravatar image

updated 2018-03-17 05:26:13 -0500

Hi, I am using solvePnp to detect head pose. But estimate result from rotation, translation fluctuating a lots.

solvePnp Call:

cv::solvePnP(model3DPoints, imagePoints, cameraMatrix, dist_coeffs, rotationMat, translationMat);

Camera matrix code:

float focal_length = frame.cols;
cv::Point2d center = cv::Point2d(frame.cols / 2, frame.rows / 2);
cameraMatrix = (cv::Mat_<double>(3,3) << focal_length, 0, center.x, 0 , focal_length, center.y, 0, 0, 1);

Camera matrix value in real time:

640.000000 0.000000 320.000000
0.000000 640.000000 426.000000
0.000000 0.000000 1.000000

Distortion coefficients matrix:

dist_coeffs = cv::Mat::zeros(4,1,cv::DataType<double>::type);

3D Models Points:

model3DPoints.push_back(cv::Point3f(6.825897, 6.760612, 4.402142));
model3DPoints.push_back(cv::Point3f(1.330353, 7.122144, 6.903745));
model3DPoints.push_back(cv::Point3f(-1.330353, 7.122144, 6.903745));
model3DPoints.push_back(cv::Point3f(-6.825897, 6.760612, 4.402142));
model3DPoints.push_back(cv::Point3f(5.311432, 5.485328, 3.987654));
model3DPoints.push_back(cv::Point3f(1.789930, 5.393625, 4.413414));
model3DPoints.push_back(cv::Point3f(-1.789930, 5.393625, 4.413414));
model3DPoints.push_back(cv::Point3f(-5.311432, 5.485328, 3.987654));
model3DPoints.push_back(cv::Point3f(2.005628, 1.409845, 6.165652));
model3DPoints.push_back(cv::Point3f(-2.005628, 1.409845, 6.165652));
model3DPoints.push_back(cv::Point3f(2.774015, -2.080775, 5.048531));
model3DPoints.push_back(cv::Point3f(-2.774015, -2.080775, 5.048531));
model3DPoints.push_back(cv::Point3f(0.000000, -3.116408, 6.097667));
model3DPoints.push_back(cv::Point3f(0.000000, -7.415691, 4.070434));

2D Points value:

(156.139725, 367.403290)
(288.635376, 340.711731)
(358.303589, 343.156128)
(495.513824, 371.169189)
(199.867783, 404.109467)
(272.105225, 411.756317)
(379.791809, 412.740295)
(453.119293, 409.567810)
(276.528778, 520.536621)
(371.074890, 519.674438)
(241.585831, 596.283813)
(409.880096, 592.829407)
(327.109375, 641.688782)
(330.348145, 716.255615)

Only the 2d image point change a bit but the result change a lots.

ROTATION (-3452928277881874609248275663945728.000000, -0.915058, 0.000000)
TRANSLATION (-3635378688.000000, -1.656431, -385174336.000000)

ROTATION (0.000000, -0.899182, 0.005109) 
TRANSLATION (0.000000, -1.649161, 1274852533763833856.000000)

ROTATION (-0.000000, -0.953833, 7.130205) 
TRANSLATION (-0.000000, -1.669374, -0.001339)

ROTATION (0.000052, 0.986896, 1245620912259072.000000)
TRANSLATION (-0.000000, -1.616727, 0.000000)
edit retag flag offensive close merge delete

Comments

please add the solvePnP call

berak gravatar imageberak ( 2018-03-17 05:03:20 -0500 )edit
1

Thank you, I updated my question.

Luan Tran Minh gravatar imageLuan Tran Minh ( 2018-03-17 05:26:29 -0500 )edit

maybe use another flag ? e.g. SOLVEPNP_EPNP works good for me in a very similar program

(and ofc., double check, if your original 2d<-->3d point associations are correct !)

berak gravatar imageberak ( 2018-03-17 05:46:28 -0500 )edit

Thank you for the suggestion, the estimated rotation translation results still change a lots. Also I double checked by projectPoints with same 3D points, the rotation, translation from solvePnP result and it gives me not same value as 2d image points.

Luan Tran Minh gravatar imageLuan Tran Minh ( 2018-03-17 07:13:08 -0500 )edit

are you on windows, using VS ?

berak gravatar imageberak ( 2018-03-17 11:38:29 -0500 )edit

I am using Mac, Xcode.

Luan Tran Minh gravatar imageLuan Tran Minh ( 2018-03-18 06:22:56 -0500 )edit

naw, ok.

i was more thinking of a win specific problem, when linking debug libs to release projects (the std::vector definitions go out of sync, leads to absurd numbers like yours above)

berak gravatar imageberak ( 2018-03-18 06:25:07 -0500 )edit