Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

having trouble understanding pose matrix.... #34

Open
ofZach opened this issue Dec 17, 2017 · 7 comments
Open

having trouble understanding pose matrix.... #34

ofZach opened this issue Dec 17, 2017 · 7 comments

Comments

@ofZach
Copy link

ofZach commented Dec 17, 2017

Hi ! I am trying to use the pose matrix to project points in space but having trouble understanding
what's happening internally, I am basically trying to project points on three axis to make the same orientation as drawDebugPose. I saw there is a pose example, but that is "drawing" I kind of need project points myself (I need to calculate a 3d plane which is oriented to the face)

here's what I get when I try to draw it (next to drawDebugPose, which looks right):

screen shot 2017-12-17 at 10 32 28 am

I see that loadPoseMatrix() is also calling transformPosePosition().... I am a little lost about what's happening there.

if I wanted to rotate points by hand (rather than drawing) to make something that looks like drawDebugPose is there an easy way to do this?

ie:

if(tracker.size() > 0){ 
        ofMatrix4x4 pose = tracker.getInstances()[0].getPoseMatrix();
        ofMultMatrix(pose);
        ofPoint aa(0,0,0);
        ofPoint bb(100,0,0);
        ofPoint cc(0,100,0);
        ofPoint dd(0,0,100);
        ofLine(aa, bb);
        ofLine(aa, cc);
        ofLine(aa, dd);
    }

or

    if(tracker.size() > 0){
        ofMatrix4x4 pose = tracker.getInstances()[0].getPoseMatrix();
        ofPoint aa(0,0,0);
        ofPoint bb(100,0,0);
        ofPoint cc(0,100,0);
        ofPoint dd(0,0,100);
        aa = pose * aa;
        bb = pose * bb;
        cc = pose * cc;
        dd = pose * dd;
        ofLine(aa, aa + (bb-aa).getNormalized() * 100);
        ofLine(aa, aa + (cc-aa).getNormalized()* 100);
        ofLine(aa, aa + (dd-aa).getNormalized()* 100);
        
    }
@ofZach
Copy link
Author

ofZach commented Dec 17, 2017

@ofZach
Copy link
Author

ofZach commented Dec 17, 2017

I experimented with the code here:

https://forum.openframeworks.cc/t/ofxfactetracker2-how-to-manipulate-pose-matrix/25173

and found I can get something that's close-ish so what draw debug is giving -- mine is in white, the original draw debug is in r/g/b

screen shot 2017-12-17 at 4 48 12 pm

screen shot 2017-12-17 at 4 45 52 pm

my intuition is that the only difference is the projection matrix that happens in draw debug -- so maybe this is ok and it's just visually different since it's two different projections?

@HalfdanJ
Copy link
Owner

HalfdanJ commented Dec 18, 2017 via email

@ofZach
Copy link
Author

ofZach commented Dec 18, 2017

it could be but debug draw looks better to my eye... I guess I am just confused about why Intrinsics::loadProjectionMatrix is called in debug draw -- is it important somehow?

I experimented with making an ofCamera and setting the FOV really low gives something visually similar to debug draw.

with a normal FOV

screen shot 2017-12-17 at 4 48 12 pm

with a very low FOV -- matches closer...

screen shot 2017-12-17 at 7 30 44 pm

screen shot 2017-12-17 at 7 31 30 pm

@ofZach
Copy link
Author

ofZach commented Dec 18, 2017

also, if it's helpful, setting up an ortho camera (ofCamera::enableOrtho) also produces something very visually similar to debug draw.....

@ofZach
Copy link
Author

ofZach commented Jan 18, 2018

I don't have a PR yet, but just a quick note that I found this useful:

http://answers.opencv.org/question/23089/opencv-opengl-proper-camera-pose-using-solvepnp/

I am only interested in rotation, so something like this works for me after the solvepnp call to get a matrix which captures rotation in a way that's more OF compatible :

rotation = cv::Mat::zeros(4, 4, CV_64F);
    cv::Mat viewMatrix = cv::Mat::zeros(4, 4, CV_64F);
    cv::Rodrigues(poservec, rotation);
    
    for(unsigned int row=0; row<3; ++row)
    {
        for(unsigned int col=0; col<3; ++col)
        {
            viewMatrix.at<double>(row, col) = rotation.at<double>(row, col);
        }
        viewMatrix.at<double>(row, 3) = 0; //posetvec.at<double>(row, 0);
    }
    viewMatrix.at<double>(3, 3) = 1.0f;
    cv::Mat cvToGl = cv::Mat::zeros(4, 4, CV_64F);
    glViewMatrix = cv::Mat::zeros(4, 4, CV_64F);
    cv::transpose(viewMatrix , glViewMatrix);   // <--- glViewMatrix has rotation in a way easy to use...

dunno if it's helpful, just posting if folks are in similar boat to me trying to get useful info out...

@vanderlin
Copy link

vanderlin commented Jan 10, 2019

I found my way to this thread via searching. I am too having trouble getting a directional vector from the pose.

I experimented with the code from this thread - https://forum.openframeworks.cc/t/ofxfactetracker2-how-to-manipulate-pose-matrix/25173/2?u=vanderlin

but looks like I'm way off. The pink line is me...
screen shot 2019-01-10 at 9 40 15 am

I was trying to convert pitch, roll, yaw to a unit vector.

x = cos(yaw)*cos(pitch)
y = sin(yaw)*cos(pitch)
z = sin(pitch)

I also tried to get a vector from the rotation quaternion.

 glm::vec3 vec = rotation * glm::vec3(0, 0, 1);

Am I totally off?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants