Created
December 11, 2014 00:40
-
-
Save agirault/960f027648e05973b0ce to your computer and use it in GitHub Desktop.
homography screenReality
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//-- Matrix | |
float modelview[16]; | |
float projection[16]; | |
glGetFloatv (GL_MODELVIEW_MATRIX, modelview); | |
glGetFloatv (GL_PROJECTION_MATRIX, projection); | |
cv::Mat modelM(4,4,CV_32FC2,modelview); | |
cv::Mat projM(4,4,CV_32FC2,projection); | |
cv::Mat M = projM*modelM; | |
std::cout<<M<<std::endl; | |
// HOMOGRAPHY CORRECTION //might only need 3 points | |
//-- opengl camera center | |
float cx = (float)windowWidth/40.0; | |
float cy = (float)windowHeight/40.0; | |
//-- space corners coordinates | |
float p0[4]={cx,cy,0,1}; | |
float p1[4]={-cx,cy,0,1}; | |
float p2[4]={-cx,-cy,0,1}; | |
float p3[4]={cx,-cy,0,1}; | |
//-- space corners matrix | |
cv::Mat P0(4,1,CV_32FC2,p0); | |
cv::Mat P1(4,1,CV_32FC2,p1); | |
cv::Mat P2(4,1,CV_32FC2,p2); | |
cv::Mat P3(4,1,CV_32FC2,p3); | |
//-- projected corners matrix | |
cv::Mat Q0 = M*P0; | |
cv::Mat Q1 = M*P1; | |
cv::Mat Q2 = M*P2; | |
cv::Mat Q3 = M*P3; | |
//-- projected corners divided by z | |
Q0 /= Q0.at<float>(2.0,0.0); | |
Q1 /= Q1.at<float>(2.0,0.0); | |
Q2 /= Q2.at<float>(2.0,0.0); | |
Q3 /= Q3.at<float>(2.0,0.0); | |
//-- space corners points | |
std::vector<cv::Point2f> ps; | |
ps.push_back(cv::Point2f(cx,cy)); | |
ps.push_back(cv::Point2f(-cx,cy)); | |
ps.push_back(cv::Point2f(-cx,-cy)); | |
ps.push_back(cv::Point2f(cx,-cy)); | |
//-- projected corners points | |
std::vector<cv::Point2f> qs; | |
qs.push_back(cv::Point2f(Q0.at<float>(0.0,0.0),Q0.at<float>(1.0,0.0))); | |
qs.push_back(cv::Point2f(Q1.at<float>(0.0,0.0),Q1.at<float>(1.0,0.0))); | |
qs.push_back(cv::Point2f(Q2.at<float>(0.0,0.0),Q2.at<float>(1.0,0.0))); | |
qs.push_back(cv::Point2f(Q3.at<float>(0.0,0.0),Q3.at<float>(1.0,0.0))); | |
//cv::Mat H = cv::findHomography( ps , qs , CV_RANSAC ); | |
//std::cout<<H<<std::endl; | |
//std::cout<<Q0<<std::endl; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment