Advertisement
Guest User

Untitled

a guest
Jun 14th, 2014
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. #include <opencv2\opencv.hpp>
  2. #include <iostream>
  3. int main()
  4. {
  5. std::vector<cv::Point3f> cld;
  6. cld.push_back(cv::Point3f(20.0,20.0,20.0));
  7. cld.push_back(cv::Point3f(60.0,20.0,20.0));
  8. cld.push_back(cv::Point3f(20.0,60.0,20.0));
  9. cld.push_back(cv::Point3f(60.0,60.0,20.0));
  10. cld.push_back(cv::Point3f(20.0,20.0,60.0));
  11. cld.push_back(cv::Point3f(60.0,20.0,60.0));
  12. cld.push_back(cv::Point3f(20.0,60.0,60.0));
  13. cld.push_back(cv::Point3f(60.0,60.0,60.0));
  14.  
  15. cv::Mat K; // intrinsic parameter matrix
  16. cv::Mat rvec; // rotation matrix
  17. cv::Mat tvec; // translation vector
  18. cv::Mat R;
  19.  
  20. cv::Mat_<double> t(3,1,CV_32FC1); // Any idea how to get this?
  21.  
  22. // Create the known projection matrix
  23. cv::Mat P(3,4,CV_64FC1);
  24. P.at<double>(0,0) = -2.8058e-01;
  25. P.at<double>(1,0) = -6.8326e-02;
  26. P.at<double>(2,0) = 5.1458e-07;
  27.  
  28. P.at<double>(0,1) = 2.0045e-02;
  29. P.at<double>(1,1) = -3.1718e-01;
  30. P.at<double>(2,1) = 4.5840e-06;
  31.  
  32. P.at<double>(0,2) = 1.8102e-01;
  33. P.at<double>(1,2) = -7.2974e-02;
  34. P.at<double>(2,2) = 2.6699e-06;
  35.  
  36. P.at<double>(0,3) = 6.6062e-01;
  37. P.at<double>(1,3) = 5.8402e-01;
  38. P.at<double>(2,3) = 1.5590e-03;
  39.  
  40. cv::decomposeProjectionMatrix(P, K, R, tvec);
  41.  
  42. // tvec is a 1x4 matrix, project points requires a 1x3
  43.  
  44. cv::Rodrigues(R,rvec);
  45.  
  46. cv::Mat distCoeffs = cv::Mat::zeros(4,1,CV_64FC1);
  47. std::vector<cv::Point2f> imagePoints;
  48. cv::setIdentity(K);
  49. rvec.setTo(0);
  50. t.setTo(0);
  51. try
  52. {
  53. cv::projectPoints(cld, rvec, t, K, distCoeffs, imagePoints );
  54. }
  55. catch(cv::Exception e)
  56. {
  57. std::cout << e.msg << std::endl;
  58. }
  59. cv::Mat drawImage = cv::Mat::zeros(400,400,CV_8UC1);
  60. for(int i=0; i<imagePoints.size();i++)
  61. {
  62. cv::circle(drawImage,imagePoints[i],3,cv::Scalar(255,255,255),-1);
  63. }
  64. cv::imshow("Cloud",drawImage);
  65. cv::waitKey();
  66. return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement