Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. /*
  2. * intrinsic:3x3 double matrix
  3. */
  4. void pose_estimation_2d2d ( const cv::Mat& intrinsic, double focal_length, std::vector<KeyPoint> keypoints_1,
  5. std::vector<KeyPoint> keypoints_2,
  6. std::vector< DMatch > matches,
  7. Mat& R, Mat& t )
  8. {
  9. // 相机内参,TUM Freiburg2
  10. Mat K = ( Mat_<double> ( 3,3 ) << 520.9, 0, 325.1, 0, 521.0, 249.7, 0, 0, 1 );
  11.  
  12. //-- 把匹配点转换为vector<Point2f>的形式
  13. vector<Point2f> points1;
  14. vector<Point2f> points2;
  15.  
  16. for ( int i = 0; i < ( int ) matches.size(); i++ )
  17. {
  18. points1.push_back ( keypoints_1[matches[i].queryIdx].pt );
  19. points2.push_back ( keypoints_2[matches[i].trainIdx].pt );
  20. }
  21.  
  22. //-- 计算基础矩阵
  23. Mat fundamental_matrix;
  24. fundamental_matrix = findFundamentalMat ( points1, points2, CV_FM_8POINT );
  25. cout<<"fundamental_matrix is "<<endl<< fundamental_matrix<<endl;
  26.  
  27. //-- 计算本质矩阵
  28. Point2d principal_point ( intrinsic.at<double>(0,2), intrinsic.at<double>(1,2) ); //相机光心, TUM dataset标定值
  29. //double focal_length = 521; //相机焦距, TUM dataset标定值
  30. Mat essential_matrix;
  31. essential_matrix = findEssentialMat ( points1, points2, focal_length, principal_point );
  32. cout<<"essential_matrix is "<<endl<< essential_matrix<<endl;
  33.  
  34. //-- 计算单应矩阵
  35. Mat homography_matrix;
  36. homography_matrix = findHomography ( points1, points2, RANSAC, 3 );
  37. cout<<"homography_matrix is "<<endl<<homography_matrix<<endl;
  38.  
  39. //-- 从本质矩阵中恢复旋转和平移信息.
  40. recoverPose ( essential_matrix, points1, points2, R, t, focal_length, principal_point );
  41. cout<<"R is "<<endl<<R<<endl;
  42. cout<<"t is "<<endl<<t<<endl;
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement