我正在使用solvepnp为头戴式设备(Hololens)使用LED作为标记进行相机(iphone相机)姿势估计。我已经校准了下面的相机是相机内在参数
/* approx model*/
double focal_length = image.cols;
Point2d center = cv::Point2d(image.cols/2,image.rows/2);
iphone_camera_matrix = (cv::Mat_<double>(3,3) << focal_length, 0, center.x, 0 , focal_length, center.y, 0, 0, 1);
iphone_dist_coeffs = cv::Mat::zeros(4,1,cv::DataType<double>::type);
/* caliberated(usng opencv) model */
iphone_camera_matrix = (cv::Mat_<double>(3,3) <<839.43920487140315, 0, 240, 0, 839.43920487140315, 424, 0, 0, 1);
iphone_dist_coeffs = (cv::Mat_<double>(5,1) <<4.6476561543838640e-02, -2.0580084834071521, 0, 0 ,2.0182662261396342e+01);
usng solvpnp 能够在相机坐标系中获得正确的对象姿势 下面是代码
cv::solvePnP(world_points, image_points, iphone_camera_matrix, iphone_dist_coeffs, rotation_vector, translation_vector, true, SOLVEPNP_ITERATIVE);
输出是
rotation_vector :
[-65.41956646885059;
-52.49185328449133;
36.82917796058498]
translation_vector :
[94.1158604375937;
-164.2178023980637;
580.5666657301058]
使用这个rotation_vector 和translation_vector 通过投影点为的三向量来可视化姿势
points_to_project :
[0, 0, 0;
20, 0, 0;
0, 20, 0;
0, 0, 20]
projectPoints(points_to_project, rotation_vector, translation_vector, iphone_camera_matrix, iphone_dist_coeffs, projected_points);
projectionPoints 的输出为
projected_points :
[376.88803, 185.15131;
383.05768, 195.77643;
406.46454, 175.12997;
372.67371, 155.56181]
这似乎是正确的,如下所示
我尝试通过使用由solvepnp给出的rotation_vector和translation_vector的变换来在世界/对象坐标系中找到相机姿势
cv::Rodrigues(rotation_vector, rotation_matrix);
rot_matrix_wld = rotation_matrix.t();
translation_vec_wld = -rot_matrix_wld * translation_vector;
我使用了 rot_matrix_wld、translation_vec_wld 来可视化姿势(与我在相机坐标系中可视化对象姿势的方式相同,如上所述)
projectPoints(points_to_project, rot_matrix_wld, translation_vec_wld, iphone_camera_matrix, iphone_dist_coeffs, projected_points);
和
points_to_project :
[0, 0, 0;
20, 0, 0;
0, 20, 0;
0, 0, 20]
我得到错误的翻译向量(低于 2 个投影点用于视频的 2 个不同图像帧)
projected_points :
[-795.11768, -975.85846;
-877.84937, -932.39697;
-868.5517, -1197.4443;
projected_points :
[589.42999, 3019.0732;
590.64789, 2665.5835;
479.49728, 2154.8057;
187.78407, 3333.3054]
-593.41058, -851.74432]
我使用了近似相机模型和校准相机模型都给出了错误的平移向量。
我已经浏览了这里的链接并验证了我的校准程序,我做得正确。
我不确定哪里做错了,任何人都可以帮我解决这个问题。
提前致谢。