1. 程式人生 > >如何將CV::Mat轉成glm::ma4

如何將CV::Mat轉成glm::ma4

How a cv::Mat translate from/to a glm::mat4

void fromCV2GLM(const cv::Mat& cvmat, glm::mat4* glmmat) {
    if (cvmat.cols != 4 || cvmat.rows != 4 || cvmat.type() != CV_32FC1) {
        cout << "Matrix conversion error!" << endl;
        return;
    }
    memcpy(glm::value_ptr(*glmmat), cvmat.data, 16 * sizeof(float));
}

void fromGLM2CV(const glm::mat4& glmmat, cv::Mat* cvmat) {
    if (cvmat->cols != 4 || cvmat->rows != 4) {
        (*cvmat) = cv::Mat(4, 4, CV_32F);
    }
    memcpy(cvmat->data, glm::value_ptr(glmmat), 16 * sizeof(float));
}