1 | initial version |
As StevenPuttemans says, the out put of solvePnP() is not directly roll, yaw & pitch, but need to calculate using the rotation matrix.
I also came through the same problem and found the function decomposeProjectionMatrix which gives euler angles as it's output.
Suppose we already get the rotation Mat from solvePnP()
solvePnP(..,...,rotCamerMatrix,transMatrix,false);
Rodrigues(rotCamerMatrix,rotCamerMatrix1);
Now using the function,
void getEulerAngles(Mat &rotCamerMatrix,Vec3d &eulerAngles){
Mat cameraMatrix,rotMatrix,transVect,rotMatrixX,rotMatrixY,rotMatrixZ;
double* _r = rotCamerMatrix.ptr<double>();
double projMatrix[12] = {_r[0],_r[1],_r[2],0,
_r[3],_r[4],_r[5],0,
_r[6],_r[7],_r[8],0};
decomposeProjectionMatrix( Mat(3,4,CV_64FC1,projMatrix),
cameraMatrix,
rotMatrix,
transVect,
rotMatrixX,
rotMatrixY,
rotMatrixZ,
eulerAngles);
}
Call it like,
Vec3d eulerAngles;
getEulerAngles(rotCamerMatrix1,eulerAngles);
where
yaw = eulerAngles[1];
pitch = eulerAngles[0];
roll = eulerAngles[2];
2 | No.2 Revision |
As StevenPuttemans @StevenPuttemans says, the out put of solvePnP() is not directly roll, yaw & pitch, but need to calculate using the rotation matrix.
I also came through the same problem and found the function decomposeProjectionMatrix which gives euler angles as it's output.
Suppose we already get the rotation Mat from solvePnP()
solvePnP(..,...,rotCamerMatrix,transMatrix,false);
Rodrigues(rotCamerMatrix,rotCamerMatrix1);
Now using the function,
void getEulerAngles(Mat &rotCamerMatrix,Vec3d &eulerAngles){
Mat cameraMatrix,rotMatrix,transVect,rotMatrixX,rotMatrixY,rotMatrixZ;
double* _r = rotCamerMatrix.ptr<double>();
double projMatrix[12] = {_r[0],_r[1],_r[2],0,
_r[3],_r[4],_r[5],0,
_r[6],_r[7],_r[8],0};
decomposeProjectionMatrix( Mat(3,4,CV_64FC1,projMatrix),
cameraMatrix,
rotMatrix,
transVect,
rotMatrixX,
rotMatrixY,
rotMatrixZ,
eulerAngles);
}
Call it like,
Vec3d eulerAngles;
getEulerAngles(rotCamerMatrix1,eulerAngles);
where
yaw = eulerAngles[1];
pitch = eulerAngles[0];
roll = eulerAngles[2];
3 | No.3 Revision |
As @StevenPuttemans says, the out put of solvePnP() is not directly roll, yaw & pitch, but need to calculate using the rotation matrix.
I also came through the same problem and found the function decomposeProjectionMatrix which gives euler angles as it's output.
Suppose we already get the rotation Mat from solvePnP()
solvePnP(..,...,rotCamerMatrix,transMatrix,false);
Rodrigues(rotCamerMatrix,rotCamerMatrix1);
Now using the function,
void getEulerAngles(Mat &rotCamerMatrix,Vec3d &eulerAngles){
Mat cameraMatrix,rotMatrix,transVect,rotMatrixX,rotMatrixY,rotMatrixZ;
double* _r = rotCamerMatrix.ptr<double>();
double projMatrix[12] = {_r[0],_r[1],_r[2],0,
_r[3],_r[4],_r[5],0,
_r[6],_r[7],_r[8],0};
decomposeProjectionMatrix( Mat(3,4,CV_64FC1,projMatrix),
cameraMatrix,
rotMatrix,
transVect,
rotMatrixX,
rotMatrixY,
rotMatrixZ,
eulerAngles);
}
Call it like,
Vec3d eulerAngles;
getEulerAngles(rotCamerMatrix1,eulerAngles);
where
yaw = eulerAngles[1];
pitch = eulerAngles[0];
roll = eulerAngles[2];
4 | No.4 Revision |
As @StevenPuttemans says, the out put of solvePnP() is not directly roll, yaw & pitch, but need to calculate using the rotation matrix.
I also came through the same problem and found the function decomposeProjectionMatrix which gives euler angles as it's output.
Suppose we already get the rotation Mat from solvePnP()
solvePnP(..,...,rotCamerMatrix,transMatrix,false);
Rodrigues(rotCamerMatrix,rotCamerMatrix1);
Now using the function,
void getEulerAngles(Mat &rotCamerMatrix,Vec3d &eulerAngles){
Mat cameraMatrix,rotMatrix,transVect,rotMatrixX,rotMatrixY,rotMatrixZ;
double* _r = rotCamerMatrix.ptr<double>();
double projMatrix[12] = {_r[0],_r[1],_r[2],0,
_r[3],_r[4],_r[5],0,
_r[6],_r[7],_r[8],0};
decomposeProjectionMatrix( Mat(3,4,CV_64FC1,projMatrix),
cameraMatrix,
rotMatrix,
transVect,
rotMatrixX,
rotMatrixY,
rotMatrixZ,
eulerAngles);
}
Call it like,
Vec3d eulerAngles;
getEulerAngles(rotCamerMatrix1,eulerAngles);
where
yaw = eulerAngles[1];
pitch = eulerAngles[0];
roll = eulerAngles[2];