Skip to content

Instantly share code, notes, and snippets.

@eprana
Created November 19, 2015 10:19
Show Gist options
  • Select an option

  • Save eprana/8abf86ebd324545dc3fc to your computer and use it in GitHub Desktop.

Select an option

Save eprana/8abf86ebd324545dc3fc to your computer and use it in GitHub Desktop.
// Retrieve pinhole from 'pinholeProjectionMatrix' attribute
// Focal is the first element
MDoubleArray intrinsicsArray;
MVGMayaUtil::getDoubleArrayAttribute(camera.getDagPath().node(), "mvg_intrinsicParams", intrinsicsArray);
LOG_INFO("mvg_intrinsicParams : ")
LOG_INFO(intrinsicsArray)
// Initialize K
openMVG::Mat3 K;
K(0,1) = 0.0;
K(0,2) = 0.0;
K(1,0) = 0.0;
K(1,2) = 0.0;
K(2,0) = 0.0;
K(2,2) = 0.0;
K(0,0) = intrinsicsArray[0];
K(1,1) = intrinsicsArray[0];
K(2,2) = 1.0;
// First method : retrieve K and t
MMatrix inclusiveMatrix = camera.getDagPath().inclusiveMatrix();
MTransformationMatrix transformMatrix(inclusiveMatrix);
// Rotation matrix
openMVG::Mat3 R;
MMatrix rotationMatrix = transformMatrix.asRotateMatrix();
for(int i = 0; i < 3; ++i)
{
for(int j = 0; j < 3; ++j)
R(i, j) = rotationMatrix[i][j];
}
openMVG::Vec3 t;
MVector translation = transformMatrix.translation(MSpace::kWorld);
for(int i = 0; i < 3; ++i)
t(i) = translation[i];
openMVG::Mat34 P;
openMVG::P_From_KRt(K, R, t, &P);
@eprana
Copy link
Author

eprana commented Nov 19, 2015

Mise à jour du code :

        // Retrieve pinhole from 'pinholeProjectionMatrix' attribute
        MDoubleArray intrinsicsArray;
        MVGMayaUtil::getDoubleArrayAttribute(camera.getDagPath().node(), "mvg_intrinsicParams", intrinsicsArray);
        LOG_INFO("mvg_intrinsicParams : ")   
        LOG_INFO(intrinsicsArray)

        openMVG::Mat3 K;
        K(0,0) = intrinsicsArray[0];
        K(0,1) = 0.0;
        K(0,2) = intrinsicsArray[1];
        K(1,0) = 0.0;
        K(1,1) = intrinsicsArray[0];
        K(1,2) = intrinsicsArray[2];
        K(2,0) = 0.0;    
        K(2,2) = 1.0;

        LOG_INFO("### K ###")
        LOG_INFO(K)

        MMatrix inclusiveMatrix = camera.getDagPath().inclusiveMatrix();
        LOG_INFO("### inclusiveMatrix ###")
        LOG_INFO(inclusiveMatrix)
        MTransformationMatrix transformMatrix(inclusiveMatrix);

        openMVG::Mat3 R;        
        MMatrix rotationMatrix = transformMatrix.asRotateMatrix();
        for(int m = 0; m < 3; ++m)
        {
            for(int j = 0; j < 3; ++j)
                R(m, j) = rotationMatrix[m][j];
        }
        LOG_INFO("### R ###")
        LOG_INFO(R)

        MFnCamera fnCamera(camera.getDagPath());
        openMVG::Vec3 C = TO_VEC3(fnCamera.eyePoint(MSpace::kWorld));
        LOG_INFO("### C ###")
        LOG_INFO(C)
        openMVG::Vec3 t = -R * C;
        LOG_INFO("### t ###")
        LOG_INFO(t)

        openMVG::Mat34 P; 
        openMVG::P_From_KRt(K, R, t, &P);
        LOG_INFO("### P ###")
        LOG_INFO(P)

        projectiveCameras.push_back(P);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment