Initially I knew nothing about what formats OpenCV uses. So some research first. Looking at the documentation for solvePnP
, it appears like its returning a matrix. (The Rodrigues2
function mentioned in an older version in the docs appears to be called Rodrigues
these days.)
The description there indicates that you can expect a matrix with either a single row or a single column. The direction of that vector indicates the axis of rotation, while the length (or “norm”) of the vector gives the angle.
So your input is in angle-axis representation. Which you can interpret as a simultaneous rotation about the x, y and z axes. So if by “XYZ rotation” you mean simultaneous rotation, then you are already there. If, however, you mean some combination which rotates first about the x axis and then about the y axis and then about the z axis, you are in a strange setup, and probably should make sure you are using the correct API.
If it is Euler angles you are after, then calling them “XYZ rotation” is somewhat misleading. The Wikipedia article Rotation formalisms in three dimensions gives a list of the various formats, and how to convert between them. In particular, it does give formulas to convert from Axis and angle to matrix and from there to euler angles.
Make sure you are using the correct representation to match your graphics output machinery. Or if you have a choice, try to work directly on the rotation marix representation, as that should be easiest to understand and work with.