Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <opencv2\opencv.hpp>
- #include <iostream>
- int main()
- {
- std::vector<cv::Point3f> cld;
- cld.push_back(cv::Point3f(20.0,20.0,20.0));
- cld.push_back(cv::Point3f(60.0,20.0,20.0));
- cld.push_back(cv::Point3f(20.0,60.0,20.0));
- cld.push_back(cv::Point3f(60.0,60.0,20.0));
- cld.push_back(cv::Point3f(20.0,20.0,60.0));
- cld.push_back(cv::Point3f(60.0,20.0,60.0));
- cld.push_back(cv::Point3f(20.0,60.0,60.0));
- cld.push_back(cv::Point3f(60.0,60.0,60.0));
- cv::Mat K; // intrinsic parameter matrix
- cv::Mat rvec; // rotation matrix
- cv::Mat tvec; // translation vector
- cv::Mat R;
- cv::Mat_<double> t(3,1,CV_32FC1); // Any idea how to get this?
- // Create the known projection matrix
- cv::Mat P(3,4,CV_64FC1);
- P.at<double>(0,0) = -2.8058e-01;
- P.at<double>(1,0) = -6.8326e-02;
- P.at<double>(2,0) = 5.1458e-07;
- P.at<double>(0,1) = 2.0045e-02;
- P.at<double>(1,1) = -3.1718e-01;
- P.at<double>(2,1) = 4.5840e-06;
- P.at<double>(0,2) = 1.8102e-01;
- P.at<double>(1,2) = -7.2974e-02;
- P.at<double>(2,2) = 2.6699e-06;
- P.at<double>(0,3) = 6.6062e-01;
- P.at<double>(1,3) = 5.8402e-01;
- P.at<double>(2,3) = 1.5590e-03;
- cv::decomposeProjectionMatrix(P, K, R, tvec);
- // tvec is a 1x4 matrix, project points requires a 1x3
- cv::Rodrigues(R,rvec);
- cv::Mat distCoeffs = cv::Mat::zeros(4,1,CV_64FC1);
- std::vector<cv::Point2f> imagePoints;
- cv::setIdentity(K);
- rvec.setTo(0);
- t.setTo(0);
- try
- {
- cv::projectPoints(cld, rvec, t, K, distCoeffs, imagePoints );
- }
- catch(cv::Exception e)
- {
- std::cout << e.msg << std::endl;
- }
- cv::Mat drawImage = cv::Mat::zeros(400,400,CV_8UC1);
- for(int i=0; i<imagePoints.size();i++)
- {
- cv::circle(drawImage,imagePoints[i],3,cv::Scalar(255,255,255),-1);
- }
- cv::imshow("Cloud",drawImage);
- cv::waitKey();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement