OpenCV + OpenGL: proper camera pose using solvePnP - OpenCV Q&A Forum

cv::Mat class::cvtCoordGL2CV(const cv::Mat GLPose)
{
    //

    cv::Mat GL2CV = cv::Mat::zeros(4, 4, CV_32FC1);
    GL2CV.at<float>(0, 0) = 1.0f;
    GL2CV.at<float>(1, 1) = -1.0f; // Invert the y axis
    GL2CV.at<float>(2, 2) = -1.0f; // invert the z axis
    GL2CV.at<float>(3, 3) = 1.0f;

    return GL2CV * GLPose;
}